-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use consistent terminology across @wordpress/core-data #39349
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3bef33d
Refactor entities.js to talk about configs and loaders
adamziel 5c5dc0d
Rename state.entities.data to state.entities.records
adamziel cea1da7
Rename getEntity to getEntityConfig
adamziel a9a4662
Rename Entity to Entity Config or Entity Provider, whichever was appr…
adamziel 6b41f40
Rename variables called entity/entities to entityConfig/configs
adamziel 4c87d95
Adjust the terminology used in comments
adamziel 8d31a5c
Lint
adamziel 2b3653b
Rename entity type to entity name
adamziel 3c45c25
Regenerate docs
adamziel 3b1cae7
Migrate consumers of core-data to use getEntityConfig
adamziel f353b65
Lint
adamziel e11e359
Use a proper deprecation comment to indicate WordPress 6.0
adamziel 4005f3b
Update README with the new deprecation notices
adamziel 970b9f3
Abracadabra, static checks turn green (Regenerate data-core.md)
adamziel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import deprecated from '@wordpress/deprecated'; | |
* Internal dependencies | ||
*/ | ||
import { receiveItems, removeItems, receiveQueriedItems } from './queried-data'; | ||
import { getKindEntities, DEFAULT_ENTITY_KEY } from './entities'; | ||
import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities'; | ||
import { createBatch } from './batch'; | ||
import { STORE_NAME } from './name'; | ||
|
||
|
@@ -66,8 +66,8 @@ export function addEntities( entities ) { | |
/** | ||
* Returns an action object used in signalling that entity records have been received. | ||
* | ||
* @param {string} kind Kind of the received entity. | ||
* @param {string} name Name of the received entity. | ||
* @param {string} kind Kind of the received entity record. | ||
* @param {string} name Name of the received entity record. | ||
* @param {Array|Object} records Records received. | ||
* @param {?Object} query Query Object. | ||
* @param {?boolean} invalidateCache Should invalidate query caches. | ||
|
@@ -209,9 +209,9 @@ export function receiveEmbedPreview( url, preview ) { | |
/** | ||
* Action triggered to delete an entity record. | ||
* | ||
* @param {string} kind Kind of the deleted entity. | ||
* @param {string} name Name of the deleted entity. | ||
* @param {string} recordId Record ID of the deleted entity. | ||
* @param {string} kind Kind of the deleted entity record. | ||
* @param {string} name Name of the deleted entity record. | ||
* @param {string} recordId Record ID of the deleted entity record. | ||
* @param {?Object} query Special query parameters for the | ||
* DELETE API call. | ||
* @param {Object} [options] Delete options. | ||
|
@@ -226,17 +226,17 @@ export const deleteEntityRecord = ( | |
query, | ||
{ __unstableFetch = apiFetch } = {} | ||
) => async ( { dispatch } ) => { | ||
const entities = await dispatch( getKindEntities( kind ) ); | ||
const entity = find( entities, { kind, name } ); | ||
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) ); | ||
const entityConfig = find( configs, { kind, name } ); | ||
let error; | ||
let deletedRecord = false; | ||
if ( ! entity || entity?.__experimentalNoFetch ) { | ||
if ( ! entityConfig || entityConfig?.__experimentalNoFetch ) { | ||
return; | ||
} | ||
|
||
const lock = await dispatch.__unstableAcquireStoreLock( | ||
STORE_NAME, | ||
[ 'entities', 'data', kind, name, recordId ], | ||
[ 'entities', 'records', kind, name, recordId ], | ||
{ exclusive: true } | ||
); | ||
|
||
|
@@ -249,7 +249,7 @@ export const deleteEntityRecord = ( | |
} ); | ||
|
||
try { | ||
let path = `${ entity.baseURL }/${ recordId }`; | ||
let path = `${ entityConfig.baseURL }/${ recordId }`; | ||
|
||
if ( query ) { | ||
path = addQueryArgs( path, query ); | ||
|
@@ -299,13 +299,13 @@ export const editEntityRecord = ( | |
edits, | ||
options = {} | ||
) => ( { select, dispatch } ) => { | ||
const entity = select.getEntity( kind, name ); | ||
if ( ! entity ) { | ||
const entityConfig = select.getEntityConfig( kind, name ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my goodness this line's change alone makes this PR worthwhile. |
||
if ( ! entityConfig ) { | ||
throw new Error( | ||
`The entity being edited (${ kind }, ${ name }) does not have a loaded config.` | ||
); | ||
} | ||
const { transientEdits = {}, mergedEdits = {} } = entity; | ||
const { transientEdits = {}, mergedEdits = {} } = entityConfig; | ||
const record = select.getRawEntityRecord( kind, name, recordId ); | ||
const editedRecord = select.getEditedEntityRecord( kind, name, recordId ); | ||
|
||
|
@@ -401,17 +401,17 @@ export const saveEntityRecord = ( | |
record, | ||
{ isAutosave = false, __unstableFetch = apiFetch } = {} | ||
) => async ( { select, resolveSelect, dispatch } ) => { | ||
const entities = await dispatch( getKindEntities( kind ) ); | ||
const entity = find( entities, { kind, name } ); | ||
if ( ! entity || entity?.__experimentalNoFetch ) { | ||
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) ); | ||
const entityConfig = find( configs, { kind, name } ); | ||
if ( ! entityConfig || entityConfig?.__experimentalNoFetch ) { | ||
return; | ||
} | ||
const entityIdKey = entity.key || DEFAULT_ENTITY_KEY; | ||
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; | ||
const recordId = record[ entityIdKey ]; | ||
|
||
const lock = await dispatch.__unstableAcquireStoreLock( | ||
STORE_NAME, | ||
[ 'entities', 'data', kind, name, recordId || uuid() ], | ||
[ 'entities', 'records', kind, name, recordId || uuid() ], | ||
{ exclusive: true } | ||
); | ||
|
||
|
@@ -446,7 +446,7 @@ export const saveEntityRecord = ( | |
let updatedRecord; | ||
let error; | ||
try { | ||
const path = `${ entity.baseURL }${ | ||
const path = `${ entityConfig.baseURL }${ | ||
recordId ? '/' + recordId : '' | ||
}`; | ||
const persistedRecord = select.getRawEntityRecord( | ||
|
@@ -543,10 +543,10 @@ export const saveEntityRecord = ( | |
} | ||
} else { | ||
let edits = record; | ||
if ( entity.__unstablePrePersist ) { | ||
if ( entityConfig.__unstablePrePersist ) { | ||
edits = { | ||
...edits, | ||
...entity.__unstablePrePersist( | ||
...entityConfig.__unstablePrePersist( | ||
persistedRecord, | ||
edits | ||
), | ||
|
@@ -659,12 +659,12 @@ export const saveEditedEntityRecord = ( | |
if ( ! select.hasEditsForEntityRecord( kind, name, recordId ) ) { | ||
return; | ||
} | ||
const entities = await dispatch( getKindEntities( kind ) ); | ||
const entity = find( entities, { kind, name } ); | ||
if ( ! entity ) { | ||
const configs = await dispatch( getOrLoadEntitiesConfig( kind ) ); | ||
const entityConfig = find( configs, { kind, name } ); | ||
if ( ! entityConfig ) { | ||
return; | ||
} | ||
const entityIdKey = entity.key || DEFAULT_ENTITY_KEY; | ||
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; | ||
|
||
const edits = select.getEntityRecordNonTransientEdits( | ||
kind, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a reason we dispatch this action here but rely on the
getEntityConfig
selector foreditEntityRecord
, and dispatch again onsaveEntityRecord
when deleting and saving we will try and fetch more entity configs if we can't find the given one, but on
edit
we give up immediately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that by the time we edit an entity record, it must have been resolved, which means that the loading already happened in a different code path. Definitely confusing, though. It would be easier to read if we relied on
getOrLoad
ineditEntityRecord
too, even if only for consistency. Let's save it for another PR.