state-tree
Advanced tools
Comparing version 0.1.9 to 0.1.10
{ | ||
"name": "state-tree", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "A state tree that handles reference updates and lets you flush a description of changes", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -228,2 +228,3 @@ # state-tree (EXPERIMENTAL) | ||
import HOC from 'state-tree/react/HOC'; | ||
import {computed} from 'state-tree'; | ||
import addItem from './addItem'; | ||
@@ -230,0 +231,0 @@ |
@@ -231,43 +231,39 @@ var subscribers = []; | ||
}, | ||
computed: function (deps, cb) { | ||
var computedHasChanged = true; | ||
var value = null; | ||
return { | ||
get: function (passedState) { | ||
if (computedHasChanged) { | ||
computedHasChanged = false; | ||
value = cb(Object.keys(deps).reduce(function (props, key) { | ||
var path = deps[key].split('.'); | ||
props[key] = getByPath(path, passedState); | ||
return props; | ||
}, {})); | ||
return value; | ||
} else { | ||
return value; | ||
} | ||
}, | ||
// Can optimize by remembering the changes in case multiple | ||
// components checks the computed, but very unlikely | ||
hasChanged: function (changes) { | ||
if (computedHasChanged) { | ||
return true; | ||
} | ||
for (var key in deps) { | ||
if (hasChanged(deps[key], changes)) { | ||
computedHasChanged = true; | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
}; | ||
StateTree.computed = function (deps, cb) { | ||
var computedHasChanged = true; | ||
var value = null; | ||
return { | ||
get: function (passedState) { | ||
if (computedHasChanged) { | ||
computedHasChanged = false; | ||
value = cb(Object.keys(deps).reduce(function (props, key) { | ||
var path = deps[key].split('.'); | ||
props[key] = getByPath(path, passedState); | ||
return props; | ||
}, {})); | ||
return value; | ||
} else { | ||
return value; | ||
} | ||
}, | ||
// Can optimize by remembering the changes in case multiple | ||
// components checks the computed, but very unlikely | ||
hasChanged: function (changes) { | ||
if (computedHasChanged) { | ||
return true; | ||
} | ||
for (var key in deps) { | ||
if (hasChanged(deps[key], changes)) { | ||
computedHasChanged = true; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}; | ||
}; | ||
} | ||
} | ||
/* | ||
- Create computed | ||
- ComponentWillMount, subscribe to computed | ||
*/ | ||
module.exports = StateTree; |
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
254
32526
791