react-redux工作原理
工作流程
- const store= createStore(fn)生成数据;
- action: {type: Symble('action01), payload:'payload' }定义行为;
- dispatch发起action:store.dispatch(doSomething('action001'));
- reducer:处理action,返回新的state;
通俗点解释:
1.view通过dispatch发出action
2.store自动调用reducer,传入state和收到的action,reducer返回新的state
3.state一旦有变化,store调用监听函数,更新view