Redux学习笔记

  |  
 阅读次数

dispatch

1
2
3
4
5
6
7
8
function (action) {
if (sagaMonitor && sagaMonitor.actionDispatched) {
sagaMonitor.actionDispatched(action);
}
var result = next(action); // hit reducers
sagaEmitter.emit(action);
return result;
};

项目中学习Redux

记录在脚手架学习Demo中尝试使用Redux的过程。

  1. 定义
  2. Action中创建AppRedux文件夹, 创建action.AppRedux.type.js \
    内容如下:

    export const APP_REDUX = “APP_REDUX”;

  3. Action文件夹下index中引入 需要抛出的变量

    import {APP_REDUX} from ‘./AppRedux/action.appRedux.type’;

  4. 定义 一个 Reducer APP_REDUX, 并引入 action 变量 type
  5. 每次程序 dispatch 一个 action,所有 reducer 都会在当前reducer中通过 switch 语句 判断 action 是否 触发本状态
    7.
    1
    2
    3
    import { combineReducers } from 'redux';

    // 所有 reducer 通过 `combineReducers({...Reducers})`方法