From 211a668ddc6756718e107c9ff1fe64ef3871f5e5 Mon Sep 17 00:00:00 2001 From: Svetlana Linuxenko Date: Wed, 29 Mar 2017 09:25:31 +0300 Subject: [PATCH] Update components props fix --- lib/h.js | 8 +++++++- package.json | 2 +- tests/mocha-tests/h.test.js | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/h.js b/lib/h.js index 078e363..52969c4 100644 --- a/lib/h.js +++ b/lib/h.js @@ -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); } diff --git a/package.json b/package.json index bc7af5c..a8e9568 100644 --- a/package.json +++ b/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": [ diff --git a/tests/mocha-tests/h.test.js b/tests/mocha-tests/h.test.js index 666f37b..63c8ce8 100644 --- a/tests/mocha-tests/h.test.js +++ b/tests/mocha-tests/h.test.js @@ -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'); + }); });