File size: 736 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import {
BREADCRUMB_RESET_LIST,
BREADCRUMB_UPDATE_LIST,
BREADCRUMB_APPEND_ITEM,
} from 'calypso/state/action-types';
// Stores the complete list of breadcrumbs in an array,
export default ( state = [], action ) => {
switch ( action.type ) {
case BREADCRUMB_RESET_LIST:
return [];
case BREADCRUMB_UPDATE_LIST:
return [ ...action.items ];
case BREADCRUMB_APPEND_ITEM: {
// If the new item already exists, clear crumbs back to & including the existing item, & add the new item.
const existingItemIndex = state.findIndex( ( item ) => item.id === action.item?.id );
if ( existingItemIndex > -1 ) {
state = state.slice( 0, existingItemIndex );
}
return [ ...state, action.item ];
}
}
return state;
};
|