-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Core Data: Avoid extraneous when creating a new record #72666
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -525,8 +525,9 @@ export const saveEntityRecord = | |
| if ( ! entityConfig ) { | ||
| return; | ||
| } | ||
| const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; | ||
| const entityIdKey = entityConfig.key ?? DEFAULT_ENTITY_KEY; | ||
| const recordId = record[ entityIdKey ]; | ||
| const isNewRecord = !! entityIdKey && ! recordId; | ||
|
Contributor
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. Why are we concerned about
Member
Author
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. For the
Contributor
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. It's a smallish breaking change I guess but I don't really expect impact, WDYT.
Member
Author
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. I don't expect this to break any consumer code. |
||
|
|
||
| const lock = await dispatch.__unstableAcquireStoreLock( | ||
| STORE_NAME, | ||
|
|
@@ -580,11 +581,10 @@ export const saveEntityRecord = | |
| } | ||
| try { | ||
| const path = `${ baseURL }${ recordId ? '/' + recordId : '' }`; | ||
| const persistedRecord = select.getRawEntityRecord( | ||
| kind, | ||
| name, | ||
| recordId | ||
| ); | ||
| // Skip the raw values check when creating a new record; they don't exist yet. | ||
| const persistedRecord = ! isNewRecord | ||
| ? select.getRawEntityRecord( kind, name, recordId ) | ||
| : {}; | ||
|
|
||
| if ( isAutosave ) { | ||
| // Most of this autosave logic is very specific to posts. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ export const rootEntitiesConfig = [ | |
| { | ||
| label: __( 'Base' ), | ||
| kind: 'root', | ||
| key: false, | ||
|
Member
Author
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. The |
||
| name: '__unstableBase', | ||
| baseURL: '/', | ||
| baseURLParams: { | ||
|
|
@@ -381,6 +382,7 @@ async function loadSiteEntity() { | |
| label: __( 'Site' ), | ||
| name: 'site', | ||
| kind: 'root', | ||
| key: false, | ||
|
Member
Author
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. Same here, should I add a comment? |
||
| baseURL: '/wp/v2/settings', | ||
| meta: {}, | ||
| }; | ||
|
|
||
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 think it makes sense to update similar assignments to use the nullish coalescing operator. The entity either has a key defined or will be using the fallback.
I don't expect this to be a breaking change.
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.
@youknowriad, what do you think about this? Should I make similar changes in other places? Mostly for consistency.