05.通过subscribe订阅,实现redux数据响应
const store = createStore(weight)
const watch = () => {
const cur = store.getState()
console.log(`stark wang 现在体重为${cur}斤`)
}
store.subscribe(watch)
// watch()
store.dispatch({type:'eat'})
store.dispatch({type:'eat'})
store.dispatch({type:'eat'})
store.dispatch({ type: 'hungry' })
通过 subscribe 订阅一个函数实现数据响应
store.subscribe(watch)