-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update for model specific selectors, actions, resolvers
- Loading branch information
Showing
18 changed files
with
540 additions
and
154 deletions.
There are no files selected for viewing
File renamed without changes.
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
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
120 changes: 120 additions & 0 deletions
120
assets/src/data/eventespresso/core/model/entity-actions.js
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* External import | ||
*/ | ||
import { MODEL_NAMES } from '@eventespresso/model'; | ||
|
||
/** | ||
* Internal imports | ||
*/ | ||
import { getMethodName } from '../../base-model'; | ||
|
||
/** | ||
* Dynamic creation of actions for entities | ||
* @param {Object} action The action object that dynamically created functions | ||
* will be mapped to. | ||
* @return {Object} The new action object containing functions for each model. | ||
*/ | ||
export const createActions = ( action ) => MODEL_NAMES.reduce( | ||
( actions, modelName ) => { | ||
actions[ getMethodName( | ||
modelName, | ||
'', | ||
'create' | ||
) ] = ( entity ) => action.createEntity( modelName, entity ); | ||
actions[ getMethodName( | ||
modelName, | ||
'byId', | ||
'delete' | ||
) ] = ( entityId ) => action.deleteEntityById( modelName, entityId ); | ||
actions[ getMethodName( | ||
modelName, | ||
'byId', | ||
'trash', | ||
) ] = ( entityId ) => action.trashEntityById( modelName, entityId ); | ||
actions[ getMethodName( | ||
modelName, | ||
'record', | ||
'persist' | ||
) ] = ( entity ) => action.persistEntityRecord( modelName, entity ); | ||
actions[ getMethodName( | ||
modelName, | ||
'id', | ||
'persistFor', | ||
) ] = ( entityId ) => action.persistForEntityId( modelName, entityId ); | ||
actions[ getMethodName( | ||
modelName, | ||
'ids', | ||
'persistFor', | ||
) ] = ( entityIds ) => action.persistForEntityIds( | ||
modelName, | ||
entityIds | ||
); | ||
actions[ getMethodName( | ||
modelName, | ||
'', | ||
'persistDeletesFor', | ||
) ] = () => action.persistDeletesForModel( modelName ); | ||
actions[ getMethodName( | ||
modelName, | ||
'', | ||
'persistTrashesFor', | ||
) ] = () => action.persistTrashesForModel( modelName ); | ||
actions[ getMethodName( | ||
modelName, | ||
'byId', | ||
'remove', | ||
) ] = ( entityId ) => action.removeEntityById( modelName, entityId ); | ||
actions[ getMethodName( | ||
modelName, | ||
'id', | ||
'removeDelete', | ||
) ] = ( entityId ) => action.removeDeleteEntityId( | ||
modelName, | ||
entityId | ||
); | ||
actions[ getMethodName( | ||
modelName, | ||
'id', | ||
'removeTrash', | ||
) ] = ( entityId ) => action.removeTrashEntityId( modelName, entityId ); | ||
actions[ getMethodName( | ||
modelName, | ||
'records', | ||
'receive', | ||
) ] = ( entities ) => action.receiveEntityRecords( | ||
modelName, | ||
entities | ||
); | ||
actions[ getMethodName( | ||
modelName, | ||
'records', | ||
'receiveAndReplace', | ||
) ] = ( entities ) => action.recieveAndReplaceEntityRecords( | ||
modelName, | ||
entities | ||
); | ||
actions[ getMethodName( | ||
modelName, | ||
'byId', | ||
'remove', | ||
) ] = ( entityId ) => action.removeEntityById( modelName, entityId ); | ||
actions[ getMethodName( | ||
modelName, | ||
'id', | ||
'receiveTrash', | ||
) ] = ( entityId ) => action.receiveTrashEntityId( | ||
modelName, | ||
entityId | ||
); | ||
actions[ getMethodName( | ||
modelName, | ||
'id', | ||
'receiveDelete', | ||
) ] = ( entityId ) => action.receiveDeleteEntityId( | ||
modelName, | ||
entityId | ||
); | ||
return actions; | ||
}, | ||
{} | ||
); |
28 changes: 28 additions & 0 deletions
28
assets/src/data/eventespresso/core/model/entity-resolvers.js
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* External import | ||
*/ | ||
import { MODEL_NAMES } from '@eventespresso/model'; | ||
|
||
/** | ||
* Internal imports | ||
*/ | ||
import { getMethodName } from '../../base-model'; | ||
|
||
/** | ||
* Dynamic creation of resolvers for entities | ||
* @param {Object} resolver The resolver object that dynamically created | ||
* functions will be mapped to. | ||
* @return {Object} The new resolver object containing functions for each model. | ||
*/ | ||
export const createResolvers = ( resolver ) => MODEL_NAMES.reduce( | ||
( resolvers, modelName ) => { | ||
resolvers[ getMethodName( | ||
modelName, | ||
'byId', | ||
'get' | ||
) ] = ( entityId ) => resolver.getEntityById( modelName, entityId ); | ||
|
||
return resolvers; | ||
}, | ||
{} | ||
); |
52 changes: 52 additions & 0 deletions
52
assets/src/data/eventespresso/core/model/entity-selectors.js
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* External import | ||
*/ | ||
import { MODEL_NAMES } from '@eventespresso/model'; | ||
|
||
/** | ||
* Internal imports | ||
*/ | ||
import { getMethodName } from '../../base-model'; | ||
|
||
/** | ||
* Dynamic creation of selectors for entities | ||
* @param {Object} selector selector object that dynamically created functions | ||
* will be mapped to. | ||
* @return {Object} The new selector objects for each model. | ||
*/ | ||
export const createSelectors = ( selector ) => MODEL_NAMES.reduce( | ||
( selectors, modelName ) => { | ||
selectors[ getMethodName( modelName, 'records' ) ] = ( | ||
state | ||
) => selector.getEntityRecordsForModel( state, modelName ); | ||
selectors[ getMethodName( modelName, '', 'get', true ) ] = ( | ||
state | ||
) => selector.getEntitiesForModel( state, modelName ); | ||
selectors[ getMethodName( modelName, 'byId' ) ] = ( | ||
state, | ||
entityId | ||
) => selector.getEntityById( state, modelName, entityId ); | ||
selectors[ getMethodName( modelName, 'byIds', 'get', true ) ] = ( | ||
state, | ||
entityIds, | ||
) => selector.getEntitiesByIds( state, modelName, entityIds ); | ||
selectors[ getMethodName( | ||
modelName, | ||
'idsQueuedForTrash', | ||
'get' | ||
) ] = ( state ) => selector.getEntityIdsQueuedForTrash( | ||
state, | ||
modelName | ||
); | ||
selectors[ getMethodName( | ||
modelName, | ||
'idsQueuedForDelete', | ||
'get' | ||
) ] = ( state ) => selector.getEntityIdsQueuedforDelete( | ||
state, | ||
modelName | ||
); | ||
return selectors; | ||
}, | ||
{} | ||
); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as entityActions from './entity-actions'; | ||
import * as entityResolvers from './entity-resolvers'; | ||
import * as entitySelectors from './entity-selectors'; | ||
import * as relationActions from './relation-actions'; | ||
import * as relationSelectors from './relation-selectors'; | ||
import * as baseSelectors from '../selectors'; | ||
import * as baseActions from '../actions'; | ||
import * as baseResolvers from '../resolvers'; | ||
|
||
export const selectors = { | ||
...entitySelectors.createSelectors( baseSelectors ), | ||
...relationSelectors.createSelectors( baseSelectors ), | ||
}; | ||
|
||
export const actions = { | ||
...entityActions.createActions( baseActions ), | ||
...relationActions.createActions( baseActions ), | ||
}; | ||
|
||
export const resolvers = { | ||
...entityResolvers.createResolvers( baseResolvers ), | ||
}; |
Oops, something went wrong.