zoukankan      html  css  js  c++  java
  • react-redux 和 redux-saga 小结

    react-redux 将 store 绑定到 props 上,便于全局调用。

    redux-saga 是将 redux 的同步转换为异步。

    注:

    dispatch 到 saga , saga 匹配行为的 type,调用接口请求数据,并将数据 通过 dispatch 传给 redux。

    redux 匹配 type 并将数据绑定到 props 上

    思路:

    (1)routes 下的页面触发 action

    this.props.dispatch({
      type:"xxx", // 行为名称
      payload: yyy
    })

    (2)saga 下的异步 redux 进行匹配

    找到对应的 fork(reducer)

    在 reducer 中调用整体的也是唯一的 action

    yield takeLatest("xxx",(yyy) => functionName(yyy))

    在 functionName 中使用 put 代替 dispatch

    yield put({
      type:"aaa", // 数据type
      payload: bbb
    })

    (3)redux 下的同步 redux 进行匹配

    找到对应的 reducer

    在 reducer 中进行 type 匹配

    case 匹配 type , return 出去的数据 需要 先 

    const initstate = { ccc: ddd }

    初始化。

    将获取的 数据 return 到 props 上

    (4)全局获取 store 上的数据

    const { ccc } = this.props;

    .

  • 相关阅读:
    HDU 5585 Numbers
    HDU 3308 LCIS
    POJ 2991 Crane
    POJ 1436 Horizontally Visible Segments
    POJ 3667 Hotel
    HaiHongOJ 1003 God Wang
    【SDOI 2008】 递归数列
    5月19日省中提高组题解
    【HDU 1588】 Gauss Fibonacci
    【POJ 3233】Matrix Power Series
  • 原文地址:https://www.cnblogs.com/crazycode2/p/9256863.html
Copyright © 2011-2022 走看看