Skip to content

Commit

Permalink
fix(Views): fix angularjs ctrl prop override bug (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni authored and Guria committed Jul 25, 2017
1 parent aff20ea commit e9ca780
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/node_modules/cerebral/src/views/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class View {
this._hasWarnedBigComponent = false
this.isUnmounted = false
this.updateComponent = onUpdate
this.propKeys = Object.keys(props)

if (this.controller.devtools && this.controller.devtools.warnStateProps) {
this.verifyProps(props)
Expand Down Expand Up @@ -293,7 +294,7 @@ class View {
Runs whenever the component has an update and renders.
Extracts the actual values from dependency trackers and/or tags
*/
getProps(props = {}) {
getProps(props = {}, includeProps = true) {
const dependenciesProps = Object.keys(
this.dependencies
).reduce((currentProps, key) => {
Expand Down Expand Up @@ -355,7 +356,7 @@ class View {
)
}

return Object.assign({}, props, dependenciesProps)
return Object.assign({}, includeProps ? props : {}, dependenciesProps)
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/node_modules/cerebral/src/views/angularjs/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CerebralScope {
const hasUpdate = this.view.onPropsUpdate(oldProps, nextProps)

if (hasUpdate) {
Object.assign(this.ctrl, this.view.getProps(nextProps))
Object.assign(this.ctrl, this.view.getProps(nextProps, false))
this.scope.safeApply()
}
}
Expand All @@ -50,12 +50,12 @@ class CerebralScope {
this.$apply(fn)
}
}
Object.assign(this.ctrl, this.view.getProps(this.props))
Object.assign(this.ctrl, this.view.getProps(this.props, false))
}
}
onUpdate(stateChanges, force) {
this.view.updateFromState(stateChanges, this.props, force)
Object.assign(this.ctrl, this.view.getProps(this.props))
Object.assign(this.ctrl, this.view.getProps(this.props, false))
this.scope.safeApply()
}
}
Expand Down

0 comments on commit e9ca780

Please sign in to comment.