Skip to content

Commit

Permalink
add constants for action types
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad committed Jan 1, 2019
1 parent ec9a546 commit 4df4d8d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions assets/src/data/eventespresso/lists/action-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const ACTION_TYPES = {
RECEIVE_LIST: 'RECEIVE_LIST',
RECEIVE_ENTITY_LIST: 'RECEIVE_ENTITY_LIST',
};
9 changes: 7 additions & 2 deletions assets/src/data/eventespresso/lists/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Internal imports
*/
import { ACTION_TYPES as types } from './action-types';

/**
* Returns an action object used in updating the store with the provided items
* retrieved from a request using the given querystring.
Expand All @@ -19,7 +24,7 @@
*/
export function receiveResponse( identifier, queryString, items = [] ) {
return {
type: 'RECEIVE_LIST',
type: types.RECEIVE_LIST,
identifier,
queryString,
items,
Expand All @@ -42,7 +47,7 @@ export function receiveEntityResponse(
entities = new Map(),
) {
return {
type: 'RECEIVE_ENTITY_LIST',
type: types.RECEIVE_ENTITY_LIST,
identifier: modelName,
queryString,
items: entities,
Expand Down
5 changes: 3 additions & 2 deletions assets/src/data/eventespresso/lists/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import { DEFAULT_LISTS_STATE } from '../../model';
import { ACTION_TYPES as types } from './action-types';

/**
* External dependencies
Expand All @@ -25,11 +26,11 @@ export function receiveListItems(
let doUpdate = true,
existingValues;
switch ( type ) {
case 'RECEIVE_LIST':
case types.RECEIVE_LIST:
existingValues = state.getIn( path ) || Set();
items = existingValues.merge( items );
break;
case 'RECEIVE_ENTITY_LIST':
case types.RECEIVE_ENTITY_LIST:
existingValues = state.getIn( path ) || OrderedMap();
items = existingValues.merge(
items.map( entity => [ entity.id, entity ] )
Expand Down
7 changes: 4 additions & 3 deletions assets/src/data/eventespresso/lists/test/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { fromJS, OrderedMap, Map, Set } from 'immutable';
* Internal dependencies
*/
import { receiveListItems } from '../reducers';
import { ACTION_TYPES as types } from '../action-types';
import {
genericObjects,
eventEntityItems,
Expand Down Expand Up @@ -102,7 +103,7 @@ describe( 'receiveListItems()', () => {
testRunner(
testConditions,
originalState,
'RECEIVE_LIST',
types.RECEIVE_LIST,
'generic'
);
} );
Expand All @@ -112,7 +113,7 @@ describe( 'receiveListItems()', () => {
' original state', () => {
const originalState = fromJS( { event: {} } );
const state = receiveListItems( originalState, {
type: 'RECEIVE_ENTITY_LIST',
type: types.RECEIVE_ENTITY_LIST,
identifier: 'event',
queryString: '?some_value=1',
items: eventEntityItems,
Expand Down Expand Up @@ -202,7 +203,7 @@ describe( 'receiveListItems()', () => {
testRunner(
testConditions,
originalState,
'RECEIVE_ENTITY_LIST',
types.RECEIVE_ENTITY_LIST,
'event',
);
} );
Expand Down

0 comments on commit 4df4d8d

Please sign in to comment.