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
Formalize the Wakeable and Thenable types #18391
Conversation
We use two subsets of Promises throughout React APIs. This introduces the smallest subset - Wakeable. It's the thing that you can throw to suspend. It's something that can ping. I also use a shared type for Thenable in the cases where we expect a value so we can be a bit more rigid with our us of them.
This value is just going from here to React so we can keep it a lighter abstraction throughout.
Details of bundled changes.Comparing: a6924d7...a910e62 react-flight-dom-webpack
react-flight-dom-relay
react-client
Size changes (stable) |
|
||
// The subset of a Thenable required by things thrown by Suspense. | ||
// This doesn't require a value to be passed to either handler. | ||
export interface Wakeable { |
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.
Thenable is called that way because you can call then on it.
Maybe this should be Waker or something. The walkable thing is what you pass to the then method. Something that can be woken.
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 guess in Rust, a Waker is the thing you call to then (essentially). It's the thing to be woken up.
So I guess Wakeable is fine. It's the thing that will at some point trigger to wake up the Waker.
Details of bundled changes.Comparing: a6924d7...a910e62 react-flight-dom-webpack
react-client
react-flight-dom-relay
Size changes (experimental) |
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.
if (chunk._status === RESOLVED) { | ||
return chunk._value; | ||
} else if (chunk._status === PENDING) { | ||
// eslint-disable-next-line no-throw-literal |
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.
Btw this seems like a bug in the no-throw-literal lint. It gets confused by the Flow annotation.
We use two subsets of Promises throughout React APIs. This introduces the smallest subset - Wakeable. It's the thing that you can throw to suspend. It's something that can ping.
I also use a shared type for Thenable in the cases where we expect a value so we can be a bit more rigid with our us of them.
I also made Flight use fake Promises as the Wakeable that it throws.