Redux
来源:互联网 发布:c语言repeat是什么意思 编辑:程序博客网 时间:2024/06/04 18:09
Redux 可以用这三个基本原则来描述
1、单一数据源:整个应用的 state 被储存在一棵 object tree 中,并且这个 object tree 只存在于唯一一个 store 中
2、State 是只读的:惟一改变 state 的方法就是触发 action,action 是一个用于描述已发生事件的普通对象。
3、使用纯函数来执行修改:为了描述 action 如何改变 state tree ,你需要编写 reducers。
Reducer 只是一些纯函数,它接收先前的 state 和 action,并返回新的 state
action 来描述“发生了什么”,和使用 reducers 来根据 action 更新 state 的用法。
Store 就是把它们联系到一起的对象
store.dispatch()
将 action 传到 store。2、Action 创建函数:就是生成 action 的方法。在 Redux 中的 action 创建函数只是简单的返回一个 action
二、Reducer
1、指明应用如何更新 state
2、reducer 就是一个纯函数,接收旧的 state 和 action,返回新的 state。
(previousState, action) => newState
3、 combineReducers()
将多个 reducer 合并成为一个
注意:
1) 不要修改 state
。使用 Object.assign()
新建了一个副本。不能这样使用 Object.assign(state,{ visibilityFilter: action.filter })
,因为它会改变第一个参数的值。你必须把第一个参数设置为空对象。
default
情况下返回旧的 state
。遇到未知的 action 时,一定要返回旧的 state
。三、store
1、Store 就是把Action和Reducer联系到一起的对象
2、Store 有以下职责
1)维持应用的state
2)提供getState()方法获取state
3)提供dispatch(action)方法更新state
4)提供subscribe(listener)注册监听器
5)提供subscribe(listener)返回的函数注销监听器
注意:Redux 应用只有一个单一的 store。当需要拆分数据处理逻辑时,你应该使用 reducer 组合而不是创建多个 store。
import { createStore } from 'redux'import todoApp from './reducers'let store = createStore(todoApp)
学习链接:
http://www.redux.org.cn/docs/basics/UsageWithReact.html
http://leonshi.com/redux-saga-in-chinese/docs/api/index.html#createsagamiddlewaresagas
- Redux
- Redux
- Redux
- redux
- redux
- Redux
- Redux
- Redux
- Redux
- Redux
- redux
- redux react-redux
- react+redux+react-redux
- Redux(三: React-Redux)
- 理解 redux
- react-redux
- redux笔记
- redux爬坑记
- jquery实现复制到剪贴板 通用
- nodejs 二进制转十六进制(hex)
- 盒子模型
- 前端学习心得-javascript设计模式与开发实践-AOP面向切面编程
- rhel 6.x 使用 udev scsi rules 配置裸设备
- Redux
- 查看oracle数据库允许的最大连接数和当前连接数
- selinux is active unexpected inconsistency RUN fsck MANUALLY
- MySql的优化系列
- [POJ](2718)Smallest Difference ---- 穷竭搜索
- 队列及其c语言实现
- Linux命令分析:yum
- jQuery函数map()和each()介绍及异同点分析
- 【疑问】Chrome浏览器和firefox浏览器在追踪http时居然不同