import { ConfigActions } from '../model/config' ; import { Todo , TodoAction , TodoActions } from '../model/index' ; import createReducer from './createReducer' ; export const todoList = createReducer < Todo [ ] > ( [ ] , { [ TodoActions . ADD_TODO ] ( state , action ) { return [ ... state , action . payload ] ; } , [ TodoActions . COMPLETE_TODO ] ( state , action ) { return state . map ( t => ( t . id === action . payload ? { ... t , completed : true } : t ) ) ; } , [ TodoActions . UNCOMPLETE_TODO ] ( state , action ) { return state . map ( t => ( t . id === action . payload ? { ... t , completed : false } : t ) ) ; } , [ TodoActions . DELETE_TODO ] ( state , action ) { return state . filter ( t => t . id !== action . payload ) ; } , [ ConfigActions . PURGE_STATE ] ( state , action ) { return [ ] ; } , } ) ;