Safer container value management.
This commit is contained in:
parent
de50cbd6c3
commit
44000f9d77
@ -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",
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user