Creating Reactions in Reactions
ds300 opened this issue · 3 comments
Creating new reactions for some atom A (directly or indirectly) in reaction to A's state changing throws errors right now. The gc sweep phase doesn't like it because the graph changed since the mark phase.
It would be a trivial fix, but I want to have a deep think about whether it should be allowed in the first place. At the moment I think it should be.
Perhaps it could be allowed, but would only be considered in future changes. Wouldn't it open the door for non-terminating reactions and the same set of problems that were present with cyclical derivables?
Wouldn't it open the door for non-terminating reactions
I think only if the reaction creates copies of itself recursively. Dependency cycles won't be created because creating reactions doesn't cause state changes and executing reactions must not cause recursive state changes.
It seems like this is just a plain old bug that needs fixing.
apparently this only happens in transactions. here's the minimal steps to reproduce:
const a = atom('a');
transact(() => {
a.set('b');
a.react(a => console.log(a));
})fix incoming