diff --git a/package.json b/package.json index e0e9476..f33678a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "snabbdom", - "version": "0.1.1", + "version": "0.1.2", "description": "A virtual DOM library with focus on simplicity, modularity, powerful features and performance.", "main": "snabbdom.js", "directories": { diff --git a/snabbdom.js b/snabbdom.js index 3bda104..fc28897 100644 --- a/snabbdom.js +++ b/snabbdom.js @@ -94,10 +94,10 @@ function init(modules) { } function invokeDestroyHook(vnode) { - var i = vnode.data.hook, j; - if (!isUndef(i) && !isUndef(j = i.destroy)) j(vnode); + var i = vnode.data, j; + if (!isUndef(i) && !isUndef(i = i.hook) && !isUndef(i = i.destroy)) i(vnode); for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode); - if (!isUndef(vnode.children)) { + if (!isUndef(i = vnode.children)) { for (j = 0; j < vnode.children.length; ++j) { invokeDestroyHook(vnode.children[j]); } @@ -112,8 +112,8 @@ function init(modules) { rm = createRmCb(parentElm, ch.elm, listeners); for (i = 0; i < cbs.remove.length; ++i) cbs.remove[i](ch, rm); invokeDestroyHook(ch); - if (ch.data.hook && ch.data.hook.remove) { - ch.data.hook.remove(ch, rm); + if (!isUndef(i = ch.data) && !isUndef(i = i.hook) && !isUndef(i = i.remove)) { + i(ch, rm); } else { rm(); } diff --git a/test/core.js b/test/core.js index 0379ae0..cad5768 100644 --- a/test/core.js +++ b/test/core.js @@ -593,6 +593,14 @@ describe('snabbdom', function() { patch(vnode1, vnode0); assert.equal(result.length, 1); }); + it('handles text vnodes with `undefined` `data` property', function() { + var vnode1 = h('div', [ + ' ' + ]); + var vnode2 = h('div', []); + patch(vnode0, vnode1); + patch(vnode1, vnode2); + }); it('invokes `destroy` module hook for all removed children', function() { var created = 0; var destroyed = 0;