-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Batch together calls to setState, setProps, etc #115
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
Conversation
Change api docs to reflect presence of the new argument. In addition, callback was change to require only a "truthy" value.
Small problem with markdown syntax in syntax-highlighted block.
All public facing {set,replace,force}{props,state} methods now support
callbacks.
src/core/ReactComponent.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should throw this in a separate module that is webworker-safe and supports a better RAF polyfill (@benjamn has a good one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supposedly setTimeout exists in a web worker, but I just realized that this reference to window will probably fail. Happy to use a polyfill if one exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just splitting it out into a separate module is fine for now. Him or I can drop his polyfill in there later.
src/core/ReactComponent.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears unused
|
@spicyj if you need some help with this lmk and I can stack a commit on top of this or something :) I'm really excited about landing this! |
|
@petehunt++ -- i am also very excited for this update. |
src/core/ReactComponent.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
This is great. Along the lines of your |
|
Going to leave mounting as synchronous for now I think but I need to add a callback to renderComponent because that calls setProps half the time. |
|
@petehunt @yungsters @jordwalke Took another pass at it – I like this version a lot better. For now, I'm only batching things together when they're in a block like this: This means that the event handlers have batched updates but nothing else does yet. I wrote ReactUpdates such that it should be easy to make this defer using rAF in the future. |
src/core/ReactCompositeComponent.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit.
if (A &&
B &&
C) {|
The revised version makes a ton of sense. I love the direction and agree with the |
|
(fixed spacing nits) |
|
if @yungsters is good, I'm good. |
|
Lovin' this. |
src/core/ReactUpdates.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, forceUpdate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should try/finally this, right?
|
@spicyj looks like you've got a failing test; can you take a look? I tried the naive approach of surrounding with batchedUpdates() but it didn't work. |
The end of ReactUpdates-test.js is probably most illuminating for seeing how this works.
Batch together calls to setState, setProps, etc
Based off of @ngavalas's #93. Probably not quite mergeable yet but I wanted to send this out tonight and get some feedback.
The end of ReactUpdates-test.js is probably most illuminating for seeing how this works.