Skip to content

Cleanup van.derive listener #230

Answered by Tao-VanJS
Atmos4 asked this question in Q&A
Discussion options

You must be logged in to vote

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 sub is true, the derivation depends on s. When sub becomes false (after unmount), the derivation won't depend on s anymore, which is why you're seeing the listeners get cleaned up.

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@Atmos4
Comment options

@Tao-VanJS
Comment options

@Atmos4
Comment options

@Atmos4
Comment options

Comment options

You must be logged in to vote
2 replies
@Tao-VanJS
Comment options

@Atmos4
Comment options

Comment options

You must be logged in to vote
1 reply
@Atmos4
Comment options

Answer selected by Tao-VanJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants