Skip to content

Commit b4711e7

Browse files
Mamadukaellatrix
andauthored
Block Directory: Memoize store selectors (#63346)
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
1 parent bdfd1d7 commit b4711e7

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

packages/block-directory/src/store/selectors.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { createRegistrySelector } from '@wordpress/data';
4+
import { createSelector, createRegistrySelector } from '@wordpress/data';
55
import { store as blockEditorStore } from '@wordpress/block-editor';
66

77
/**
@@ -53,15 +53,21 @@ export function getInstalledBlockTypes( state ) {
5353
*
5454
* @return {Array} Block type items.
5555
*/
56-
export const getNewBlockTypes = createRegistrySelector(
57-
( select ) => ( state ) => {
58-
const usedBlockTree = select( blockEditorStore ).getBlocks();
59-
const installedBlockTypes = getInstalledBlockTypes( state );
56+
export const getNewBlockTypes = createRegistrySelector( ( select ) =>
57+
createSelector(
58+
( state ) => {
59+
const usedBlockTree = select( blockEditorStore ).getBlocks();
60+
const installedBlockTypes = getInstalledBlockTypes( state );
6061

61-
return installedBlockTypes.filter( ( blockType ) =>
62-
hasBlockType( blockType, usedBlockTree )
63-
);
64-
}
62+
return installedBlockTypes.filter( ( blockType ) =>
63+
hasBlockType( blockType, usedBlockTree )
64+
);
65+
},
66+
( state ) => [
67+
getInstalledBlockTypes( state ),
68+
select( blockEditorStore ).getBlocks(),
69+
]
70+
)
6571
);
6672

6773
/**
@@ -72,15 +78,21 @@ export const getNewBlockTypes = createRegistrySelector(
7278
*
7379
* @return {Array} Block type items.
7480
*/
75-
export const getUnusedBlockTypes = createRegistrySelector(
76-
( select ) => ( state ) => {
77-
const usedBlockTree = select( blockEditorStore ).getBlocks();
78-
const installedBlockTypes = getInstalledBlockTypes( state );
81+
export const getUnusedBlockTypes = createRegistrySelector( ( select ) =>
82+
createSelector(
83+
( state ) => {
84+
const usedBlockTree = select( blockEditorStore ).getBlocks();
85+
const installedBlockTypes = getInstalledBlockTypes( state );
7986

80-
return installedBlockTypes.filter(
81-
( blockType ) => ! hasBlockType( blockType, usedBlockTree )
82-
);
83-
}
87+
return installedBlockTypes.filter(
88+
( blockType ) => ! hasBlockType( blockType, usedBlockTree )
89+
);
90+
},
91+
( state ) => [
92+
getInstalledBlockTypes( state ),
93+
select( blockEditorStore ).getBlocks(),
94+
]
95+
)
8496
);
8597

8698
/**

0 commit comments

Comments
 (0)