Skip to content
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

Merged
merged 3 commits into from
Feb 14, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 13, 2018

This pull request seeks to refactor copy and scroll-into-view logic currently contained within BlockListLayout to two separate top-level non-visual components CopyHandler and MultiSelectScrollIntoView. The goal is to optimize rendering of BlockListLayout, which currently re-renders when any blocks change because of its dependency on getMultiSelectedBlocks. Further, since CopyHandler and MultiSelectScrollIntoView 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.

@aduth aduth added the [Type] Performance Related to performance efforts label Feb 13, 2018

scrollIntoView(
extentNode,
extentNode.closest( '.edit-post-layout__content' ),
Copy link
Contributor

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.

Copy link
Member Author

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 ) => {
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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)?

Copy link
Member Author

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

getLastMultiSelectedBlockUid,
getMultiSelectedBlocks,
getMultiSelectedBlockUids,
getSelectedBlock,
Copy link
Contributor

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?

Copy link
Member Author

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 😄

@aduth aduth force-pushed the add/copy-handlers branch from 9e29469 to 7c6f187 Compare February 13, 2018 21:25
@aduth
Copy link
Member Author

aduth commented Feb 13, 2018

In latest rebase:

  • Removes registration of unused selectors
  • Uses new selector API signature
  • Replaced reference to editor scrollable layout with reused getScrollContainer originally in BlockListBlock, moved to editor DOM utilities file

@aduth
Copy link
Member Author

aduth commented Feb 13, 2018

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 return null; from render, the reconciliation is very simple even if the props are changing.

@youknowriad
Copy link
Contributor

youknowriad commented Feb 13, 2018

@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 MultiSelectScrollIntoView component and whether it makes sense to use it to handle the scrolling behavior when moving block as well. It would make a global EditorScrollManager or something

@youknowriad
Copy link
Contributor

youknowriad commented Feb 13, 2018

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.

@aduth
Copy link
Member Author

aduth commented Feb 14, 2018

Yeah, my only concern so far with this is that it moves access of the DOM node from being ref-bound to querySelector. Wondering if we ought to at least isolate these as well (some getBlockDOMNode helper).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants