Skip to content

Commit aa0ddc6

Browse files
authored
add console.diffPush (#1)
1 parent 38564b3 commit aa0ddc6

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ Example
1010
console.diff(left, right);
1111
console.diffLeft(left);
1212
console.diffRight(right);
13+
console.diffPush(next);
1314
```
1415
![screenshot](./doc/screenshot.png)
1516

17+
Usage basics
18+
===
19+
Left side for old state, right side for new.
20+
To track changes of the same object in timed manner you can push it with `diffPush` command,
21+
that will shift objects from right to left, showing differences with previous push state.
22+
1623
Based on
1724
===
1825
[jsondiffpatch](https://github.com/benjamine/jsondiffpatch) by benjamine

src/js/app/panel.vue.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ define(['api'], function (api) {
130130
console.log('$_onRuntimeMessage', req);
131131

132132
if (req.source === 'jsdiff-devtools-extension-api') {
133-
this.$_onDiffRequest(req.payload.left, req.payload.right);
133+
this.$_onDiffRequest(req.payload);
134134
}
135135
},
136136

@@ -147,12 +147,18 @@ define(['api'], function (api) {
147147
return false;
148148
},
149149

150-
$_onDiffRequest(left, right) {
151-
if (left) {
152-
this.compare.left = left;
150+
$_onDiffRequest({left, right, push}) {
151+
if (push) {
152+
this.compare.left = this.compare.right;
153+
this.compare.right = push;
153154
}
154-
if (right) {
155-
this.compare.right = right;
155+
else {
156+
if (left) {
157+
this.compare.left = left;
158+
}
159+
if (right) {
160+
this.compare.right = right;
161+
}
156162
}
157163

158164
this.$_restartLastUpdated();

src/js/jsdiff-devtools.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,15 @@ function injectScripts () {
4646
}
4747

4848
function jsdiff_devtools_extension_api () {
49-
'use strict';
50-
5149
if (console.diff) {return;/*nothing to do*/}
5250
const source = 'jsdiff-devtools-extension-api';
5351
const w = window;
5452

5553
Object.assign(console, {
5654
diff(left, right) {w.postMessage({payload: {left, right}, source}, '*');},
5755
diffLeft(left) {w.postMessage({payload: {left}, source}, '*');},
58-
diffRight(right) {w.postMessage({payload: {right}, source}, '*');}
56+
diffRight(right) {w.postMessage({payload: {right}, source}, '*');},
57+
diffPush(push) {w.postMessage({payload: {push}, source}, '*');}
5958
});
6059

6160
console.log(
@@ -67,7 +66,7 @@ function jsdiff_devtools_extension_api () {
6766
border: 1px solid #bbb;
6867
border-radius: 4px;
6968
`,
70-
`console.diff(left, right); console.diffLeft(left); console.diffRight(right);`
69+
`console.diff(left, right); console.diffLeft(left); console.diffRight(right); console.diffPush(next);`
7170
);
7271
}
7372

0 commit comments

Comments
 (0)