Comparing version 1.2.0 to 2.0.0
@@ -33,2 +33,4 @@ var assert = require('assert') | ||
return null | ||
} else if (newNode.isSameNode && newNode.isSameNode(oldNode)) { | ||
return oldNode | ||
} else if (newNode !== oldNode) { | ||
@@ -35,0 +37,0 @@ if (newNode.tagName !== oldNode.tagName) { |
{ | ||
"name": "nanomorph", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Hyper fast diffing algorithm for real DOM nodes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,4 +8,4 @@ # nanomorph [![stability][0]][1] | ||
```js | ||
const nanomorph = require('nanomorph') | ||
const html = require('bel') | ||
var nanomorph = require('nanomorph') | ||
var html = require('bel') | ||
@@ -19,8 +19,8 @@ var tree = html`<div>hello people</div>` | ||
```js | ||
const updateDom = require('nanomorph/update-dom') | ||
const html = require('bel') | ||
var update = require('nanomorph/update') | ||
var html = require('bel') | ||
// create the initial tree, save it and append to DOM | ||
const tree = html`<div>hello people</div>` | ||
const update = updateDom(tree) | ||
var tree = html`<div>hello people</div>` | ||
var update = update(tree) | ||
document.body.appendChild(tree) | ||
@@ -55,9 +55,14 @@ | ||
## See Also | ||
- [morphdom][morphdom] | ||
- [yo-yo][yo-yo] | ||
- [bel][bel] | ||
- [nanoraf][nanoraf] | ||
- [choo][choo] | ||
- [set-dom][set-dom] | ||
- [min-document][mindoc] | ||
- [yoshuawuyts/nanoraf](https://github.com/yoshawuyts/nanoraf) | ||
- [yoshuawuyts/nanocomponent](https://github.com/yoshuawuyts/nanocomponent) | ||
- [yoshuawuyts/nanotick](https://github.com/yoshuawuyts/nanotick) | ||
- [bendrucker/document-ready](https://github.com/bendrucker/document-ready) | ||
- [shama/on-load](https://github.com/shama/on-load) | ||
- [shama/bel](https://github.com/shama/bel) | ||
## Similar Packages | ||
- [patrick-steele-idem/morphdom](https://github.com/patrick-steele-idem/morphdom) | ||
- [tbranyen/diffhtml](https://github.com/tbranyen/diffhtml) | ||
## Further Reading | ||
- [how to write your own virtual dom 1][own-vdom-1] | ||
@@ -69,10 +74,2 @@ - [how to write your own virtual dom 2][own-vdom-2] | ||
[own-vdom-1]: https://medium.com/@deathmood/how-to-write-your-own-virtual-dom-ee74acc13060 | ||
[own-vdom-2]: https://medium.com/@deathmood/write-your-virtual-dom-2-props-events-a957608f5c76 | ||
[mindoc]: https://github.com/Raynos/min-document | ||
[nanoraf]: https://github.com/yoshuawuyts/nanoraf | ||
[bel]: https://github.com/shama/bel | ||
[choo]: https://github.com/yoshuawuyts/choo | ||
[set-dom]: https://github.com/DylanPiercey/set-dom | ||
[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square | ||
@@ -90,4 +87,5 @@ [1]: https://nodejs.org/api/documentation.html#documentation_stability_index | ||
[11]: https://github.com/feross/standard | ||
[morphdom]: https://github.com/patrick-steele-idem/morphdom | ||
[yo-yo]: https://github.com/maxogden/yo-yo | ||
[mt]: https://en.wikipedia.org/wiki/Merkle_tree | ||
[own-vdom-1]: https://medium.com/@deathmood/how-to-write-your-own-virtual-dom-ee74acc13060 | ||
[own-vdom-2]: https://medium.com/@deathmood/write-your-virtual-dom-2-props-events-a957608f5c76 |
72
test.js
@@ -5,4 +5,4 @@ var test = require('tape') | ||
test('nanomorph', (t) => { | ||
t.test('should assert input types', (t) => { | ||
test('nanomorph', function (t) { | ||
t.test('should assert input types', function (t) { | ||
t.plan(2) | ||
@@ -13,4 +13,4 @@ t.throws(nanomorph, /newTree/) | ||
t.test('root level', (t) => { | ||
t.test('should replace a node', (t) => { | ||
t.test('root level', function (t) { | ||
t.test('should replace a node', function (t) { | ||
t.plan(1) | ||
@@ -26,3 +26,3 @@ | ||
t.test('should morph a node', (t) => { | ||
t.test('should morph a node', function (t) { | ||
t.plan(1) | ||
@@ -38,3 +38,3 @@ | ||
t.test('should morph a node with namespaced attribute', (t) => { | ||
t.test('should morph a node with namespaced attribute', function (t) { | ||
t.plan(1) | ||
@@ -50,3 +50,3 @@ | ||
t.test('should ignore if node is same', (t) => { | ||
t.test('should ignore if node is same', function (t) { | ||
t.plan(1) | ||
@@ -62,4 +62,4 @@ | ||
t.test('nested', (t) => { | ||
t.test('should replace a node', (t) => { | ||
t.test('nested', function (t) { | ||
t.test('should replace a node', function (t) { | ||
t.plan(1) | ||
@@ -79,3 +79,3 @@ | ||
t.test('should replace a node', (t) => { | ||
t.test('should replace a node', function (t) { | ||
t.plan(1) | ||
@@ -95,3 +95,3 @@ | ||
t.test('should replace a node', (t) => { | ||
t.test('should replace a node', function (t) { | ||
t.plan(1) | ||
@@ -108,3 +108,3 @@ | ||
t.test('should append a node', (t) => { | ||
t.test('should append a node', function (t) { | ||
t.plan(1) | ||
@@ -124,3 +124,3 @@ | ||
t.test('should remove a node', (t) => { | ||
t.test('should remove a node', function (t) { | ||
t.plan(1) | ||
@@ -142,8 +142,8 @@ | ||
t.test('events', (t) => { | ||
t.test('should copy onclick events', (t) => { | ||
t.test('events', function (t) { | ||
t.test('should copy onclick events', function (t) { | ||
t.plan(2) | ||
const oldTree = html` | ||
var oldTree = html` | ||
<button | ||
onclick=${() => { | ||
onclick=${function () { | ||
t.ok(true) | ||
@@ -154,4 +154,4 @@ }} | ||
</button>` | ||
const newTree = html`<button>UPDATED</button>` | ||
const res = nanomorph(newTree, oldTree) | ||
var newTree = html`<button>UPDATED</button>` | ||
var res = nanomorph(newTree, oldTree) | ||
t.ok(typeof res.onclick === 'function') | ||
@@ -161,13 +161,13 @@ res.onclick() | ||
t.test('should copy onsubmit events', (t) => { | ||
const oldTree = html` | ||
t.test('should copy onsubmit events', function (t) { | ||
var oldTree = html` | ||
<form | ||
onsubmit=${() => { t.ok(false) }} | ||
onsubmit=${function () { t.ok(false) }} | ||
> | ||
<button>Sup</button> | ||
</form>` | ||
const newTree = html`<form> | ||
var newTree = html`<form> | ||
<button>Sup</button> | ||
</form>` | ||
const res = nanomorph(newTree, oldTree) | ||
var res = nanomorph(newTree, oldTree) | ||
t.ok(typeof res.onsubmit === 'function') | ||
@@ -177,2 +177,26 @@ t.end() | ||
}) | ||
t.test('isSameNode', function (t) { | ||
t.test('should return oldTree if true', function (t) { | ||
t.plan(1) | ||
var oldTree = html`<div>YOLO</div>` | ||
var newTree = html`<div>FOMO</div>` | ||
newTree.isSameNode = function (el) { | ||
return true | ||
} | ||
var res = nanomorph(newTree, oldTree) | ||
t.equal(res.childNodes[0].data, 'YOLO') | ||
}) | ||
t.test('should return newTree if false', function (t) { | ||
t.plan(1) | ||
var oldTree = html`<div>YOLO</div>` | ||
var newTree = html`<div>FOMO</div>` | ||
newTree.isSameNode = function (el) { | ||
return false | ||
} | ||
var res = nanomorph(newTree, oldTree) | ||
t.equal(res.childNodes[0].data, 'FOMO') | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16323
351
87