Comparing version 0.7.2 to 0.7.3
@@ -23,3 +23,3 @@ function invokeHandler(handler, vnode, event) { | ||
for (var i = 0; i < handler.length; i++) { | ||
invokeHandler(handler[i]); | ||
invokeHandler(handler[i], vnode, event); | ||
} | ||
@@ -26,0 +26,0 @@ } |
@@ -1,2 +0,3 @@ | ||
var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout; | ||
// Bindig `requestAnimationFrame` like this fixes a bug in IE/Edge. See #360 and #409. | ||
var raf = (typeof window !== 'undefined' && (window.requestAnimationFrame).bind(window)) || setTimeout; | ||
var nextFrame = function (fn) { raf(function () { raf(fn); }); }; | ||
@@ -3,0 +4,0 @@ var reflowForced = false; |
@@ -270,2 +270,5 @@ import vnode from './vnode'; | ||
else if (oldVnode.text !== vnode.text) { | ||
if (isDef(oldCh)) { | ||
removeVnodes(elm, oldCh, 0, oldCh.length - 1); | ||
} | ||
api.setTextContent(elm, vnode.text); | ||
@@ -272,0 +275,0 @@ } |
@@ -25,3 +25,3 @@ "use strict"; | ||
for (var i = 0; i < handler.length; i++) { | ||
invokeHandler(handler[i]); | ||
invokeHandler(handler[i], vnode, event); | ||
} | ||
@@ -28,0 +28,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout; | ||
// Bindig `requestAnimationFrame` like this fixes a bug in IE/Edge. See #360 and #409. | ||
var raf = (typeof window !== 'undefined' && (window.requestAnimationFrame).bind(window)) || setTimeout; | ||
var nextFrame = function (fn) { raf(function () { raf(fn); }); }; | ||
@@ -5,0 +6,0 @@ var reflowForced = false; |
{ | ||
"name": "snabbdom", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "A virtual DOM library with focus on simplicity, modularity, powerful features and performance.", | ||
@@ -12,3 +12,2 @@ "main": "snabbdom.js", | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -23,5 +22,11 @@ "benchmark": "^2.1.4", | ||
"gulp-uglify": "^3.0.0", | ||
"karma": "^3.0.0", | ||
"karma-browserstack-launcher": "^1.3.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-typescript": "^3.0.13", | ||
"knuth-shuffle": "^1.0.1", | ||
"testem": "^1.18.1", | ||
"typescript": "^2.4.2", | ||
"mocha": "^5.2.0", | ||
"typescript": "^3.0.3", | ||
"xyz": "2.1.0" | ||
@@ -28,0 +33,0 @@ }, |
@@ -458,2 +458,10 @@ # Snabbdom | ||
Each handler is called not only with the given arguments but also with the current event and vnode appended to the argument list. It also supports using multiple listeners per event by specifying an array of handlers: | ||
```javascript | ||
stopPropagation = function(ev) { ev.stopPropagation() } | ||
sendValue = function(func, ev, vnode) { func(vnode.elm.value) } | ||
h('a', { on:{ click:[[sendValue, console.log], stopPropagation] } }); | ||
``` | ||
Snabbdom allows swapping event handlers between renders. This happens without | ||
@@ -712,1 +720,41 @@ actually touching the event handlers attached to the DOM. | ||
using Snabbdom. | ||
## Common errors | ||
``` | ||
Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': | ||
The node before which the new node is to be inserted is not a child of this node. | ||
``` | ||
The reason for this error is reusing of vnodes between patches (see code example), snabbdom stores actual dom nodes inside the virtual dom nodes passed to it as performance improvement, so reusing nodes between patches is not supported. | ||
```js | ||
var sharedNode = h('div', {}, 'Selected'); | ||
var vnode1 = h('div', [ | ||
h('div', {}, ['One']), | ||
h('div', {}, ['Two']), | ||
h('div', {}, [sharedNode]), | ||
]); | ||
var vnode2 = h('div', [ | ||
h('div', {}, ['One']), | ||
h('div', {}, [sharedNode]), | ||
h('div', {}, ['Three']), | ||
]); | ||
patch(container, vnode1); | ||
patch(vnode1, vnode2); | ||
``` | ||
You can fix this issue by creating a shallow copy of the object (here with object spread syntax): | ||
```js | ||
var vnode2 = h('div', [ | ||
h('div', {}, ['One']), | ||
h('div', {}, [{ ...sharedNode }]), | ||
h('div', {}, ['Three']), | ||
]); | ||
``` | ||
Another solution would be to wrap shared vnodes in a factory function: | ||
```js | ||
var sharedNode = () => h('div', {}, 'Selected'); | ||
var vnode1 = h('div', [ | ||
h('div', {}, ['One']), | ||
h('div', {}, ['Two']), | ||
h('div', {}, [sharedNode()]), | ||
]); | ||
``` |
@@ -274,2 +274,5 @@ "use strict"; | ||
else if (oldVnode.text !== vnode.text) { | ||
if (isDef(oldCh)) { | ||
removeVnodes(elm, oldCh, 0, oldCh.length - 1); | ||
} | ||
api.setTextContent(elm, vnode.text); | ||
@@ -276,0 +279,0 @@ } |
@@ -29,3 +29,3 @@ import {VNode, VNodeData} from '../vnode'; | ||
for (var i = 0; i < handler.length; i++) { | ||
invokeHandler(handler[i]); | ||
invokeHandler(handler[i], vnode, event); | ||
} | ||
@@ -112,2 +112,2 @@ } | ||
} as Module; | ||
export default eventListenersModule; | ||
export default eventListenersModule; |
@@ -9,3 +9,4 @@ import {VNode, VNodeData} from '../vnode'; | ||
var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout; | ||
// Bindig `requestAnimationFrame` like this fixes a bug in IE/Edge. See #360 and #409. | ||
var raf = (typeof window !== 'undefined' && (window.requestAnimationFrame).bind(window)) || setTimeout; | ||
var nextFrame = function(fn: any) { raf(function() { raf(fn); }); }; | ||
@@ -12,0 +13,0 @@ var reflowForced = false; |
@@ -279,2 +279,5 @@ /* global module, document, Node */ | ||
} else if (oldVnode.text !== vnode.text) { | ||
if (isDef(oldCh)) { | ||
removeVnodes(elm, oldCh as Array<VNode>, 0, (oldCh as Array<VNode>).length - 1); | ||
} | ||
api.setTextContent(elm, vnode.text as string); | ||
@@ -281,0 +284,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances 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
803795
176
8637
759
18
52