diff --git a/package.json b/package.json index e9ccb1a..be4b940 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/snabbdom.js b/snabbdom.js index f7895d5..e55aa10 100644 --- a/snabbdom.js +++ b/snabbdom.js @@ -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]); } diff --git a/test/core.js b/test/core.js index 7f99d61..be41a7f 100644 --- a/test/core.js +++ b/test/core.js @@ -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');