search.reducer.ts 761 Bytes
Newer Older
1 2 3 4 5 6
/**
 * reducers/search.reducer.ts
 *
 * Perform operations on the current state of the "search.searchedSections"
 * list in the store and return a new definition of the state.
 */
David Haynes's avatar
David Haynes committed
7
import { SET_SEARCH_SECTIONS } from '../actions/search/search.action-types';
8 9
import { SearchAction } from '../actions/search/search.actions';
import { Section } from '../util/section';
Andrew Hrdy's avatar
Andrew Hrdy committed
10 11 12 13 14

export interface SearchState {
    searchedSections: Section[];
}

David Haynes's avatar
David Haynes committed
15
export const search = (state: SearchState = { searchedSections: [] }, action: SearchAction) => {
Andrew Hrdy's avatar
Andrew Hrdy committed
16 17 18
    switch (action.type) {
        case SET_SEARCH_SECTIONS:
            return Object.assign({}, state, {
David Haynes's avatar
David Haynes committed
19
                searchedSections: [...action.sections],
Andrew Hrdy's avatar
Andrew Hrdy committed
20 21 22 23
            });
        default:
            return state;
    }
David Haynes's avatar
David Haynes committed
24
};