-
Notifications
You must be signed in to change notification settings - Fork 4.7k
getInsertionPoint: Avoid returning a different object on every call #53722
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The reducer
statecan befalse, so the selector now can return also a boolean in addition to the{ rootClientId, insertionIndex }object. On one hand that's fine, becausefalseis object-like andfalse.rootClientIdevaluates toundefined. It doesn't crash. On the other hand, the selector's return type becomes messy and TypeScript would be very sad seeing this.I propose to also patch the reducers so that
state.blockInserterPanelis always an object with the same shape,{ rootClientId, insertionIndex }, sometimes plusfilterValue. The initial values of the fields arenull. And actions that until now were setting thestatetofalsewould reset the fields back tonulls.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.
Agree. This is a bit confusing way to handle the state. I was just trying to keep changes related to the issue here, but I am also happy to work on those improvements.
The same state is responsible for opening the block inserter -
setIsInserterOpened( true ). How do you suggest handling atruthyvalue? TheinsertionPointdata isn't required for opening the inserter.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.
For the
__experimentalGetInsertionPointselector, it doesn't matter at all whether the state value istrueorfalse. Theconst { rootClientId } = statedestructuring always yields the sameundefinedvalue.But patching the reducers is not as easy as I originally thought, because there's also the
isInserterOpenedselectors that cares about the boolean value.We could do this:
That gives the selector a consistent return type, the same as it had before this PR, and it should be easy to implement.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sounds good. I'll update the PR.
I think in the future, we could split the state in two -
isInserterOpenandblockInsertionPoint.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.
Updated in 139d7a8.