state-tree
Advanced tools
Comparing version 0.1.15 to 0.1.16
{ | ||
"name": "state-tree", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"description": "A state tree that handles reference updates and lets you flush a description of changes", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
var React = require('react'); | ||
function hasChanged(path, changes) { | ||
return path.split('.').reduce(function (changes, key) { | ||
return changes[key]; | ||
path = Array.isArray(path) ? path : path.split('.'); | ||
return path.reduce(function (changes, key) { | ||
return changes ? changes[key] : false; | ||
}, changes); | ||
@@ -12,9 +13,9 @@ } | ||
contextTypes: { | ||
tree: React.PropTypes.object | ||
controller: React.PropTypes.object | ||
}, | ||
componentWillMount() { | ||
this.context.tree.subscribe(this.update); | ||
this.context.controller.on('flush', this.update); | ||
}, | ||
componentWillUnmount() { | ||
this.context.tree.unsubscribe(this.update); | ||
this.context.controller.removeListener('flush', this.update); | ||
}, | ||
@@ -24,4 +25,4 @@ update(changes) { | ||
if ( | ||
(typeof paths[key] === 'object' && paths[key].hasChanged(changes)) || | ||
(typeof paths[key] !== 'object' && hasChanged(paths[key], changes)) | ||
(paths[key].hasChanged && paths[key].hasChanged(changes)) || | ||
(!paths[key].hasChanged && hasChanged(paths[key], changes)) | ||
) { | ||
@@ -33,6 +34,6 @@ return this.forceUpdate(); | ||
getProps() { | ||
var tree = this.context.tree; | ||
var controller = this.context.controller; | ||
var props = this.props || {}; | ||
var propsToPass = Object.keys(paths || {}).reduce(function (props, key) { | ||
props[key] = typeof paths[key] === 'object' ? paths[key].get(tree.get()) : tree.get(paths[key]); | ||
props[key] = paths[key].hasChanged ? paths[key].get(controller.get()) : controller.get(paths[key]); | ||
return props | ||
@@ -46,2 +47,4 @@ }, {}) | ||
propsToPass.signals = this.context.controller.getSignals(); | ||
return propsToPass | ||
@@ -48,0 +51,0 @@ }, |
@@ -322,3 +322,6 @@ var subscribers = []; | ||
for (var key in deps) { | ||
if (hasChanged(deps[key], changes)) { | ||
if ( | ||
(typeof deps[key] === 'string' && hasChanged(deps[key], changes)) || | ||
(typeof deps[key] !== 'string' && deps[key].hasChanged(changes)) | ||
) { | ||
computedHasChanged = true; | ||
@@ -325,0 +328,0 @@ return true; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37142
11
918