-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Initial implementation of new-style refs #1554
Conversation
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
* @param {function} success Callback in case of success | ||
* @param {?function} failure Callback in case of failure | ||
*/ | ||
then(success, failure) { |
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.
One cool feature of the async refs, is that it makes it impossible (or at least difficult/fragile) for anyone to access a ref inside of a render method.
So it sounds like the only thing left to do on this one is to make the refs |
I think so. You also wanted some test cases around cloneWithProps and transferPropsTo. Do you want to support having more than one ref? Right now cloneWithProps just warns you if you clone a component with a (string) ref. |
With this diff, cloning a component with (this type of) ref should be okay because refs won't be tied to any particular owner. So that means multiple components can retain a reference to the ref. I'd say it's bad for any program to be effected by whether or not your refs are resolved in a blocking manner, (at the moment you invoke So that being said, @sebmarkbage: Can we just make sure the |
Under those terms, we can hide this feature behind |
This doesn't work on initial render because of how the batching currently works and also doesn't work if you access it outside of a lifecycle method, like in an event handler. Not sure how serious a problem that is for you @jordwalke. |
Callbacks passed to this setImmediate function are called at the end of the current update cycle, which is guaranteed to be asynchronous but in the same event loop (with the default batching strategy). This is useful for new-style refs (facebook#1373, facebook#1554) and for fixing facebook#1698. Test Plan: jest
Callbacks passed to this setImmediate function are called at the end of the current update cycle, which is guaranteed to be asynchronous but in the same event loop (with the default batching strategy). This is useful for new-style refs (facebook#1373, facebook#1554) and for fixing facebook#1698. Test Plan: jest
Let's call Also, I think that we should make I still hate this API (even though I originally came up with it) but I don't have a better idea for now. |
Per facebook#1554 (comment). Test Plan: jest
cf. facebook#1373 This implementation can be used in any situation that refs can currently be used (and can also be used without an owner, which is a plus).
Depends on/includes #1758.
cf. #1373
This particular implementation doesn't attempt to do anything smart about async resolution --
.then
always runs one of its arguments immediately. It can be used in any situation that refs can currently be used (and can also be used without an owner, which is a plus).We can enhance this later to do something more intelligent when using refs during updates.
cc @jordwalke @sebmarkbage