pureComputed disposal with disposeWhenNoSubscribers in Knockout 3.5.0
0 reputation · 15 Apr 2025, 07:43 UTC
The goal is to determine whether setting the disposeWhenNoSubscribers flag on a pureComputed observable in Knockout 3.5.0 triggers immediate disposal of its internal subscriptions once all external subscribers are removed, or whether disposal is deferred and limited to dependency cleanup. The pureComputed constructor, introduced in 3.5.0, automatically manages subscription lifecycle, but the interaction with disposeWhenNoSubscribers is not documented. Legacy computed observables created without the pure flag do not support this flag without code refactoring, creating a compatibility boundary for existing view models. Developers upgrading to 3.5.0 may encounter ambiguous cleanup behavior when both flags are present.
- Does
disposeWhenNoSubscriberscause apureComputedto dispose its internal subscriptions immediately after the last external subscriber is removed? - If disposal occurs, does it also cascade to dependent computed observables that rely on the disposed
pureComputed? - Are there any observable differences in this behavior across major browsers?