state-tree
Advanced tools
Comparing version 0.1.8 to 0.1.9
{ | ||
"name": "state-tree", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "A state tree that handles reference updates and lets you flush a description of changes", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -34,3 +34,3 @@ var React = require('react'); | ||
var propsToPass = Object.keys(paths || {}).reduce(function (props, key) { | ||
props[key] = typeof paths[key] === 'object' ? paths[key].get() : tree.get(paths[key]); | ||
props[key] = typeof paths[key] === 'object' ? paths[key].get(tree.get()) : tree.get(paths[key]); | ||
return props | ||
@@ -37,0 +37,0 @@ }, {}) |
@@ -215,3 +215,3 @@ # state-tree (EXPERIMENTAL) | ||
myComputed.get() // "bar!!!" | ||
myComputed.get(tree) // "bar!!!" | ||
let changes = tree.flushChanges(); // {} | ||
@@ -222,3 +222,3 @@ myComputed.hasChanged(changes); // false | ||
myComputed.hasChanged(changes); // true | ||
myComputed.get() // "bar2!!!" | ||
myComputed.get(tree) // "bar2!!!" | ||
``` | ||
@@ -231,4 +231,9 @@ So, this seems like a lot of code to make computed work, but again, this is low level. Implemented in the HOC of React you can simply do this. | ||
import addItem from './addItem'; | ||
import awesomeItems from './computed/awesomeItems'; | ||
const awesomeItems = computed({ | ||
list: 'list' // Define its deps | ||
}, state => { | ||
return state.list.filter(item => item.isAwesome); | ||
}); | ||
function Items(props) { | ||
@@ -249,13 +254,3 @@ return ( | ||
``` | ||
And *awesomeItems.js* would look like: | ||
```js | ||
import tree from './tree'; | ||
export default tree.computed({ | ||
list: 'list' // Define its deps | ||
}, state => { | ||
return state.list.filter(item => item.isAwesome); | ||
}); | ||
``` | ||
There is no magic going on here. The components will pass in the flushed "change tree" to whatever computed they have. This is what tells them to verify if an update is necessary, if not already ready to calculate a new value. |
@@ -235,3 +235,3 @@ var subscribers = []; | ||
return { | ||
get: function (changes) { | ||
get: function (passedState) { | ||
if (computedHasChanged) { | ||
@@ -241,3 +241,3 @@ computedHasChanged = false; | ||
var path = deps[key].split('.'); | ||
props[key] = getByPath(path, state); | ||
props[key] = getByPath(path, passedState); | ||
return props; | ||
@@ -244,0 +244,0 @@ }, {})); |
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
32677
253