-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block List: Extract copy, scroll-into-view logic to separate non-visual components #5021
Conversation
|
||
scrollIntoView( | ||
extentNode, | ||
extentNode.closest( '.edit-post-layout__content' ), |
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.
It should be easier to use a prop for this className now since it's an "external" className.
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.
I'm wondering if this is necessary at all...
} | ||
} | ||
|
||
export default query( ( select ) => { |
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.
Any reason for using query here instead of connect
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.
Any reason for using query here instead of connect
I guess it speaks to a broader question: Do we want to start discouraging use of connect
altogether? My thinking is that it speaks strongly to its viability if we're forced to use it in first-party code. Also a nice abstraction to avoid interacting with Redux directly. Also avoids some problems with variable shadowing and importing selectors.
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.
Also avoids some problems with variable shadowing and importing selectors.
Can you elaborate a little? Or are these separate things, i.e. you mean variable shadowing for actions (see our recent discussion)?
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.
Can you elaborate a little?
I'll elaborate in the form of a refactoring pull request demonstrating the benefits 😆
See: #5083
editor/store/index.js
Outdated
getLastMultiSelectedBlockUid, | ||
getMultiSelectedBlocks, | ||
getMultiSelectedBlockUids, | ||
getSelectedBlock, |
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.
Why are we exposing those selectors?
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.
Ah, I think at https://github.com/WordPress/gutenberg/pull/5021/files#diff-a6cb47a97748d7742a26ae134e49e8a1R76 I started down the path of using query
but realized I have no access to dispatch which is necessary 😄
9e29469
to
7c6f187
Compare
In latest rebase:
|
In a subsequent pull request, I could imagine creating a separate component for keeping the currently selected block in view. Does this approach for non-visual components seem sensible to you @youknowriad ? I like that because they |
@aduth Actually, I like these components a lot, I wonder though if they should be included by the layout module "edit-post" or implicitly inside BlockList or something. Also, I was wondering about the |
In general, it looks like step by step, we're moving all this imperative code relying on DOM nodes to components like this (including WritingFlow in the mix). It kind of feel like the right thing to do to isolate these behaviors. |
Yeah, my only concern so far with this is that it moves access of the DOM node from being |
This pull request seeks to refactor copy and scroll-into-view logic currently contained within
BlockListLayout
to two separate top-level non-visual componentsCopyHandler
andMultiSelectScrollIntoView
. The goal is to optimize rendering ofBlockListLayout
, which currently re-renders when any blocks change because of its dependency ongetMultiSelectedBlocks
. Further, sinceCopyHandler
andMultiSelectScrollIntoView
is neither specific to a list layout rendering nor has any visual effect, it is well-suited as a non-visual component.Testing instructions:
Verify that there are no regressions in the copying, cutting, or scroll-into-view assurance of multi-selection and multi-selection expansions.