Comparing version 0.1.12 to 0.1.13
@@ -127,2 +127,3 @@ // Create a range object for efficently rendering strings to elements. | ||
var onBeforeMorphElChildren = options.onBeforeMorphElChildren || noop; | ||
var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop; | ||
@@ -173,4 +174,7 @@ function removeNodeHelper(node, nestedInSavedEl) { | ||
function removeNode(node, parentNode, alreadyVisited) { | ||
if (onBeforeNodeDiscarded(node) === false) { | ||
return; | ||
} | ||
parentNode.removeChild(node); | ||
if (alreadyVisited) { | ||
@@ -177,0 +181,0 @@ if (!node.id) { |
@@ -36,3 +36,3 @@ { | ||
"dependencies": {}, | ||
"version": "0.1.12" | ||
"version": "0.1.13" | ||
} |
@@ -69,2 +69,3 @@ morphdom | ||
- *onBeforeNodeDiscarded* (`Function(node)`) - A function that will called before a `Node` in the `from` tree has been discarded. If the listener function returns `false` then the element will not be discarded. | ||
- *onNodeDiscarded* (`Function(node)`) - A function that will called when a `Node` in the `from` tree has been discarded and will no longer exist in the final DOM tree. | ||
@@ -77,2 +78,5 @@ - *onBeforeMorphEl* (`Function(fromEl, toEl)`) - A function that will called when a `HTMLElement` in the `from` tree is about to be morphed. If the listener function returns `false` then the element will be skipped. | ||
var morphedNode = morphdom(fromNode, toNode, { | ||
onBeforeNodeDiscarded: function(node) { | ||
return true; | ||
} | ||
onNodeDiscarded: function(node) { | ||
@@ -128,9 +132,9 @@ | ||
## Is this module used by any library/framework? | ||
## What projects are using `morphdom`? | ||
This module will be used by the next major version of [Marko Widgets](https://github.com/marko-js/marko-widgets) (currently in beta: `npm install marko-widgets@^5.0.0-beta --save`). Marko Widgets is a high performance and lightweight UI components framework that uses the [Marko templating engine](https://github.com/marko-js/marko) for rendering UI components. | ||
`morphdom` is being used in the following projects: | ||
You can see how Marko Widgets compares to React in performance by taking a look at the following benchmark: [Marko vs React: Performance Benchmark](https://github.com/patrick-steele-idem/marko-vs-react) | ||
- __[Marko Widgets](https://github.com/marko-js/marko-widgets)__ (`v5.0.0-beta+`) - Marko Widgets is a high performance and lightweight UI components framework that uses the [Marko templating engine](https://github.com/marko-js/marko) for rendering UI components. You can see how Marko Widgets compares to React in performance by taking a look at the following benchmark: [Marko vs React: Performance Benchmark](https://github.com/patrick-steele-idem/marko-vs-react) | ||
However, `morphdom` was designed to be standalone and will work with any library or framework. | ||
_NOTE: If you are using a `morphdom` in your project please send a PR to add your project here_ | ||
@@ -137,0 +141,0 @@ # Benchmarks |
@@ -149,2 +149,9 @@ var chai = require('chai'); | ||
function onBeforeNodeDiscarded(node) { | ||
if (node.$onBeforeNodeDiscarded) { | ||
throw new Error('Duplicate oonBeforeNodeDiscarded for: ' + serializeNode(node)); | ||
} | ||
node.$onBeforeNodeDiscarded = true; | ||
} | ||
function onNodeDiscarded(node) { | ||
@@ -175,2 +182,3 @@ if (node.$onNodeDiscarded) { | ||
var morphedNode = morphdom(fromNode, toNode, { | ||
onBeforeNodeDiscarded: onBeforeNodeDiscarded, | ||
onNodeDiscarded: onNodeDiscarded, | ||
@@ -365,2 +373,27 @@ onBeforeMorphEl: onBeforeMorphEl, | ||
it('should allow discarding to be skipped for a node', function() { | ||
var el1a = document.createElement('div'); | ||
var el1b = document.createElement('b'); | ||
var el1c = document.createElement('span'); | ||
var el1d = document.createElement('a'); | ||
el1a.appendChild(el1b); | ||
el1a.appendChild(el1c); | ||
el1a.appendChild(el1d); | ||
var el2a = document.createElement('div'); | ||
var el2b = document.createElement('a'); | ||
el2a.appendChild(el2b); | ||
morphdom(el1a, el2a, { | ||
onBeforeNodeDiscarded: function(el) { | ||
if (el.tagName === 'B') { | ||
return false; | ||
} | ||
} | ||
}); | ||
expect(el1a.childNodes[0].tagName).to.equal('B'); | ||
expect(el1a.childNodes[1].tagName).to.equal('A'); | ||
}); | ||
it('should transform a simple el to a target HTML string', function() { | ||
@@ -367,0 +400,0 @@ var el1 = document.createElement('div'); |
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
135059
953
470