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 Library: Add EntityProvider, controlled InnerBlocks and basic template blocks. #17135

Conversation

epiqueras
Copy link
Contributor

cc @youknowriad

Description

This PR puts together the best ideas in #17020 and #17118 to implement Full-Site editing blocks.

Here is the prior art of this refined approach: #17118 (comment).

The Site Title Block was intentionally left out to reduce the scope of this PR, but the Post Content Block was kept so that we have a block to use the new "semi-controlled" InnerBlocks with.

How has this been tested?

The blocks were tested manually to work as expected.

Types of Changes

New Feature: Add new template blocks: Post, Post Title, and Post Content.

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.

aduth and others added 30 commits August 19, 2019 11:11
@epiqueras epiqueras added [Feature] Blocks Overall functionality of blocks [Package] Blocks /packages/blocks [Package] Block library /packages/block-library labels Aug 22, 2019
@epiqueras epiqueras added this to the Future milestone Aug 22, 2019
@epiqueras epiqueras self-assigned this Aug 22, 2019
acc[ entity.name ] = { kind: entity.kind, context: createContext() };
return acc;
}, {} ),
post: { kind: 'postType', context: createContext() },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember properly, there's no way to ensure the name is unique across kinds. so we might be better using a two level objects [kind][name] or just an array of entities.

Also, there might be a better way to automatically create contexts for these dynamic entities (like post).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be better using a two level objects [kind][name]

Yes

Also, there might be a better way to automatically create contexts for these dynamic entities (like post).

We could add this to the store and load them asynchronously, but it seems unnecessarily complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or.....

217bcad

🚀🚀🚀🚀🚀🚀🚀🚀🚀😆

);

const { editEntityRecord } = useDispatch( 'core' );
const setValue = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that you use useCallback a lot across your hooks usage. I personally feel this memoization has more costs than regular functions. I guess it depends on the usage but shouldn't we be adding these only when we measure performance degradation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a library hook, so the cost will be determined by the user, unknown to us.

Users don't expect the function returned to change (like with useState), and they might pass it directly to pure components and break their optimization.

The cost of useCallback is minimal even if paid everywhere the hook is used. A single pure component de-optimization probably offsets it.

useCallbackCost * nTimesUsed < potentiallyLargePureComponentDeOptimizationCost * probabilityThisHappens

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that API-wise, these seems like a good approach. I'm not sure I understand the changes in InnerBlocks entirely yet and as I said, I'm still convinced that we might be better served with separate block lists (without intersections) for separate entities. For example here if I serialize the blocks for a given entity, I'm pretty certain the serialization will include the blocks from other entities in the produces HTML (post-content block).

@epiqueras epiqueras force-pushed the update/the-editor-store-to-use-core-data-entities branch from 4d5de1b to a020241 Compare August 22, 2019 14:35
@epiqueras
Copy link
Contributor Author

I'm not sure I understand the changes in InnerBlocks entirely yet

It's just allowing the parent to sync with it through value and on change props.

I'm pretty certain the serialization will include the blocks from other entities in the produces HTML (post-content block).

No, that's explicitly controlled by the post content block not having a save component.

@epiqueras
Copy link
Contributor Author

Closed in favor of #17153.

@epiqueras epiqueras closed this Aug 27, 2019
@youknowriad youknowriad deleted the add/entity-provider-controlled-inner-blocks-and-basic-template-blocks branch September 9, 2019 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Package] Block library /packages/block-library [Package] Blocks /packages/blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants