How do I manually dispose derive(() => {}) called outside van components?
#469
-
|
I am using some Perhaps there can be an API const a = van.state(1)
const logA = () => console.log(a.val)
//log a whenever it's changed
van.derive(logA)
//stop logging
dispose(logA) |
Beta Was this translation helpful? Give feedback.
Answered by
sirenkovladd
Oct 4, 2025
Replies: 2 comments 4 replies
-
|
we definitely need something like this to manually dispose a derive |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You can create your own wrapper const a = van.state(1)
const customDerive = (fn) => {
let enabled = true;
van.derive(() => enabled && fn())
return () => enabled = false;
}
//log a whenever it's changed
const dispose = customDerive(() => console.log(a.val))
setInterval(() => a.val += 1, 1000)
setTimeout(dispose, 10000) |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
Tao-VanJS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can create your own wrapper