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