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

Editor: Refactor currentPost state to use core-data package #16520

Closed
aduth opened this issue Jul 10, 2019 · 4 comments
Closed

Editor: Refactor currentPost state to use core-data package #16520

aduth opened this issue Jul 10, 2019 · 4 comments
Labels
[Package] Core data /packages/core-data [Package] Editor /packages/editor [Type] Code Quality Issues or PRs that relate to code quality

Comments

@aduth
Copy link
Member

aduth commented Jul 10, 2019

Previously: #16402 (comment)

The editor maintains a copy of the original post being edited in its state, as currentPost. This value is always representative of the last saved value of the post; edits are maintained separately. There should be effectively no difference between this value and what would be produced by...

wp.data.select( 'core' ).getEntityRecord( 'postType', 'post', wp.data.select( 'core/editor' ).getCurrentPostId() );

By using the entity provided from the core-data data store, we gain some benefit:

  • There is only at most one copy of the post held in memory at a given time
  • Updates to the canonical post are reflected in the editor, and vice-versa
  • The implementation will likely push us to implement saving and setting behaviors for core-data entities (and a subsequent refactor of savePost to use core-data as well)
  • Reduced implementation complexity and maintenance overhead of the editor reducer file

Implementation Specifics:

For the most part, the crux of the implementation requires changing...

export function getCurrentPost( state ) {
return state.currentPost;
}

...to:

export const getCurrentPost = createRegistrySelector( ( registry ) => ( state ) => {
	return registry.select( 'core' ).getEntityRecord( 'postType', 'post' /* !!! */, getCurrentPostId( state ) );
} );

Some details:

  • How do we know the post type? We may still need to track this in editor state, or as an edit. This is unfortunately required because an entity cannot be retrieved from the REST API without providing its post type (related discussion).
  • We should see about providing a simpler interface to retrieving entities (I thought we already had getPost etc. auto-generated for entities?)
@aduth aduth added [Type] Code Quality Issues or PRs that relate to code quality [Package] Core data /packages/core-data [Package] Editor /packages/editor labels Jul 10, 2019
@gziolo
Copy link
Member

gziolo commented Oct 20, 2019

const post = select( 'core' ).getRawEntityRecord( 'postType', postType, postId );

It looks like it was addressed in #16932 by @epiqueras.

@Mamaduka
Copy link
Member

@gziolo, should we close this issue?

@gziolo
Copy link
Member

gziolo commented Jul 21, 2021

I don't know and that's why I didn't close this issue 😄

@gziolo
Copy link
Member

gziolo commented Sep 1, 2022

I did another check. Everything is implemented.

@gziolo gziolo closed this as completed Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Package] Editor /packages/editor [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

No branches or pull requests

3 participants