redux(逻辑理解)

redux工作流

模块  action  -->store------>reducers ---->store ----->react(component)

1、用户发出 Action。store.dispatch(action)

2、然后,Store 自动调用 Reducer,并且传入两个参数:当前 State 和收到的 Action。 Reducer 会返回新的 State 。
   let nextState = todoApp(previousState, action);
3、State 一旦有变化,Store 就会调用监听函数。
store.subscribe(listener)
4、listener可以通过store.getState()得到当前状态。如果使用的是 React,这时可以触发重新渲染 View。
function listerner() {
  let newState = store.getState();
  component.setState(newState);   
}

posted @ 2021-03-11 17:19  东方踏凌  阅读(101)  评论(0)    收藏  举报