app.js 413 B

123456789101112131415161718192021222324
  1. import { Map } from "immutable";
  2. import {
  3. INCREMENT,
  4. } from "actions/app";
  5. const initialState = Map({
  6. counter: 0,
  7. });
  8. const actionsMap = {
  9. [INCREMENT]: (state) => {
  10. const counter = state.get("counter") + 1;
  11. return state.merge({
  12. counter,
  13. });
  14. },
  15. };
  16. export default function reducer(state = initialState, action = {}) {
  17. const fn = actionsMap[action.type];
  18. return fn ? fn(state, action) : state;
  19. }