-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
limitation on mutating observables in reaction #25
Comments
Hi! Mutating observables inside reactions won't trigger other reactions, but they don't break the app in any other way. Triggering other reactions in reactions could cause infinite loops and a very obfuscated control flow. Reactions are meant to react on data changes and not to trigger other data changes. (They should save or visualize data as examples). In the past the lib allowed triggering reactions inside reactions and automatically cut the infinite loops, but I had to remove this when I added custom schedulers. With custom async schedulers and observable mutations inside reactions it would be possible to cause async infinite loops, which is a really nasty thing. Do you have an example use case where you would like to mutate reactive data inside reactions? PS: I also saw the other issue, where you referenced this. I would advise you against using NX framework in serious projects. Some parts of it (like this lib and the queue-util) are actively maintained and prod ready, but the project as a whole is stuck in beta until I have more time to finish it. |
Mobx has autorun, and meteor has autorun(it being the only thing they have). Mobx says it's meant as a bridge to imperative code, and I suppose it's a consumer of a reaction/computed prop, so I say reactive programming that isn't responsive to itself is seriously gimped. |
Mobx Mobx:
nx-observe:
MobX Do you have a use case (code snippet) where you would like to update reactive data in reactions? EDIT: the MobX docs is a bit poorly worded here. |
Might actually work. |
Anyway it feels a little weird to me. I'll give it a try, but here's meteor's guide to tracker: https://github.com/meteor/docs/blob/version-NEXT/long-form/tracker-manual.md, obviously it's somewhat slower. |
I'm trying to map observer api onto tracker api. |
Im looking to pass invariable amount of functions into getter for Dependency since it supports multiple calls on changed method, and actually be able to tell what function called the method in production. |
I feel like I can't help here, what's is your overall goal? Would you like to track which function uses which observable values? In that case I suggest you to check the experimental
I don't know if this is what you are looking for. |
Convert meteor's reactive lib tracker to yours, im trying to do. |
Ur typical implementation for observable would be call new Dependency(), and then dependency.changed() when it was change in function, and dependency.depend() when the observable was used. I was thinking I should change dependency.changed( ) whould set observable on function where it was used as getter for dependency, but Im not sure that will work. |
Is there a reason for why this limitation exists? I can see how this may cause loops, but otherwise there's nothing wrong with having reaction triggered in reaction (not in, after).
The text was updated successfully, but these errors were encountered: