Skip to content

Commit

Permalink
Core Data: Mark the getEntityRecordNoResolver selector as experimen…
Browse files Browse the repository at this point in the history
…tal. (#20053)
  • Loading branch information
epiqueras authored Feb 6, 2020
1 parent 7900b61 commit c5d9b83
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 70 deletions.
15 changes: 0 additions & 15 deletions docs/designers-developers/developers/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,6 @@ _Returns_

- `?Object`: The entity record's non transient edits.

<a name="getEntityRecordNoResolver" href="#getEntityRecordNoResolver">#</a> **getEntityRecordNoResolver**

Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state.

_Parameters_

- _state_ `Object`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _key_ `number`: Record's key

_Returns_

- `?Object`: Record.

<a name="getEntityRecords" href="#getEntityRecords">#</a> **getEntityRecords**

Returns the Entity's records.
Expand Down
15 changes: 0 additions & 15 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,21 +415,6 @@ _Returns_

- `?Object`: The entity record's non transient edits.

<a name="getEntityRecordNoResolver" href="#getEntityRecordNoResolver">#</a> **getEntityRecordNoResolver**

Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state.

_Parameters_

- _state_ `Object`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _key_ `number`: Record's key

_Returns_

- `?Object`: Record.

<a name="getEntityRecords" href="#getEntityRecords">#</a> **getEntityRecords**

Returns the Entity's records.
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export function* saveEntityRecord(
// Get the full local version of the record before the update,
// to merge it with the edits and then propagate it to subscribers
persistedEntity = yield select(
'getEntityRecordNoResolver',
'__experimentalGetEntityRecordNoResolver',
kind,
name,
recordId
Expand Down
7 changes: 6 additions & 1 deletion packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ export function getEntityRecord( state, kind, name, key ) {
*
* @return {Object?} Record.
*/
export function getEntityRecordNoResolver( state, kind, name, key ) {
export function __experimentalGetEntityRecordNoResolver(
state,
kind,
name,
key
) {
return getEntityRecord( state, kind, name, key );
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core-data/src/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ describe( 'saveEntityRecord', () => {
'SAVE_ENTITY_RECORD_START'
);

// Should select getEntityRecordNoResolver selector (as opposed to getEntityRecord)
// Should select __experimentalGetEntityRecordNoResolver selector (as opposed to getEntityRecord)
// see https://github.com/WordPress/gutenberg/pull/19752#discussion_r368498318.
expect( fulfillment.next().value.type ).toBe( 'SELECT' );
expect( fulfillment.next().value.selectorName ).toBe(
'getEntityRecordNoResolver'
'__experimentalGetEntityRecordNoResolver'
);
expect( fulfillment.next().value.type ).toBe( 'SELECT' );
expect( fulfillment.next().value.type ).toBe( 'RECEIVE_ITEMS' );
Expand Down
72 changes: 36 additions & 36 deletions packages/core-data/src/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import deepFreeze from 'deep-freeze';
*/
import {
getEntityRecord,
getEntityRecordNoResolver,
__experimentalGetEntityRecordNoResolver,
getEntityRecords,
getEntityRecordChangesByRecord,
getEntityRecordNonTransientEdits,
Expand All @@ -21,53 +21,53 @@ import {
getReferenceByDistinctEdits,
} from '../selectors';

// getEntityRecord and getEntityRecordNoResolver selectors share the same tests
describe.each( [ [ getEntityRecord ], [ getEntityRecordNoResolver ] ] )(
'%p',
( selector ) => {
it( 'should return undefined for unknown record’s key', () => {
const state = deepFreeze( {
entities: {
data: {
root: {
postType: {
queriedData: {
items: {},
queries: {},
},
// getEntityRecord and __experimentalGetEntityRecordNoResolver selectors share the same tests
describe.each( [
[ getEntityRecord ],
[ __experimentalGetEntityRecordNoResolver ],
] )( '%p', ( selector ) => {
it( 'should return undefined for unknown record’s key', () => {
const state = deepFreeze( {
entities: {
data: {
root: {
postType: {
queriedData: {
items: {},
queries: {},
},
},
},
},
} );
expect( selector( state, 'root', 'postType', 'post' ) ).toBe(
undefined
);
},
} );
expect( selector( state, 'root', 'postType', 'post' ) ).toBe(
undefined
);
} );

it( 'should return a record by key', () => {
const state = deepFreeze( {
entities: {
data: {
root: {
postType: {
queriedData: {
items: {
post: { slug: 'post' },
},
queries: {},
it( 'should return a record by key', () => {
const state = deepFreeze( {
entities: {
data: {
root: {
postType: {
queriedData: {
items: {
post: { slug: 'post' },
},
queries: {},
},
},
},
},
} );
expect( selector( state, 'root', 'postType', 'post' ) ).toEqual( {
slug: 'post',
} );
},
} );
}
);
expect( selector( state, 'root', 'postType', 'post' ) ).toEqual( {
slug: 'post',
} );
} );
} );

describe( 'getEntityRecords', () => {
it( 'should return an null by default', () => {
Expand Down

0 comments on commit c5d9b83

Please sign in to comment.