-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Private actions and selectors: return stable references, expose to thunks #51051
Conversation
Size Change: +77 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
Flaky tests detected in 6f85e3e940ed98adaa46d6b83bfee03aa9e66d19. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5200297799
|
Adding one more private selectors patch to this branch: in #50985 @noisysocks demonstrates a bug with private registry selectors by adding a failing test. I cherry-picked the tests to this PR and commited a fix on top. |
@jsnajdr would you separate the two changes into two PRs? That would make this one easier to review |
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.
These changes and new the tests look good to me.
Our automated tests cover this code pretty well so that they pass is a fairly good indication that we can be confident of these changes.
I created a test branch containing this branch and #50857 and was able to confirm that my original problem (not being able to call a private createRegistrySelector
selector from a public selector in the block-editor
store) was fixed once I switched the order of registerPrivateActions
and register
.
I think we should move to an atomic API like the one described in #50985 (comment) so that reordering isn't necessary but this is good enough for now.
f49fad0
to
5082b05
Compare
5082b05
to
6f85e3e
Compare
6f85e3e
to
3aa08c6
Compare
@jsnajdr: Are you still planning on splitting this up or can we land this? |
There are still three fixes in one:
But all the code changes are concentrated at one place and should be easy to review. So let's review and land this PR as one. |
…unks (WordPress#51051) * Return stable references to private selectors and actions * Expose unlocked private actions and selectors to thunks * Add tests for private registry selectors, including one failing test * Fix comment typo in createRegistrySelector * Private registry selectors test: register selectors before store instantiation * Pre-bind private selectors so that registry selectors are bound to registry --------- Co-authored-by: Robert Anderson <[email protected]>
Solves two problems with private actions and selectors:
const { setFoo } = unlock( useDispatch() )
always returns the samesetFoo
on each call, and analogously also foruseSelect
. This wasn't true before, as the private actions and selectors were re-bound on each call of thedispatch
getter. Action references are sometimes used as effect dependencies, with possibly disastrous consequences if they are not constant.dispatch
andselect
objects (proxies) to thunks. Thunks are considered private code of the store, and should have access to all private APIs.The PR contains a larger exploratory refactor of how the actions and selectors are bound to the store, best to review commit by commit.