-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Move action-binding code to a bindAction function #51161
Conversation
Size Change: +8 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
Flaky tests detected in 230b101. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5143597539
|
); | ||
function bindAction( action ) { | ||
return ( ...args ) => | ||
Promise.resolve( store.dispatch( action( ...args ) ) ); |
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.
Does it not turn synchronous results into promises? Or does dispatch always return a promise?
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.
Yes, dispatch always returns a promise, for historical reasons. I would love to get rid of that, because it doesn't make much sense -- not all actions are async. But that would break code like dispatch( foo ).bar().then( ... )
.
Refactoring of the
mapActions
function, a spinoff from #51051. Which will build on these changes and implement returning stable references to private actions fromdispatch
, and exposing private actions to thunks.The
mapActions
function is removed in favor of callingmapValues( actions, bindAction )
directly. And in the private action proxy, we map only the one action that the getter is requesting, not all of them.