首先,用户发出 Action。


store.dispatch(action);

然后,Store 自动调用 Reducer,并且传入两个参数:当前 State 和收到的 Action。 Reducer 会返回新的 State 。


let nextState = todoApp(previousState, action);

State 一旦有变化,Store 就会调用监听函数。


// 设置监听函数
store.subscribe(listener);

listener可以通过store.getState()得到当前状态。如果使用的是 React,这时可以触发重新渲染 View。


function listerner() {
  let newState = store.getState();
  component.setState(newState);   
}

相关文章:

  • 2021-10-04
  • 2021-10-06
  • 2021-08-20
  • 2022-12-23
  • 2021-06-06
  • 2022-01-07
  • 2022-01-08
猜你喜欢
  • 2021-09-01
  • 2021-08-24
  • 2022-12-23
  • 2021-09-17
  • 2021-08-08
相关资源
相似解决方案