-
Notifications
You must be signed in to change notification settings - Fork 8
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
Redundant view updates? #37
Comments
@mindplay-dk Generally an effect is asynchronous, so when you dispatch a message it won't cause an immediate update again. If you find that you're modeling something synchronous as an effect, I think that's a good time to step back and consider if it ought not be a pure helper function called from your Hope this helps! Given how simple Raj is, it definitely could be abused to thrash renders and updates. Like anything it'll need some consideration if you start running into performance bottlenecks but I've not had a problem here in particular. |
I'm just getting reacquainted, and I think where I got confused again is by the return tuples with the I have this other little thing I've been playing with: https://gist.github.com/mindplay-dk/135124139217f08bf2903c2553cf1aac It's different from Raj, using an object as state, allowing partial updates - which works better for my use-case. But if you ignore that... Instead of returning effects, I went with simply passing the It has similar behavior, but doesn't require tuples (which still to this day confuse me) and doesn't limit you to one effect. I don't know if that's really a meaningful difference - I think I just like the idea of functions returning one thing, and if I can pass a It's probably mostly a matter of preference, I guess. Anyhow, feel free to carry on the discussion if you like, or just close the issue, since there's no issue with your library here. 🙂 (and I still like it, I'm just concerned about future maintainers being able to read and understand the code - it's still quite difficult for me, and I've spent quite a bit of time with it, which is why I'm looking for ways to make things more readable without adding substantial complexity...) |
@mindplay-dk I'll respond to only a few of these bits for time's sake, but I'd be wary of your action queuing pattern. It's certainly an option I've seen in other frameworks (Ember has a "run loop" everyone hates, for example) that can grow to be quite complicated to manage.
Raj guarantees the effects which are processed by the runtime will be kicked off synchronously (which gives us this order), but effects can finish asynchronously and are not awaited.
Definitely a personal preference. I find code where every meaningful operation needs to be wrapped in a function call to be very noisy. What I want is plain, testable logic without needing to provide a fake
You're definitely not limited to one effect! Check out
Returning effect values makes it easier to test which is the focus of Raj. Take this snippet from your gist as an example: setTimeout(() => {
run(state => {
console.log("ACCEPT MARKETING", state);
return { acceptMarketing: true };
});
}, 1000); This is really hard to test, we've now got asynchrony in our update function which means we'd have to do some weird mocking tricks. Instead, Raj forces you to return an effect that can be called independently at Raj's (or when under test, your own) choosing. But you don't have to call it to get access to the next state. |
If something has an effect, and the effect dispatches another update, the view effectively ends up getting updated twice.
If that effect has an effect, three updates, and so on.
Is this by design?
The text was updated successfully, but these errors were encountered: