-
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
Data: allow binding registry selector to multiple registries #57943
Conversation
Size Change: +91 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
c9f9c58
to
2a77bb2
Compare
2a77bb2
to
73cccd9
Compare
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.
Nice 🙂
packages/data/src/factory.js
Outdated
} | ||
return selector( ...args ); | ||
return selectorsByRegistry.get( wrappedSelector.registry )( ...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.
Let's write the code in such a way that there is ony one .get
map lookup, not the two .has
and .get
. This will be called all the time, so a micro-opt is justified.
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.
Adjusted :)
There's still the very fragile case where registry selectors are called without binding, from normal selectors: const getFoo = createRegistrySelector( ... );
const getBar = ( state ) => { getFoo( state ) }; Both before and this PR there will be erratic behavior. But that's solvable only with |
Yeah, there's definitely a bunch of things that still remain to be fixed. Another thing is that |
Flaky tests detected in 5a1c598. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7584672596
|
What?
Currently it's not possible to bind a "registry selector" (created through
createRegistrySelector
) to multiple registries. This is because the selector is bound (registry property set) when a registry initialises, so on the next initialisation thisregistry
property is overridden.The easiest solution here is to "switch" registries before calling the selector.
Additionally a cache should be kept for each registry, which shouldn't invalidate when initialising or switching to other registries.
Why?
It currently prevents me from adding registry selectors to the block editor store, because it's possible to create multiple instances of these (separate editor instances in previews for example).
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast