Skip to content

Commit 5a1c598

Browse files
committed
Avoid has + get
1 parent 73cccd9 commit 5a1c598

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

packages/data/src/factory.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ export function createRegistrySelector( registrySelector ) {
4444
// and that has the same API as a regular selector. Binding it in such a way makes it
4545
// possible to call the selector directly from another selector.
4646
const wrappedSelector = ( ...args ) => {
47+
let selector = selectorsByRegistry.get( wrappedSelector.registry );
4748
// We want to make sure the cache persists even when new registry
4849
// instances are created. For example patterns create their own editors
4950
// with their own core/block-editor stores, so we should keep track of
5051
// the cache for each registry instance.
51-
if ( ! selectorsByRegistry.has( wrappedSelector.registry ) ) {
52-
selectorsByRegistry.set(
53-
wrappedSelector.registry,
54-
registrySelector( wrappedSelector.registry.select )
55-
);
52+
if ( ! selector ) {
53+
selector = registrySelector( wrappedSelector.registry.select );
54+
selectorsByRegistry.set( wrappedSelector.registry, selector );
5655
}
57-
return selectorsByRegistry.get( wrappedSelector.registry )( ...args );
56+
return selector( ...args );
5857
};
5958

6059
/**

0 commit comments

Comments
 (0)