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

Custom Block Attribute Sources #16282

Closed
youknowriad opened this issue Jun 25, 2019 · 1 comment · Fixed by #16402
Closed

Custom Block Attribute Sources #16282

youknowriad opened this issue Jun 25, 2019 · 1 comment · Fixed by #16402
Labels
[Feature] Block API API that allows to express the block paradigm. Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Overview Comprehensive, high level view of an area of focus often with multiple tracking issues [Type] Task Issues or PRs that have been broken down into an individual action to take
Milestone

Comments

@youknowriad
Copy link
Contributor

youknowriad commented Jun 25, 2019

Blocks support two types of attributes:

  • Attributes saved to post content (all the sourced and comment attributes),
  • Post meta attributes saved to the post meta fields.

In order to support full site editing requirements, the attribute sources need to be expanded to cover a lot more use-cases:

  • Post title attribute,
  • Post content attribute (the whole post content string),
  • Post taxonomies,
  • Basically any editable post property in the REST API post object,
  • Site options attributes.

Instead of supporting all these attribute sources in an ad-hoc way, a generic API to register custom attribute sources should be provided.

Related Issues and PRs: 5077, 16075

@youknowriad youknowriad added [Feature] Block API API that allows to express the block paradigm. Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Task Issues or PRs that have been broken down into an individual action to take labels Jun 25, 2019
@mtias mtias added the [Type] Overview Comprehensive, high level view of an area of focus often with multiple tracking issues label Jun 25, 2019
@youknowriad youknowriad added this to the WordPress 5.x milestone Jun 25, 2019
@epiqueras
Copy link
Contributor

We discussed a tentative API for this today with @aduth (we are not convinced of the naming yet) :

Whiteboarding

The result of our collaborative white-boarding^^ I have to take the blame for the bad drawing skills 😆

It supports registering custom sources of 3 different types that differ in where the data is kept in memory and storage. "Fetchers & Savers" define where to get the data from at the start of an editing cycle and where to put it at the end of an editing cycle. "Selectors & Actions/Updaters/Dispatchers", which are automatically generated based on the type of the source, define how the attributes are read and modified in memory, during the editing cycle.

It also adds a "shared attributes" slice to the block editor store for blocks to have a single source of truth for global or post-wide attribute sources.

  • type: 'post' will have fetchers that read from the editor store's post properties and create a special slice of shared attributes that syncs with post properties in the editor store. This is necessary for maintaining block independence from the editor store. Reading and updating the values during editing will be pretty straightforward and the post saving functionality will take care of persistence.

  • type: 'shared' will have asynchronous fetchers/savers that set/read to/from the shared attributes slice of the block editor store. Reading and updating from shared attributes will give cross-block syncing for free.

  • type: 'local', the default, will be almost identical to current standard attribute sources, except that they will have asynchronous fetchers and savers for defining where to get and put the data at the start and end of editing.

@aduth Will keep exploring this while I start to build the first use case for this in #16281 .

Let's try to get as much feedback as possible on this and keep iterating, as I think that the final API for this will have a huge impact on the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Overview Comprehensive, high level view of an area of focus often with multiple tracking issues [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants