Skip to content

Commit

Permalink
fix: change priority hasChange (in submitted Props)
Browse files Browse the repository at this point in the history
  • Loading branch information
fopsdev authored and christianalfoni committed Nov 27, 2016
1 parent 582a630 commit 742e1d4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/cerebral/src/viewFactories/Hoc.js
Expand Up @@ -34,16 +34,18 @@ export default (View) => {
const hasChange = propsDiffer(this.props, nextProps)

// If dynamic paths, we need to update them
if (typeof paths === 'function') {
this.evaluatedPaths = CerebralComponent.getStatePaths(nextProps)
if (hasChange && typeof paths === 'function') {
this.evaluatedPaths = CerebralComponent.getStatePaths(nextProps, this.context.cerebral.controller)

const nextDepsMap = this.getDepsMap()

if (propsDiffer(this.depsMap, nextDepsMap)) {
this.context.cerebral.updateComponent(this, this.depsMap, nextDepsMap)
this.depsMap = nextDepsMap
}
} else if (hasChange) {
}

if (hasChange) {
this._update()
}
}
Expand Down
78 changes: 78 additions & 0 deletions packages/cerebral/src/viewFactories/react.test.js
Expand Up @@ -398,6 +398,84 @@ describe('React', () => {

assert.equal(TestUtils.findRenderedDOMComponentWithTag(tree, 'div').innerHTML, 'bar')
})
it('should update on props change', () => {
const controller = Controller({})
class TestComponentClass2 extends React.Component {
render () {
return (
<div>{this.props.foo}</div>
)
}
}
const TestComponent2 = connect({}, TestComponentClass2)
class TestComponentClass extends React.Component {
constructor (props) {
super(props)
this.state = {foo: 'bar'}
}
changePath () {
this.setState({
foo: 'bar2'
})
}
render () {
return (
<span><TestComponent2 foo={this.state.foo} /></span>
)
}
}
const TestComponent = connect({}, TestComponentClass)
const tree = TestUtils.renderIntoDocument((
<Container controller={controller}>
<TestComponent />
</Container>
))
assert.equal(TestUtils.findRenderedDOMComponentWithTag(tree, 'div').innerHTML, 'bar')
const component = TestUtils.findRenderedComponentWithType(tree, TestComponentClass)
component.changePath()
assert.equal(TestUtils.findRenderedDOMComponentWithTag(tree, 'div').innerHTML, 'bar2')
})
it('should update on dynamic connect and props change', () => {
const controller = Controller({
state: {
users: {0: 'foo', 1: 'bar'},
currentUser: '0'
},
signals: {
changeUser: [
({state}) => state.set('currentUser', '1')
]
}
})
class TestComponentClass2 extends React.Component {
render () {
return (
<div>{this.props.user}</div>
)
}
}
const TestComponent2 = connect((props) => ({
user: `users.${props.currentUser}`
}), TestComponentClass2)
class TestComponentClass extends React.Component {
render () {
return (
<span><TestComponent2 currentUser={this.props.currentUser} /></span>
)
}
}
const TestComponent = connect({
currentUser: 'currentUser'
}, TestComponentClass)
const tree = TestUtils.renderIntoDocument((
<Container controller={controller}>
<TestComponent />
</Container>
))
assert.equal(TestUtils.findRenderedDOMComponentWithTag(tree, 'div').innerHTML, 'foo')
controller.getSignal('changeUser')()
assert.equal(TestUtils.findRenderedDOMComponentWithTag(tree, 'div').innerHTML, 'bar')
})
describe('STRICT render update', () => {
it('should not update when parent path changes', () => {
let renderCount = 0
Expand Down

0 comments on commit 742e1d4

Please sign in to comment.