-
|
In a context implementation I attempted with So far I just prevent callback execution with a flag, but my understanding is that it will still be in the Is there a better, more idiomatic way to remove a state's listener? (this context implementation is roughly following the webcomponent context proposal. Haven't tested, but my gut feeling is that it is also a viable pure VanJS approach to context providers and consumers) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
|
It seems like my approach kinda works and the state's listener will be garbage collected after a GC cycle 🤔 If anyone has some more time and fresh eyes to test it out, I would appreciate it greatly 🙏 |
Beta Was this translation helpful? Give feedback.
-
|
I'm confused by your example. The |
Beta Was this translation helpful? Give feedback.
-
|
BTW here is another implementation of the same context using pure VanJS The GC in the example doesn't work because I removed the unmount part (specific to van-element) |
Beta Was this translation helpful? Give feedback.
-
|
Ah.., I think I know the reason now: For the derivation: van.derive(() => sub && e.callback(s.val, () => (sub = false)));Whenever it's called, it recalculates the dependencies on-the-fly and updates corresponding listeners based on it. Thus, when |
Beta Was this translation helpful? Give feedback.
Ah.., I think I know the reason now:
For the derivation:
Whenever it's called, it recalculates the dependencies on-the-fly and updates corresponding listeners based on it. Thus, when
subistrue, the derivation depends ons. Whensubbecomesfalse(after unmount), the derivation won't depend onsanymore, which is why you're seeing the listeners get cleaned up.