redux
文章平均质量分 56
爱运动的程序员
19年前端,哈尔滨工业大学软件工程专业
展开
-
redux Store
redux Store 在前面的章节中,我们学会了使用 action 来描述“发生了什么”,和使用 reducers 来根据 action 更新 state 的用法。 Store 就是把它们联系到一起的对象。Store 有以下职责: 1维持应用的 state; 2提供 getState() 方法获取 state; 3提供 dispatch(action) 方法更新 state; 4通过 subscribe(listener) 注册监听器; 5通过 subscribe(listener) 返回的函数注销监听器原创 2021-03-03 10:56:28 · 470 阅读 · 0 评论 -
redux Reducer
Reducer Reducers 指定了应用状态的变化如何响应 actions 并发送到 store 的 设计 State 结构 以 todo 应用为例,需要保存两种不同的数据: 当前选中的任务过滤条件; 完整的任务列表。 { visibilityFilter: 'SHOW_ALL', todos: [ { text: 'Consider using Redux', completed: true, }, { text: 'Keep all原创 2021-03-03 10:47:30 · 271 阅读 · 0 评论 -
redux action
Action Action 是把数据从应用传到 store 的有效载荷。它是 store 数据的唯一来源。一般来说你会通过 store.dispatch() 将 action 传到 store。 添加新 todo 任务的 action 是这样的: const ADD_TODO = 'ADD_TODO' { type: ADD_TODO, text: 'Build my first Redux app' } Action 本质上是 JavaScript 普通对象。我们约定,action 内必须使用原创 2021-03-03 10:11:49 · 669 阅读 · 0 评论