zoukankan      html  css  js  c++  java
  • js-redux学习笔记2

    1、为了 dispatch 一个 action,我们需要一个 dispatch 函数。可以用一个 action creator 去发送一个 action。

    var setNameActionCreator = function (name) {
        return {
            type: 'SET_NAME',
            name: name
        }
    }
    
    store_0.dispatch(setNameActionCreator('bob'))

    应用流程是这样的:ActionCreator -> Action -> dispatcher -> reducer

    2、使用自定义中间件(middleware)来支持异步 action。

    每当一个 action(或者其他诸如异步 action creator 中的某个函数)被分发时,中间件就会被调用,并且在需要的时候协助 action creator 分发真正的 action。

    为了让 Redux 知道我们有一个或多个中间件,我们使用 Redux 的辅助函数:applyMiddleware.

    applyMiddleware 接收所有中间件作为参数,返回一个供 Redux createStore 调用的函数。当最后这个函数被调用时,它会产生一个 Store 增强器,用来将所有中间件应用到 Store 的 dispatch 上。

    3、使用指定的 React Redux 组件 <Provider>来让所有容器组件都可以访问 store,而不必显示地传递它。只需要在渲染根组件时使用即可。

  • 相关阅读:
    Python-Re正则表达式库
    杂记
    Python 信息提取-beautifulsoup实例
    Python 中国大学排名定向爬虫
    matlab-汉字unicode编码转换
    Python-beautifulsoup库
    python 安装resquest
    python--数字灯管
    Python time库
    Python random库
  • 原文地址:https://www.cnblogs.com/zczhangcui/p/6685047.html
Copyright © 2011-2022 走看看