state-tree
Advanced tools
Comparing version
declare class Computed { | ||
static getByPath: any; | ||
static hasChanged: any; | ||
private _value; | ||
private _computedHasChanged; | ||
private _deps; | ||
@@ -11,4 +8,3 @@ private _cb; | ||
get(passedState: any): any; | ||
hasChanged(changes: any): boolean; | ||
} | ||
export default Computed; |
@@ -7,4 +7,2 @@ "use strict"; | ||
return new Computed(_deps, _cb); | ||
this._computedHasChanged = true; | ||
this._value = null; | ||
this._deps = _deps; | ||
@@ -18,34 +16,12 @@ this._cb = _cb; | ||
var _this = this; | ||
if (this._computedHasChanged) { | ||
this._computedHasChanged = false; | ||
this._value = this._cb(Object.keys(this._deps).reduce(function (props, key) { | ||
if (typeof _this._deps[key] === 'string') { | ||
var path = _this._deps[key].split('.'); | ||
props[key] = Computed.getByPath(path, passedState); | ||
} | ||
else { | ||
props[key] = _this._deps[key].get(passedState); | ||
} | ||
return props; | ||
}, {})); | ||
return this._value; | ||
} | ||
else { | ||
return this._value; | ||
} | ||
}; | ||
// Can optimize by remembering the changes in case multiple | ||
// components checks the computed, but very unlikely | ||
Computed.prototype.hasChanged = function (changes) { | ||
if (this._computedHasChanged) { | ||
return true; | ||
} | ||
for (var key in this._deps) { | ||
if ((typeof this._deps[key] === 'string' && Computed.hasChanged(this._deps[key], changes)) || | ||
(typeof this._deps[key] !== 'string' && this._deps[key].hasChanged(changes))) { | ||
this._computedHasChanged = true; | ||
return true; | ||
return this._cb(Object.keys(this._deps).reduce(function (props, key) { | ||
if (typeof _this._deps[key] === 'string') { | ||
var path = _this._deps[key].split('.'); | ||
props[key] = Computed.getByPath(path, passedState); | ||
} | ||
} | ||
return false; | ||
else { | ||
props[key] = _this._deps[key].get(passedState); | ||
} | ||
return props; | ||
}, {})); | ||
}; | ||
@@ -55,5 +31,4 @@ return Computed; | ||
Computed.getByPath = utils_1.getByPath; | ||
Computed.hasChanged = utils_1.hasChanged; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = Computed; | ||
//# sourceMappingURL=computed.js.map |
@@ -5,2 +5,1 @@ export declare function getByPath(path: any, state: any, forcePath?: any): any; | ||
}; | ||
export declare function hasChanged(path: any, changes: any): any; |
@@ -61,8 +61,2 @@ "use strict"; | ||
exports.deepmerge = deepmerge; | ||
function hasChanged(path, changes) { | ||
return path.split('.').reduce(function (changes, key) { | ||
return changes ? changes[key] : false; | ||
}, changes); | ||
} | ||
exports.hasChanged = hasChanged; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "state-tree", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A state tree that handles reference updates and lets you flush a description of changes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
43230
13.04%19
5.56%1
-50%259
Infinity%0
-100%463
-7.21%