Safer container value management.

This commit is contained in:
Timothy Farrell 2017-12-15 21:02:11 -06:00
parent 17ff59dd0b
commit 833bbc2857
2 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "frptools", "name": "frptools",
"version": "2.2.0", "version": "2.2.1",
"description": "Observable Property and Computed data streams", "description": "Observable Property and Computed data streams",
"main": "lib/index.js", "main": "lib/index.js",
"jsnext:main": "src/index.js", "jsnext:main": "src/index.js",

View File

@ -14,11 +14,11 @@ export function container(store, hash) {
}; };
containerMethods._d = containerMethods.subscribe; containerMethods._d = containerMethods.subscribe;
function checkUpdate() { function checkUpdate(target) {
const newId = hash(store); const newId = hash(target);
if (id !== newId) { if (id !== newId) {
id = newId; id = newId;
subscribers.forEach(s => s(store)); subscribers.forEach(s => s(target));
} }
} }
@ -37,7 +37,7 @@ export function container(store, hash) {
if (typeof thing === 'function') { if (typeof thing === 'function') {
return (...args) => { return (...args) => {
const ret = target[name](...args); const ret = target[name](...args);
checkUpdate(); checkUpdate(target);
return ret; return ret;
}; };
} }
@ -48,7 +48,7 @@ export function container(store, hash) {
throw new ReferenceError(`Cannot set ${name} in ${target}`); throw new ReferenceError(`Cannot set ${name} in ${target}`);
} }
target[name] = newVal; target[name] = newVal;
checkUpdate(); checkUpdate(target);
return newVal; return newVal;
} }