Merge pull request #159 from staltz/master

Fix patch() so that the root is patched instead of recreated
pull/165/head
Simon Friis Vindum 9 years ago committed by GitHub
commit 4475a6f325

@ -39,7 +39,9 @@ function init(modules, api) {
}
function emptyNodeAt(elm) {
return VNode(api.tagName(elm).toLowerCase(), {}, [], undefined, elm);
var id = elm.id ? '#' + elm.id : '';
var c = elm.className ? '.' + elm.className.split(' ').join('.') : '';
return VNode(api.tagName(elm).toLowerCase() + id + c, {}, [], undefined, elm);
}
function createRmCb(childElm, listeners) {

@ -136,6 +136,17 @@ describe('snabbdom', function() {
done();
}
});
it('is a patch of the root element', function () {
var elmWithIdAndClass = document.createElement('div');
elmWithIdAndClass.id = 'id';
elmWithIdAndClass.className = 'class';
var vnode1 = h('div#id.class', [h('span', 'Hi')]);
elm = patch(elmWithIdAndClass, vnode1).elm;
assert.strictEqual(elm, elmWithIdAndClass);
assert.equal(elm.tagName, 'DIV');
assert.equal(elm.id, 'id');
assert.equal(elm.className, 'class');
});
});
describe('pathing an element', function() {
it('changes the elements classes', function() {

Loading…
Cancel
Save