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",
"version": "2.2.0",
"version": "2.2.1",
"description": "Observable Property and Computed data streams",
"main": "lib/index.js",
"jsnext:main": "src/index.js",

View File

@ -14,11 +14,11 @@ export function container(store, hash) {
};
containerMethods._d = containerMethods.subscribe;
function checkUpdate() {
const newId = hash(store);
function checkUpdate(target) {
const newId = hash(target);
if (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') {
return (...args) => {
const ret = target[name](...args);
checkUpdate();
checkUpdate(target);
return ret;
};
}
@ -48,7 +48,7 @@ export function container(store, hash) {
throw new ReferenceError(`Cannot set ${name} in ${target}`);
}
target[name] = newVal;
checkUpdate();
checkUpdate(target);
return newVal;
}