2
我有以下的反应,终极版状态:Redux的状态更好的结构
{
response: {
json: [],
waitingForResponse: false,
communicationError: false,
searchButtonDisabled: true
},
routing: {
...
}
}
}
我想有一个状态更好的结构是这样的:
{
app: {
home: {
searchButtonDisabled: true
},
warning: {
waitingForResponse: false,
communicationError: false
},
rest: {
json: [],
httpStatus: 200
}
},
routing: ...
}
我想我需要与商店定义做一些魔术。我现在App.js文件看起来像这样
const store = createStore(
combineReducers({
response: reducer,
routing: routerReducer
}),
composeEnhancers(applyMiddleware(thunk))
);
是否有意义建立这个结构或者它只是让我的代码更复杂,没有任何额外的好处?
如果它不是一个好主意,然后我就可以在原有属性的名称前加上前缀部分:
{
response: {
restJson: [],
restHttpStatus: 200,
warningWaitingForResponse: false,
warningCommunicationError: false,
homeSearchButtonDisabled: true
},
routing: {
locationBeforeTransitions: {
pathname: '/hello/',
...
}
}
}
什么是建立一个更大的状态组件的最佳做法?
惊人的文档!谢谢克里斯。 – zappee
不用担心,所有功劳都归马克所有,他是一支枪 – Chris
呵呵,谢谢!很高兴看到我写的东西对人们有用:) – markerikson