Add destroy hook directly on vnodes

pull/2/head
paldepind 10 years ago
parent 4799cb43e9
commit f5d2b0f861

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

@ -526,6 +526,20 @@ describe('snabbdom', function() {
assert.deepEqual(result, ['pre', 'post']);
});
it('invokes `destroy` hook for all removed children', function() {
var result = [];
function cb(vnode) { result.push(vnode); }
var vnode1 = h('div', [
h('span', 'First sibling'),
h('div', [
h('span', {hook: {destroy: cb}}, 'Child 1'),
h('span', 'Child 2'),
]),
]);
patch(vnode0, vnode1);
patch(vnode1, vnode0);
assert.equal(result.length, 1);
});
it('invokes `destroy` module hook for all removed children', function() {
var created = 0;
var destroyed = 0;
var patch = snabbdom.init([

Loading…
Cancel
Save