Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
Fix mutation on toReact
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Oct 3, 2015
1 parent bad4e8f commit d6b5afb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ Element.prototype.getElementById = function (id) {

Element.prototype.toReact = function (index) {
index = index || 0
var props = this.props
var props = clone(this.props)
props.style = clone(props.style)

function uniqueKey () {
return 'faux-dom-' + index
}

if (typeof props.key === 'undefined') {
props = clone(props)
props.key = uniqueKey()
}

Expand Down
8 changes: 8 additions & 0 deletions test/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ test('pre-built React elements are rendered into the tree', function (t) {
t.plan(1)
t.equal(tree.props.children[0].props.foo, 'bar')
})

test('toReact does not mutate the state', function (t) {
var el = mk().node()
t.plan(2)
t.equal(typeof el.props.style.setProperty, 'function')
el.toReact()
t.equal(typeof el.props.style.setProperty, 'function')
})

0 comments on commit d6b5afb

Please sign in to comment.