|
1 | 1 | ###  console.diff()
|
| 2 | + |
2 | 3 | [](https://chrome.google.com/webstore/detail/jsdiff-devtool/iefeamoljhdcpigpnpggeiiabpnpgonb)
|
3 | 4 |
|
4 | 5 | Chrome devtools extension intended to display result of deep in-memory object
|
5 | 6 | comparisons with the help of dedicated console commands.
|
6 | 7 |
|
| 8 | +<details> |
| 9 | + <summary> <strong>Screenshots</strong> </summary> |
| 10 | + |
| 11 | +- Comparing two objects |
| 12 | +  |
| 13 | + |
| 14 | +- Tracking changes in localStorage (unchanged are hidden) |
| 15 | +  |
| 16 | + |
| 17 | +</details> |
| 18 | + |
| 19 | +### Based on |
| 20 | + |
| 21 | +- [jsondiffpatch](https://github.com/benjamine/jsondiffpatch) by Benjamín Eidelman |
| 22 | +- [vuejs](https://github.com/vuejs) by Evan You |
| 23 | + |
7 | 24 | ### Features
|
8 |
| -* compare objects from multiple tabs and/or between page reloads |
9 |
| -* function code included in comparison result in form of a string, may help to see if it was altered |
10 |
| -* document, dom-elements and other non-serializable objects are filtered-out from the results |
11 |
| -* self recurring references displayed only once, the rest of occurrences are filtered-out |
| 25 | + |
| 26 | +- compare objects from multiple tabs and/or between page reloads |
| 27 | +- function code included in comparison result in form of a string, may help to see if it was altered |
| 28 | +- document, dom-elements and other non-serializable objects are filtered-out from the results |
| 29 | +- self recurring references displayed only once, the rest of occurrences are filtered-out |
| 30 | +- basic integration with search functionality within devtools |
| 31 | + - if search query contains upper-case letter - the search will be case-sensitive |
| 32 | + |
| 33 | +### Limitations and workarounds |
| 34 | + |
| 35 | +- some instances of objects may cause exception during preparations for comparison |
| 36 | + - try to narrow compared contexts |
| 37 | + - if it's some Browser API that causes an exception and not a framework, consider opening an issue, |
| 38 | + so it will be possible to solve it on a permanent basis |
| 39 | +- while paused in debug mode, JSDiff panel won't reflect the result until runtime is resumed ([#10][i10]) |
| 40 | + |
| 41 | +[i10]: https://github.com/zendive/jsdiff/issues/10 |
12 | 42 |
|
13 | 43 | ### API
|
| 44 | + |
| 45 | +- **console.diff(left, right)** - compare left and right arguments |
| 46 | + |
14 | 47 | ```javascript
|
15 |
| -console.diff(left, right); // compare left and right |
16 |
| -console.diff(next); // shorthand of diffPush while single argumented |
17 |
| -console.diffLeft(left); // update object on the left side only |
18 |
| -console.diffRight(right); // update object on the right side only |
19 |
| -console.diffPush(next); // shifts sides, right becomes left, next becomes right |
| 48 | +console.diff({ a: 1, b: 1, c: 3 }, { a: 1, b: 2, d: 3 }); |
| 49 | +``` |
| 50 | + |
| 51 | +- **console.diffPush(next)** - shifts sides, right becomes left, next becomes right |
| 52 | + |
| 53 | +```javascript |
| 54 | +console.diffPush(Date.now()); |
| 55 | +``` |
| 56 | + |
| 57 | +- **console.diff(next)** - shorthand for `diffPush` |
| 58 | + |
| 59 | +```javascript |
| 60 | +console.diff(Date.now()); |
| 61 | +``` |
| 62 | + |
| 63 | +- **console.diffLeft(left)** - update the old value only |
| 64 | + |
| 65 | +```javascript |
| 66 | +console.diffLeft(Date.now()); |
| 67 | +``` |
| 68 | + |
| 69 | +- **console.diffRight(right)** - update the new value only |
| 70 | + |
| 71 | +```javascript |
| 72 | +console.diffRight(Date.now()); |
20 | 73 | ```
|
21 | 74 |
|
22 | 75 | ### Usage basics
|
| 76 | + |
23 | 77 | Historically, left side represents the old state and right side the new state.
|
24 |
| -* Things that are present on the left side but missing on the right side are colour-coded as red (old). |
25 |
| -* Things that are missing on the left side but present on the right side are colour-coded as green (new). |
| 78 | + |
| 79 | +- Things that are present on the left side but missing on the right side are colour-coded as red (old). |
| 80 | +- Things that are missing on the left side but present on the right side are colour-coded as green (new). |
26 | 81 |
|
27 | 82 | To track changes of the same variable in timed manner you can push it with `diffPush` or `diff`
|
28 |
| -with a single argument, |
29 |
| -that will shift objects from right to left, showing differences with previous push state. |
| 83 | +with a single argument, that will shift objects from right to left, showing differences with previous push state. |
30 | 84 |
|
31 | 85 | ### How it works
|
32 |
| -* `jsdiff-devtools` registers devtools panel |
33 |
| - * injects console commands that send data to `jsdiff-proxy` |
34 |
| - * injects `jsdiff-proxy` to farther communicate objects to the extension's `jsdiff-background` |
35 |
| -* when `console.diff` command invoked |
36 |
| - * argument/s are cloned in a suitable form for sending between different window contexts and sent to `jsdiff-proxy` |
37 |
| - * `jsdiff-proxy` catches the data and sends it to the `jsdiff-background` where it is stored for future consuming |
38 |
| -* when `jsdiff-panel` is mounted (visible in devtools) it listens to data expected to come from the `jsdiff-background` |
39 |
| -and displays it |
40 |
| - |
41 |
| -### Screenshot |
42 |
| - |
43 | 86 |
|
44 |
| -### Based on |
45 |
| -- [jsondiffpatch](https://github.com/benjamine/jsondiffpatch) by Benjamín Eidelman |
46 |
| -- [vuejs](https://github.com/vuejs) by Evan You |
| 87 | +- `jsdiff-devtools.js` registers devtools panel |
| 88 | + - injects `console.diff` commands into inspected window's console interface |
| 89 | + - each function clones arguments and sends them via `postMessage` to `jsdiff-proxy.js` in `jsdiff-console-to-proxy` message |
| 90 | + - injects `jsdiff-proxy.js` that listens on window `jsdiff-console-to-proxy` message and sends it further to chrome runtime in `jsdiff-proxy-to-devtools` message |
| 91 | + - listens on `jsdiff-proxy-to-devtools` and prepares payload for `vue/panel.js` and sends it with `jsdiff-devtools-to-panel-compare` message |
| 92 | + - when user invokes devtools search command - informs `vue/panel.js` with `jsdiff-devtools-to-panel-search` message |
| 93 | +- when `vue/panel.js` is visible in devtools |
| 94 | + - reflects result of last compare request |
| 95 | + - listens on `jsdiff-devtools-to-panel-compare` requests |
| 96 | + - listens on `jsdiff-devtools-to-panel-search` and tries to find query in DOM |
0 commit comments