The observer pattern is inherently leaky. Signals don't need cleanup but any subscription does. If the signal outlives the subscriber it will have no longer relevant subscriptions. At minimum we need to mark the subscriber as dead. The fact that we dynamically create and tear down subscriptions on each run has us doing this work anyway. Consider this example:
Every time a changes you are creating a new reaction that listens to b. So a naive approach that didn't do cleanup would just keep appending more subscriptions to b. So if you updated a 3 times b would end up with 4 subscriptions. When you updated b it would console.log 4 times.
In the case of the demo you've built up in this article, the b would console.log 4 times. You writing "the fact that we dynamically create and tear down subscriptions on each run has us doing this work anyway," made me think it's not supposed to happen. But, it seems to make sense: each time a changes, a new effect is created, and so the b's will stack up.
I've read that with solid the nested effect, "would be disposed on each rerun of the "parent" effect. Is this what happens in Solid, that doesn't happen in this article?
Thank you.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The observer pattern is inherently leaky. Signals don't need cleanup but any subscription does. If the signal outlives the subscriber it will have no longer relevant subscriptions. At minimum we need to mark the subscriber as dead. The fact that we dynamically create and tear down subscriptions on each run has us doing this work anyway. Consider this example:
Every time
a
changes you are creating a new reaction that listens tob
. So a naive approach that didn't do cleanup would just keep appending more subscriptions tob
. So if you updateda
3 times b would end up with 4 subscriptions. When you updatedb
it wouldconsole.log
4 times.Hey Ryan, thank you for the article series!
In the case of the demo you've built up in this article, the
b
wouldconsole.log
4 times. You writing "the fact that we dynamically create and tear down subscriptions on each run has us doing this work anyway," made me think it's not supposed to happen. But, it seems to make sense: each timea
changes, a new effect is created, and so theb
's will stack up.I've read that with solid the nested effect, "would be disposed on each rerun of the "parent" effect. Is this what happens in Solid, that doesn't happen in this article?
Thank you.