Skip to content

Commit b115040

Browse files
authored
Core Data: Replace spread arguments with non-spread variants (#39477)
When dynamically creating accessor and updator methods for core data entities we catch variable arguments in the methods and pass them through as spread arguments. While this offers a certain expandability should we update the underlying methods it also confuses the types of the interfaces since those underlying methods don't allow variable argument lists (or at least, they ignore anything past the known arguments). In this patch we're replacing those spread variants with direct named arguments to match the underlying inferface. This will present cleaner types and remove one bit of confusion.
1 parent 73c4f18 commit b115040

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

packages/core-data/src/index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import { rootEntitiesConfig, getMethodName } from './entities';
1515
import { STORE_NAME } from './name';
1616

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

2222
const entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {
2323
const { kind, name } = entity;
2424
result[ getMethodName( kind, name ) ] = ( state, key, query ) =>
2525
selectors.getEntityRecord( state, kind, name, key, query );
26-
result[ getMethodName( kind, name, 'get', true ) ] = ( state, ...args ) =>
27-
selectors.getEntityRecords( state, kind, name, ...args );
26+
result[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>
27+
selectors.getEntityRecords( state, kind, name, query );
2828
return result;
2929
}, {} );
3030

@@ -35,13 +35,8 @@ const entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {
3535
const pluralMethodName = getMethodName( kind, name, 'get', true );
3636
result[ pluralMethodName ] = ( ...args ) =>
3737
resolvers.getEntityRecords( kind, name, ...args );
38-
result[ pluralMethodName ].shouldInvalidate = ( action, ...args ) =>
39-
resolvers.getEntityRecords.shouldInvalidate(
40-
action,
41-
kind,
42-
name,
43-
...args
44-
);
38+
result[ pluralMethodName ].shouldInvalidate = ( action ) =>
39+
resolvers.getEntityRecords.shouldInvalidate( action, kind, name );
4540
return result;
4641
}, {} );
4742

0 commit comments

Comments
 (0)