Merge "Hygiene: DRY up eventLogging reducer"

This commit is contained in:
jenkins-bot 2017-04-11 16:48:46 +00:00 committed by Gerrit Code Review
commit ecdb6e4821
3 changed files with 20 additions and 11 deletions

Binary file not shown.

Binary file not shown.

View file

@ -81,7 +81,11 @@ function createAbandonEvent( interaction ) {
* @return {Object} The state as a result of processing the action
*/
module.exports = function ( state, action ) {
var nextCount;
var nextCount,
actionTypesWithTokens = [
actionTypes.FETCH_COMPLETE,
actionTypes.ABANDON_END
];
if ( state === undefined ) {
state = {
@ -92,6 +96,15 @@ module.exports = function ( state, action ) {
};
}
// Was the action delayed? Then it requires a token to be reduced. Enforce
// this here to avoid repetion and reduce nesting below.
if (
actionTypesWithTokens.indexOf( action.type ) !== -1 &&
( !state.interaction || action.token !== state.interaction.token )
) {
return state;
}
switch ( action.type ) {
case actionTypes.BOOT:
return nextState( state, {
@ -108,15 +121,11 @@ module.exports = function ( state, action ) {
} );
case actionTypes.FETCH_COMPLETE:
if ( state.interaction && action.token === state.interaction.token ) {
return nextState( state, {
interaction: nextState( state.interaction, {
previewType: action.result.type
} )
} );
}
return state;
return nextState( state, {
interaction: nextState( state.interaction, {
previewType: action.result.type
} )
} );
case actionTypes.PREVIEW_SHOW:
nextCount = state.previewCount + 1;
@ -185,7 +194,7 @@ module.exports = function ( state, action ) {
} );
case actionTypes.ABANDON_END:
if ( action.token === state.interaction.token && !state.interaction.isUserDwelling ) {
if ( !state.interaction.isUserDwelling ) {
return nextState( state, {
interaction: undefined,
event: createAbandonEvent( state.interaction )