Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions packages/core-data/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import { rootEntitiesConfig, getMethodName } from './entities';
import { STORE_NAME } from './name';

// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)
// Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
// The "kind" and the "name" of the entity are combined to generate these shortcuts.

const entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {
const { kind, name } = entity;
result[ getMethodName( kind, name ) ] = ( state, key, query ) =>
selectors.getEntityRecord( state, kind, name, key, query );
result[ getMethodName( kind, name, 'get', true ) ] = ( state, ...args ) =>
selectors.getEntityRecords( state, kind, name, ...args );
result[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>
selectors.getEntityRecords( state, kind, name, query );
return result;
}, {} );

Expand All @@ -35,13 +35,8 @@ const entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {
const pluralMethodName = getMethodName( kind, name, 'get', true );
result[ pluralMethodName ] = ( ...args ) =>
resolvers.getEntityRecords( kind, name, ...args );
result[ pluralMethodName ].shouldInvalidate = ( action, ...args ) =>
resolvers.getEntityRecords.shouldInvalidate(
action,
kind,
name,
...args
);
result[ pluralMethodName ].shouldInvalidate = ( action ) =>
resolvers.getEntityRecords.shouldInvalidate( action, kind, name );
return result;
}, {} );

Expand Down