Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0703 #6

Open
LeungKaMing opened this issue Jul 3, 2017 · 0 comments
Open

0703 #6

LeungKaMing opened this issue Jul 3, 2017 · 0 comments

Comments

@LeungKaMing
Copy link
Owner

数据流

Redux architecture revolves around a strict unidirectional data flow.

官网原话:Redux架构是围绕严格的==单向数据流==。

数据流的生命周期遵循以下4点:

  1. store.dispatch(action)
  • 能够在React应用的任何地方调用这个方法,无论是组件还是异步回调还是定时器。
  1. Redux会调用所有你定义的Reducer函数
  • 初始化Reducer,前面提到过。
  • 只会计算下一个状态,并且是可预测的:相同的参数进来,相同的输出出去。
  • 期间不应有任何API调用和路由跳转。
  1. 一个根Reducer永远对应一个状态树
  • 但Reducer可以有多个,对应的State也有多个。
// combineReducer
function todos(state = [], action) {
  // Somehow calculate it...
  return nextState
}

function visibleTodoFilter(state = 'SHOW_ALL', action) {
  // Somehow calculate it...
  return nextState
}

// 多个Reducer合并成一个
let todoApp = combineReducers({
  todos,
  visibleTodoFilter
})

var store = createStore(todoApp)
  1. 通过根Reducer返回整个Redux的完整状态树
  • 一个起点发散开来。
This was referenced Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant