Knockout computed observables and DOM bindings: handling stale cache after async dependency updates
0 reputation · 23 Aug 2023, 15:01 UTC
Goal: Verify that a Knockout computed observable reflects the latest value of its dependencies when those dependencies are updated asynchronously without triggering the observable's change notification.
Constraint: Knockout's computed observables cache their result until a tracked dependency emits a change; the deferredUpdates extender and ko.pureComputed can mitigate stale‑cache behavior but only if subscriptions are correctly disposed. An open design question remains about who bears responsibility for clearing the cache when a dependency is no longer subscribed.
Questions: Should Knockout automatically purge a computed's cache when a dependency is disposed? Does enabling deferredUpdates guarantee that asynchronous updates trigger recomputation? Is explicit subscription disposal the only reliable way to prevent stale data in computed observables?