是否存在将redux状态绑定到对象的既定方法?将redux状态绑定到对象
我想要做这样的事情:
MyApi.setStore(myReduxStore, 'stateVar')
我已经打了通过各种的get/set操作和存储的听众,但它是一个烂摊子。
MyApi.getState =() => store.dispatch(getAction())
MyApi.setState = (state) => store.dispatch(setAction(state))
let currentState
store.subscribe(() => {
let previousState = currentState
currentState = store.getState().stateVar
if(previousState !== currentState) {
MyApi.stateListener(currentState)
}
})
你想达到什么目的? Redux状态已经是对象... – Andrey
我的API做一些异步的东西。我希望它能将它的状态暴露给redux,所以它可以在各种反应组件中找到。 – Simon
知道每个reducer都返回新状态,您可以创建将从您的API返回状态的reducer。 – Andrey