When a vnode has 'text' property, remove the text node if vnode ispatched with children.

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

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

@ -456,6 +456,15 @@ describe('snabbdom', function() {
patch(vnode1, vnode2); patch(vnode1, vnode2);
assert.equal(elm.textContent, ''); assert.equal(elm.textContent, '');
}); });
it('removes a single text node when children are updated', function() {
var vnode1 = h('div', 'One');
var vnode2 = h('div', [ h('div', 'Two'), h('span', 'Three') ]);
patch(vnode0, vnode1);
assert.equal(elm.textContent, 'One');
patch(vnode1, vnode2);
console.log(elm.childNodes);
assert.deepEqual(map(prop('textContent'), elm.childNodes), ['Two', 'Three']);
});
it('removes a text node among other elements', function() { it('removes a text node among other elements', function() {
var vnode1 = h('div', [ 'One', h('span', 'Two') ]); var vnode1 = h('div', [ 'One', h('span', 'Two') ]);
var vnode2 = h('div', [ h('div', 'Three')]); var vnode2 = h('div', [ h('div', 'Three')]);

Loading…
Cancel
Save