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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Implement `EntityProvider` and use it to refactor custom sources with a backwards compatibility hook for meta sources. #17153

Open
wants to merge 5 commits into
base: master
from

Conversation

@epiqueras
Copy link
Contributor

commented Aug 22, 2019

Description

This PR implements the notorious EntityProvider and a useEntityProp hook, and uses them to refactor custom sources, with a backwards compatibility hook for meta sources.

It's the first step in getting the features of #16565 and:

shipped 馃殌

How has this been tested?

All the current test suites that test meta attribute sources were verified to still be passing.

Types of Changes

New Feature: Add a new EntityProvider component and a useEntityProp hook that allows blocks to edit and sync with different entities, removing the need for custom sources in the process.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
@@ -28,6 +28,7 @@
"@wordpress/blocks": "file:../blocks",
"@wordpress/components": "file:../components",
"@wordpress/compose": "file:../compose",
"@wordpress/core-data": "file:../core-data",

This comment has been minimized.

Copy link
@youknowriad

youknowriad Aug 23, 2019

Contributor

This is not something we should be doing. Adding core-data as a dependency to the generic BlockEditor module (WP agnostic).

This comment has been minimized.

Copy link
@youknowriad

youknowriad Aug 23, 2019

Contributor

I think we can probably use the BlockListBlock filter to add this in the Editor package instead.

This comment has been minimized.

Copy link
@epiqueras

epiqueras Aug 23, 2019

Author Contributor

Yeah, good idea.

I paused when doing this initially, but then went with it, because block-library does depend on core-data now, but that is not WP agnostic as block-editor is.

<ReusableBlocksButtons />
<ConvertToGroupButtons />
</BlockEditorProvider>
<EntityProvider kind="postType" type={ post.type } id={ post.id }>

This comment has been minimized.

Copy link
@youknowriad

youknowriad Aug 23, 2019

Contributor

Right, makes me think later once we have the "full site editing" modes, this entity provider wouldn't be added automatically but only when the "Post" block is used (for the other modes, not the regular one).

This comment has been minimized.

Copy link
@epiqueras

epiqueras Aug 23, 2019

Author Contributor

Yeah

}

return [ attributes, setAttributes ];
}

This comment has been minimized.

Copy link
@youknowriad

youknowriad Aug 23, 2019

Contributor

Can we somehow bail early if we detect that the blockType doesn't have any "meta" attribute (for performance reasons).

This comment has been minimized.

Copy link
@epiqueras

epiqueras Aug 23, 2019

Author Contributor

Yeah, it does that:

if ( Object.values( attributeTypes ).some( ( type ) => type.source === 'meta' ) ) {
@youknowriad
Copy link
Contributor

left a comment

I like this, I wonder if this improves the editor perfs a bit?

@epiqueras

This comment has been minimized.

Copy link
Contributor Author

commented Aug 23, 2019

Master:

Average time to load: 4560ms
Average time to DOM content load: 4252ms
Average time to type character: 53.8ms
Slowest time to type character: 129ms
Fastest time to type character: 48ms

This Branch:

Average time to load: 4583ms
Average time to DOM content load: 4297ms
Average time to type character: 47.085ms
Slowest time to type character: 102ms
Fastest time to type character: 41ms
@epiqueras

This comment has been minimized.

Copy link
Contributor Author

commented Aug 23, 2019

Change:

Average time to load: 0.50%
Average time to DOM content load: 1.06%
Average time to type character: -12.48%
Slowest time to type character: -20.93%
Fastest time to type character: -14.58%

馃殌

@epiqueras epiqueras force-pushed the add/entity-provider-and-refactor-custom-sources branch from 8f3ede8 to c484874 Sep 16, 2019

epiqueras and others added 2 commits Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can鈥檛 perform that action at this time.