美文网首页
你不知道的Redux图集

你不知道的Redux图集

作者: 元气满满321 | 来源:发表于2019-05-16 09:29 被阅读0次

前言

为什么要用Redux

当我们在两个没有父子关系的组件传递数据时,就需要Redux能够管理我们的数据状态,使得这两个组件数据可以通信

Redux flow


1.Components are given callback functions as props, which they call whenever a UI event happens.
2.Those callbacks create and dispatch actions based on the event.
3.Reducers process the actions, computing the new state.
4.The new state of the whole application goes into a single store.
5.Components receive the new state as props and re-render themselves where needed.

自己翻译哒
1.组件可以抛出一个函数,当UI events发生时函数被调用
2.这个函数里创建并抛出了action
3.reducer处理("接住")了这个action,并更新state
4.这个 更新后的state 会放到store中
5,这样,组件就可以从store中获取到新的state作为props,触发页面重新渲染

1.redux整体图

体现了单向数据流:


在没有中间件的时候,Redux是这样的:
Component calls action creator/dispatches action,reducer receive actions,then handle and create new state,finally send state to component


2.Middleware

Middleware的作用:
可以利用superagent向服务器发送请求,并抛出一个action,让reducer接这个action


Middleware的作用

添加Middleware后

只讲知识不写demo,是耍流氓,
举个例子说明Middleware的用法

!!!

3.state tree

state tree

所以在state tree上,component dispatch(发布)出去action到store中,store subscribe(订阅)state是否更新
4.Redux的三大原则

three principles

每天都努力一点
谢谢你看完


相关文章

  • 你不知道的Redux图集

    前言 为什么要用Redux 当我们在两个没有父子关系的组件传递数据时,就需要Redux能够管理我们的数据状态,使得...

  • Redux 入门

    学习 Redux 是个十分痛苦的过程,因为你有可能不知道 Redux 和 React-Redux 是两个不同的东西...

  • 简单的聊一聊redux

    一、何时需要用redux????? 如果你react项目中你不知道什么时候应该使用redux,那就是你不需要...

  • redux-observable

    什么是Redux? Redux是一个了不起的库。对于那些不知道Redux是什么的人来说,它是JavaScript应...

  • Redux

    Redux状态管理 Redux 是 JavaScript 状态管理容器,提供可预测的状态管理。redux 可以让你...

  • #React-Redux

    React-Redux是Redux的官方React绑定库。它能够使你的React组件从Redux store中读取...

  • freeCodeCamp 旅途15 - Redux

    Redux Redux 是 JavaScript 状态容器,提供可预测化的状态管理。Redux 可以让你构建一致化...

  • UGUI Atlas(图集)设置与Bundle方案

    Atlas(图集) 在游戏开发中,图集是一种常见的性能优化,本篇将从原理,设置图集,及图集Bundle策略三方面介...

  • 六、使用redux管理数据

    一、安装redux 、redux-pack、redux-thunk npm i redux redux-pack ...

  • Redux实践(1)

    redux 新的尝试 normalizr redux-actions redux-persist redux-th...

网友评论

      本文标题:你不知道的Redux图集

      本文链接:https://www.haomeiwen.com/subject/pgelzttx.html