-
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
Tidy up block patterns selectors #57913
Conversation
@@ -2015,7 +2015,7 @@ export const getInserterItems = createSelector( | |||
}, | |||
( state, rootClientId ) => [ | |||
state.blockListSettings[ rootClientId ], | |||
state.blocks.byClientId, | |||
state.blocks.byClientId.get( rootClientId ), |
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.
This fixes an omission from #46204: that PR uses the rootClientId
substate only in canInsertBlockType
, but not in other selectors that call canInsertBlockType
or canIncludeBlockTypeInInserter
and therefore need to declare the same dependencies, too.
( state ) => { | ||
const userPatterns = state.settings.__experimentalReusableBlocks ?? []; | ||
const userPatternCategories = | ||
state.settings.__experimentalUserPatternCategories ?? []; |
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 two arrays are never returned from the selector, so the static constant EMPTY_ARRAY
is not really needed.
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.
Could be easy to accidentally slip in later though.
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.
Although we're anyway mapping below I see now.
Size Change: -56 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
When retrieving the block patterns we repeatedly do this:
This PR extracts this into a new
getAllPatterns
selector, which is also memoized so it doesn't have to construct the merged array on each call.Because this selector is memoized, we can use it when declaring selector dependencies. That's more straighforward than enumerating its low-level dependencies explicitly.