Do not invoke `destroy` hook for text nodes

pull/8/head
paldepind 10 years ago
parent 24206f430a
commit 7344b0aca5

@ -90,11 +90,13 @@ function init(modules) {
function invokeDestroyHook(vnode) { function invokeDestroyHook(vnode) {
var i = vnode.data, j; var i = vnode.data, j;
if (!isUndef(i) && !isUndef(i = i.hook) && !isUndef(i = i.destroy)) i(vnode); if (!isUndef(i)) {
for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode); if (!isUndef(i = i.hook) && !isUndef(i = i.destroy)) i(vnode);
if (!isUndef(i = vnode.children)) { for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode);
for (j = 0; j < vnode.children.length; ++j) { if (!isUndef(i = vnode.children)) {
invokeDestroyHook(vnode.children[j]); for (j = 0; j < vnode.children.length; ++j) {
invokeDestroyHook(vnode.children[j]);
}
} }
} }
} }

@ -656,6 +656,25 @@ describe('snabbdom', function() {
assert.equal(created, 4); assert.equal(created, 4);
assert.equal(destroyed, 4); assert.equal(destroyed, 4);
}); });
it('does not invoke `destroy` module hook for text nodes', function() {
var created = 0;
var destroyed = 0;
var patch = snabbdom.init([
{create: function() { created++; }},
{destroy: function() { destroyed++; }},
]);
var vnode1 = h('div', [
h('span', 'First sibling'),
h('div', [
h('span', 'Child 1'),
h('span', ['Text 1', 'Text 2']),
]),
]);
patch(vnode0, vnode1);
patch(vnode1, vnode0);
assert.equal(created, 4);
assert.equal(destroyed, 4);
});
}); });
}); });
describe('short circuiting', function() { describe('short circuiting', function() {

Loading…
Cancel
Save