Created
December 18, 2019 02:08
-
-
Save mayrascript/a45b24c28656b42090cede153772d514 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { actions } from 'src/app/core/services/store/actions'; | |
| import { AppState } from 'src/app/core/services/store/app-state'; | |
| export interface Action { | |
| type: string; | |
| payload?: any; | |
| } | |
| export interface Reducer<T> { | |
| (state: T, action: Action): T; | |
| } | |
| export const storeReducers: Reducer<AppState> = (state: any = {}, action: Action): AppState => { | |
| switch (action.type) { | |
| case actions.add: | |
| return { | |
| ...state, | |
| courses: [...state.courses, action.payload.course], | |
| currentCourse: {...action.payload.course} | |
| }; | |
| case actions.update: | |
| const filtered = state.courses.filter((c) => c.id !== action.payload.course.id); | |
| return { | |
| ...state, | |
| courses: [...filtered, action.payload.course], | |
| currentCourse: {...action.payload.course} | |
| }; | |
| case actions.remove: | |
| const courses = state.courses.filter((c) => c.id !== action.payload.course.id); | |
| return { | |
| ...state, | |
| courses | |
| }; | |
| default: | |
| return state; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment