When a vnode has 'text' property, remove the text node if patched with no 'text'.

pull/68/head
Ray Di Ciaccio 9 years ago
parent ab5d2d89e3
commit 116950cd5b

@ -198,6 +198,8 @@ function init(modules) {
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
} else if (isDef(oldCh)) {
removeVnodes(elm, oldCh, 0, oldCh.length - 1);
} else if (isDef(oldVnode.text)) {
elm.textContent = '';
}
} else if (oldVnode.text !== vnode.text) {
elm.textContent = vnode.text;

@ -448,6 +448,24 @@ describe('snabbdom', function() {
patch(vnode1, vnode2);
assert.deepEqual(map(inner, elm.children), ['One', 'Three']);
});
it('removes a single text node', function() {
var vnode1 = h('div', 'One');
var vnode2 = h('div');
patch(vnode0, vnode1);
assert.equal(elm.textContent, 'One');
patch(vnode1, vnode2);
assert.equal(elm.textContent, '');
});
it('removes a text node among other elements', function() {
var vnode1 = h('div', [ 'One', h('span', 'Two') ]);
var vnode2 = h('div', [ h('div', 'Three')]);
patch(vnode0, vnode1);
assert.deepEqual(map(prop('textContent'), elm.childNodes), ['One', 'Two']);
patch(vnode1, vnode2);
assert.equal(elm.childNodes.length, 1);
assert.equal(elm.childNodes[0].tagName, 'DIV');
assert.equal(elm.childNodes[0].textContent, 'Three');
});
it('reorders elements', function() {
var vnode1 = h('div', [h('span', 'One'), h('div', 'Two'), h('b', 'Three')]);
var vnode2 = h('div', [h('b', 'Three'), h('span', 'One'), h('div', 'Two')]);

Loading…
Cancel
Save