4
終極版文檔建議使用normalizr
設計的狀態是這樣的形狀:你可以使用組合減速器組成深層狀態減速器嗎?
{
entities: {
cards: {
42: {
id: 42,
text: 'Hello',
category: 2
},
43: {
id: 53,
text: 'There?',
category: 1
},
}
categories: {
1: {
id: 1,
name: 'Questions'
}
2: {
id: 2,
name: 'Greetings'
},
}
},
filter: 'SHOW_ALL',
allCardsList: {
isFetching: false,
items: [ 42, 43 ]
},
}
當然,這會分裂成三個組合的減速器(filter
,allThingsList
和entities
),但是,我會在我看來,想要爲entities.cards
和entities.categories
編寫單獨的縮減器。
是有辦法的實體的管理分成subreducers,將允許這樣的成分:
let rootReducer = combineReducers({
entities: {
things,
categories
},
filter,
allCardsList
});
是否有任何優勢,保持在entities
的cards
和categories
,而不是保持根目錄下(這將允許使用combineReducers
)?
{
cards: { ... },
categories: { ... },
filter: 'SHOW_ALL',
allCardsList: { ... }
}
現在看來很明顯,如果我想到'combineReducers'的實現。謝謝! – c10b10