state-tree
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -0,13 +1,10 @@ | ||
import { getByPath } from './utils'; | ||
declare class Computed { | ||
private _deps; | ||
private _cb; | ||
static getByPath: any; | ||
static hasChanged: any; | ||
private _value; | ||
private _computedHasChanged; | ||
static getByPath: typeof getByPath; | ||
constructor(_deps: any, _cb: any); | ||
getDepsMap(): any; | ||
get(passedState: any): any; | ||
hasChanged(changes: any): boolean; | ||
} | ||
export default Computed; |
@@ -7,4 +7,2 @@ "use strict"; | ||
this._cb = _cb; | ||
this._computedHasChanged = true; | ||
this._value = null; | ||
} | ||
@@ -16,41 +14,18 @@ Computed.prototype.getDepsMap = function () { | ||
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; | ||
}, {})); | ||
}; | ||
Computed.getByPath = utils_1.getByPath; | ||
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.5", | ||
"version": "0.2.6", | ||
"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
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
35664
467