Repository navigation
Add __experimentalGetGlobalBlocksByName selector - #39610
Conversation
|
Size Change: +31 B (0%) Total Size: 1.21 MB
ℹ️ View Unchanged
|
| return EMPTY_ARRAY; | ||
| } | ||
| const clientIds = getClientIdsWithDescendants( state ); | ||
| const foundBlocks = clientIds.filter( ( clientId ) => { |
There was a problem hiding this comment.
Could we just return the result of the filter? Do we need to use the EMPTY_ARRAY const?
There was a problem hiding this comment.
Filter will return a new array reference. Thus we use the reference to a constant object reference EMPTY_ARRAY so as to avoid returning a new object reference if the selector returns "nothing". It's a minor perf thing but it could make a big difference in certain components.
There was a problem hiding this comment.
I see Kerry even wrote a test to validate that. See the final it() in the tests.
|
What is it that makes |
|
@getdave Thanks for adding this. It has allowed me to optimize a little bit of the logic in #29739. @draganescu The term is already used by |
What?
This PR adds a new selector:
__experimentalGetGlobalBlocksByName.Why?
This is a sub PR spun out of #39290.
This selector returns all global blocks that match a given blockName. It also includes nested blocks.
This is required by #39290 to quickly get a list (including nested blocks) of any Navigation blocks currently within the current post/template.
How?
This selector is added to the
@wordpresss/block-editorpackage.Testing Instructions
Consoledrawer on any Editor page.wp.data.select('core/block-editor').__experimentalGetGlobalBlocksByName(%%YOUR BLOCK NAME HERE%%)replacing the placeholder with a block you know is in the current post/template (egcore/paragraph).Screenshots or screencast