(reducers: {
[key: string]: Reducer<any, any, any>
})
| 60 | } |
| 61 | |
| 62 | function assertReducerShape(reducers: { |
| 63 | [key: string]: Reducer<any, any, any> |
| 64 | }) { |
| 65 | Object.keys(reducers).forEach(key => { |
| 66 | const reducer = reducers[key] |
| 67 | const initialState = reducer(undefined, { type: ActionTypes.INIT }) |
| 68 | |
| 69 | if (typeof initialState === 'undefined') { |
| 70 | throw new Error( |
| 71 | `The slice reducer for key "${key}" returned undefined during initialization. ` + |
| 72 | `If the state passed to the reducer is undefined, you must ` + |
| 73 | `explicitly return the initial state. The initial state may ` + |
| 74 | `not be undefined. If you don't want to set a value for this reducer, ` + |
| 75 | `you can use null instead of undefined.` |
| 76 | ) |
| 77 | } |
| 78 | |
| 79 | if ( |
| 80 | typeof reducer(undefined, { |
| 81 | type: ActionTypes.PROBE_UNKNOWN_ACTION() |
| 82 | }) === 'undefined' |
| 83 | ) { |
| 84 | throw new Error( |
| 85 | `The slice reducer for key "${key}" returned undefined when probed with a random type. ` + |
| 86 | `Don't try to handle '${ActionTypes.INIT}' or other actions in "redux/*" ` + |
| 87 | `namespace. They are considered private. Instead, you must return the ` + |
| 88 | `current state for any unknown actions, unless it is undefined, ` + |
| 89 | `in which case you must return the initial state, regardless of the ` + |
| 90 | `action type. The initial state may not be undefined, but can be null.` |
| 91 | ) |
| 92 | } |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Turns an object whose values are different reducer functions, into a single |
no test coverage detected