有没有好办法大致实现如下概念:
var computed = ko.computed(function() {
readSomeObservables(); //<-- if these change, notify computed
ko.stopCollectingDependencies();
readSomeMoreObservables(); //<-- if these change, do not notify computed
ko.resumeCollectingDependencies();
});
我知道peek()
,但在这种情况下,计算调用的是从外部模块提供的方法,并且如果这些方法碰巧涉及可观察对象,则设计要求它纯粹是偶然的。
我有一个解决方案,大致是这样做的:
window.setTimeout(function() {
readSomeMoreObservables();
}, 0);
但由于显而易见的原因,这并不理想,并且在某些情况下会导致不良行为。