-
Notifications
You must be signed in to change notification settings - Fork 60
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
Too many calls to forceUpdate #9
Comments
Seems pretty reasonable to me - is |
With throttle you get the immediacy. So when that first add event or set of add events that synchronously come in, the forceUpdate is called right away. It's also called once at the end too, which is probably the only potential downside, but one extra call to react's render is most likely negligible. With debounce, before anything is seen, there is at least that waiting period of 1000ms (or whatever its chosen to be). If debounce were used, it'd probably be best to bring that time down to 10ms (to give the sense of immediacy) or some amount that is just enough for the collection to trigger all of the add events before debounce is open to another call. |
Ahhh yeah, good call. I've added this in 865e322 - I turned down the timeout to 500ms, and made the throttle wrapper a local variable. Take a look, but should be good to go |
This causes a rendering issue with a paged collection. See http://jsfiddle.net/54pfU/ . Click next page a couple times and notice the first remove is rendered and not until 500ms later does the rest of the list update. From where I'm sitting, I don't see an issue with calling forceUpdate N times because React already has infrastructure in place to ensure rendering is batched. And if it ever needs to be worked around on a case-by-case basis, that can be done in React rather than here. Or am I missing something? |
From what I understand, React batches DOM updates, but doesn't batch calls to render. Also, it's not batching calls to update its 'virtual dom'. It's doing that N number of times. Any logic outside of actually manipulating the DOM in the render method will be called N number of times. Throw a console.log statement in there. I see your issue here, which may mean debounce with a very small delay (~10ms?) would work around this. |
@dicicco2 we do batch calls to By default this is only enabled within event handlers, but you can use my |
@dicicco2 thanks. With my test case, debounce 10ms did the trick |
I would assume that debounce 0 would work as well. @duhseekoh How are you adding N elements to a collection? Maybe it's possible to receive only one event from Backbone. |
I may have the wrong understanding, but
You don't need |
I've recently used a similar mixin for React. What I've seen so far with using it is that N number additions to a collection triggers forceUpdate N number times.
I changed:
to this (assuming inclusion of underscore or lo-dash):
At most, force update will be called once a second here. Interested in your thoughts on this.
The text was updated successfully, but these errors were encountered: