Skip to content

Commit

Permalink
Purchases: Reorder events in Purchases store to be more consistent wi…
Browse files Browse the repository at this point in the history
…th other stores

This also formats a block of code and adds some blank lines - to help us breathe.
  • Loading branch information
stephanethomas committed Nov 23, 2015
1 parent cc5d631 commit e063df5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions client/lib/purchases/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ const INITIAL_STATE = {
};

function updatePurchaseById( state, id, properties ) {
return assign( {}, state, { data: state.data.map( purchase => {
if ( id === purchase.id ) {
return assign( {}, purchase, properties );
}
return purchase;
} ) } );
return assign( {}, state, {
data: state.data.map( purchase => {
if ( id === purchase.id ) {
return assign( {}, purchase, properties );
}
return purchase;
} )
} );
}

const PurchasesStore = createReducerStore( ( state, payload ) => {
const { action } = payload;

switch ( action.type ) {
case ActionTypes.PURCHASES_SITE_FETCH_FAILED:
case ActionTypes.PURCHASES_USER_FETCH_FAILED:
return assign( {}, state, { error: action.error } );
case ActionTypes.PURCHASES_SITE_FETCH:
case ActionTypes.PURCHASES_USER_FETCH:
return assign( {}, state, { isFetching: true } );

case ActionTypes.PURCHASES_SITE_FETCH_COMPLETED:
case ActionTypes.PURCHASES_USER_FETCH_COMPLETED:
let { purchases } = action;
Expand All @@ -56,15 +56,22 @@ const PurchasesStore = createReducerStore( ( state, payload ) => {
isFetching: false,
hasLoadedFromServer: true
} );

case ActionTypes.PURCHASES_SITE_FETCH_FAILED:
case ActionTypes.PURCHASES_USER_FETCH_FAILED:
return assign( {}, state, { error: action.error } );

case ActionTypes.PURCHASES_PRIVATE_REGISTRATION_CANCEL_COMPLETED:
return updatePurchaseById( state, action.purchaseId, {
error: null,
hasPrivateRegistration: false
} );

case ActionTypes.PURCHASES_PRIVATE_REGISTRATION_CANCEL_FAILED:
return updatePurchaseById( state, action.purchaseId, {
error: action.error
} );

default:
return state;
}
Expand Down

0 comments on commit e063df5

Please sign in to comment.