Replace element if it has a parent

pull/18/head
paldepind 10 years ago
parent 35b62dee54
commit 35de88b833

@ -1,6 +1,6 @@
{
"name": "snabbdom",
"version": "0.2.0",
"version": "0.2.1",
"description": "A virtual DOM library with focus on simplicity, modularity, powerful features and performance.",
"main": "snabbdom.js",
"directories": {

@ -208,11 +208,18 @@ function init(modules) {
return function(oldVnode, vnode) {
var i;
insertedVnodeQueue = [];
for (i = 0; i < cbs.pre.length; ++i) cbs.pre[i]();
if (oldVnode instanceof Element) {
oldVnode = emptyNodeAt(oldVnode);
if (oldVnode.parentElement !== null) {
createElm(vnode);
oldVnode.parentElement.replaceChild(vnode.elm, oldVnode);
} else {
oldVnode = emptyNodeAt(oldVnode);
patchVnode(oldVnode, vnode);
}
} else {
patchVnode(oldVnode, vnode);
}
for (i = 0; i < cbs.pre.length; ++i) cbs.pre[i]();
patchVnode(oldVnode, vnode);
for (i = 0; i < insertedVnodeQueue.length; ++i) {
insertedVnodeQueue[i].data.hook.insert(insertedVnodeQueue[i]);
}

@ -60,6 +60,14 @@ describe('snabbdom', function() {
patch(vnode0, h('div'));
assert.equal(elm.tagName, 'DIV');
});
it('has different tag and id', function() {
var elm = document.createElement('div');
vnode0.appendChild(elm);
var vnode1 = h('span#id');
patch(elm, vnode1);
assert.equal(vnode1.elm.tagName, 'SPAN');
assert.equal(vnode1.elm.id, 'id');
});
it('has id', function() {
patch(vnode0, h('div', [h('div#unique')]));
assert.equal(elm.firstChild.id, 'unique');

Loading…
Cancel
Save