Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Update components props fix
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxenko committed Mar 29, 2017
1 parent 6522c72 commit 211a668
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/h.js
Expand Up @@ -19,7 +19,13 @@ var H = function (argv) {
}

if (typeof argv === 'object' && typeof argv.render === 'function') {
argv.props = arguments[1] || {};
if ('props' in argv) {
for (var i in arguments[1]) {
argv.props[i] = arguments[1][i];
}
} else {
argv.props = arguments[1];
}
argv.props.children = [].slice.call(arguments, 2, arguments.length);
return argv.render.call(argv, argv.props);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "basic-virtual-dom",
"version": "0.3.0",
"version": "0.3.1",
"description": "Basic virtual dom implementation",
"main": "index.js",
"files": [
Expand Down
16 changes: 16 additions & 0 deletions tests/mocha-tests/h.test.js
Expand Up @@ -147,4 +147,20 @@ describe('Test h()', function() {
expect(cl.children[0].children[0].children).to.be.equal('hello');
expect(cl.children[0].children[1].children).to.be.equal('world');
});

it('should only update props', function() {
var Nested = {
props: { ownProp: 'keepme' },
render: function() {
return h('div', null, this.props.name, this.props.children, this.props.ownProp);
}
};

var cl = h('div', null, h(Nested, {name: 'hello'}, 'world'));

expect(cl.children[0].children.length).to.be.equal(3);
expect(cl.children[0].children[0].children).to.be.equal('hello');
expect(cl.children[0].children[1].children).to.be.equal('world');
expect(cl.children[0].children[2].children).to.be.equal('keepme');
});
});

0 comments on commit 211a668

Please sign in to comment.