我有一个类似的派生商店:
const filter = derived([a, b, c, d, e], callback, null);
function callback([$a, $b, $c, $d, $e], set) {
....
set(...);
return() = {
....
};
};
是否有一种简单的方法来找出[a..e]的哪个存储区在缓存存储区值之外还会触发回调中的回调。例如:如果存储'c'更新,我想用set(null)重置。
使用闭包来缓存存储值的示例代码:
function cache() {
let cached;
return ([$a, $b, $c, $d, $e], set) => {
....
set(...);
return() = {
if (cached !== $c.value) {
cached = $c.value;
set(null);
};
};
};
};
function filterStore() {
const callback = cache();
const { subscribe } = derived([a, b, c, d, e], callback, null);
return {
subscribe,
};
};
const filter = filterStore();
答案 0 :(得分:0)
我不是单纯地使用派生商店来执行此操作,但是当我听到“追溯导致突变的原因” 时,我的第一个想法就是研究动作(àla VueX / Mobx)。
这意味着您的派生商店实际上将是可写的,并且您将编写一项服务/操作来相应地更新所有商店:
MeasureOverride
然后在用户界面中相应地调用操作。
我不会将派生存储用于不完全依赖其他存储状态的东西。