1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import type { Reducer } from 'redux' import { createSlice, PayloadAction, combineReducers } from '@reduxjs/toolkit' import a1Reducer, from './a1' import a2Reducer, from './a2' import combineSlices from './combinSlices'
const aReducer = combineReducers({ a1: a1Reducer, a2: a2Reducer })
export type AState = ReturnType<typeof aReducer>
export interface A { a: AState }
const initialState: A = { a: aReducer(undefined, { type: 'INIT' }) }
const aSlice = createSlice({ name: 'aSlice', initialState, reducers: {} })
const configSlice = createSlice({ name: 'configSlice', initialState, reducers: { updateConfig: (state, action: PayloadAction<Config>) => { return action.payload }, updateA: (state, action: PayloadAction<AState>) => { state.a = action.payload }, updatePartialA: (state, action: PayloadAction<Partial<ReturnType<typeof aReducer>>>) => { state.a = { ...state.a, ...action.payload } } } })
export const { updateConfig, updateA, updatePartialA } = configSlice.actions export default configSlice.reducer
const aCombine = combineSlices( aSlice.reducer, {}, { a1: a1Reducer, a2: a2Reducer } ) const aTop: Reducer<Config> = combineSlices( configSlice.reducer, {}, { a: aCombine } ) export { aCombine, aTop }
|