vobyjs / voby

A high-performance framework with fine-grained observable-based reactivity for building rich applications.
https://voby.dev
MIT License
879 stars 22 forks source link

`batch` is global #28

Closed theSherwood closed 1 year ago

theSherwood commented 1 year ago

Hi @fabiospampinato I've been playing around a bit with Voby and I'm looking to move my app from Solid to Voby potentially. I really need something like Voby's batch behavior. However, I noticed something a little surprising about batch in that it is global. If batch is called, no effects will run for any signals until the callback resolves, not just the signals that are affected in the callback. I found this a bit surprising. It doesn't affect my use case, but I wanted to make you aware. I know Voby isn't at version 1 yet. So if the batch behavior is going to be nerfed by version 1, I'd rather not move to Voby. I already had that experience with Solid, where batch worked in the way I needed as of version 1.3, but as of 1.4, it changed and no longer fit my use case. So I wanted to check on the likelihood of batch seeing serious changes in future. Thoughts?

theSherwood commented 1 year ago

Voby looks great, by the way!

fabiospampinato commented 1 year ago

I haven't really thought about this, like batch explicitly stops the world, but what would it look like if it only stopped the world for signals updated inside the batch?

It's tricky because I'm not sure if that would be correct behavior to begin with, like if parts of your interface that the user can see can update themselves while other parts can't then that could lead to inconsistent interfaces, at least temporarily, which we should try to avoid.

The only "problem" with the current batch function that I don't like is that it's unclear that it does nothing for synchronous functions.

If batching is changed it might be changed by adding more explicit pause() and resume() methods instead or something like that. I don't see this capability going away because it's useful and I personally need it.

theSherwood commented 1 year ago

Very reasonable. I think pause and resume may be clearer. batch taking a callback seems to invite performing mutations within the callback and somewhat implies that those mutations would be handled differently from the mutations happening outside the callback. So I think pause and resume are clearer.

I'm very glad to hear that this won't be going away!