https://github.com/canjs/dom-diff
Diffing for a DOM-like DOM.
https://github.com/canjs/dom-diff
Last synced: about 1 year ago
JSON representation
Diffing for a DOM-like DOM.
- Host: GitHub
- URL: https://github.com/canjs/dom-diff
- Owner: canjs
- License: mit
- Created: 2015-07-02T14:12:58.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-07-22T01:02:12.000Z (almost 9 years ago)
- Last Synced: 2025-04-16T01:51:34.919Z (about 1 year ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# dom-diff
Creates diffs of DOM or a virtual DOM that looks like the real DOM.
## Installation
```
npm install dom-diff --save
```
## Usage
```js
var diff = require("dom-diff/diff");
var apply = require("dom-diff/patch");
var a = document.createElement("div");
var b = document.createElement("div");
b.appendChild(document.createElement("span"));
var patches = diff(a, b);
apply(a, patches);
```
## Modules
### dom-diff/diff
```
diff(Element, Element) -> patches
```
Given two elements, diffs them and returns an object containing patches.
### dom-diff/patch
```
patch(Element, patches)
```
Given an element and a set of patches, the patches will be applied to the element.
### dom-diff/serialize
```
serialize(patches) -> serializedPatches
```
Given a `patches` object will serialize it into a plain object that can be sent across WebWorker boundaries. You can further serialize this object to JSON if you need to send it across the network.
## License
MIT