zoukankan      html  css  js  c++  java
  • 【14】redux 之 redux-actions

    redux-actions有两大法宝createActionhandleActions.

    createAction

    http://www.jianshu.com/p/6ba5cd795077

    原来创建action:

    const startAction = () => ({ type: START });

    使用redux-actions创建action:

    import { createAction } from 'redux-actions';
    const startAction = createAction(START);

    handleActions

    原来reducer操作state写法要使用switchif else来匹配:

    function timer(state = defaultState, action) {
      switch (action.type) {
        case START:
          return { ...state, runStatus: true };
        case STOP:
          return { ...state, runStatus: false };
        case RESET:
          return { ...state, seconds: 0 };
        case RUN_TIMER:
          return { ...state, seconds: state.seconds + 1 };
        default:
          return state;
      }
    }

    使用redux-actions``reducer操作state:

    const timer = handleActions({
      START: (state, action) => ({ ...state, runStatus: true }),
      STOP: (state, action) => ({ ...state, runStatus: false }),
      RESET: (state, action) => ({ ...state, seconds: 0 }),
      RUN_TIMER: (state, action) => ({ ...state, seconds: state.seconds + 1 }),
    }, defaultState);

    http://blog.csdn.net/sinat_17775997/article/details/70176723
  • 相关阅读:
    android-基础编程-RecyclerView
    android-基础编程-ListView
    LINUX 日志服务器的搭建
    使用parted进行磁盘分区
    raid磁盘阵列
    LVM逻辑卷管理
    /home 分区迁移试验
    PHP 匹配一个汉字
    xhr dojo load
    ERR: Call to undefined function openssl_random_pseudo_bytes()
  • 原文地址:https://www.cnblogs.com/yeziTesting/p/7462235.html
Copyright © 2011-2022 走看看