February 2019
Intermediate to advanced
204 pages
4h 52m
English
Next, we need to write reducers. The following reducer is using Immutable JS:
import { List, Map } from "immutable";import { combineReducers } from "redux";import * as types from "../constants/ActionTypes";function todoList(state = List(), action) { switch (action.type) { case types.ADD_TODO: return state.push( Map({ id: action.id, text: action.text, isCompleted: false }) ); case types.COMPLETE_TODO: return state.map(todo => { if (todo.get("id") === action.id) { return todo.update("isCompleted", v => !v); } return todo; }); case types.DELETE_TODO: return state.filter(todo => todo.get("id") !== action.id); case types.DELETE_ALL_TODOS: return state.clear(); default: return state; }}function activeFilter(state = "all", action) { switch ...Read now
Unlock full access