(reducers: {
[key: string]: Reducer<any, any, any>
})
| 121 | > |
| 122 | : never |
| 123 | export default function combineReducers(reducers: { |
| 124 | [key: string]: Reducer<any, any, any> |
| 125 | }) { |
| 126 | const reducerKeys = Object.keys(reducers) |
| 127 | const finalReducers: { [key: string]: Reducer<any, any, any> } = {} |
| 128 | for (let i = 0; i < reducerKeys.length; i++) { |
| 129 | const key = reducerKeys[i] |
| 130 | |
| 131 | if (process.env.NODE_ENV !== class="st">'production') { |
| 132 | if (typeof reducers[key] === class="st">'undefined') { |
| 133 | warning(`No reducer provided for key class="st">"${key}"`) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (typeof reducers[key] === class="st">'function') { |
| 138 | finalReducers[key] = reducers[key] |
| 139 | } |
| 140 | } |
| 141 | const finalReducerKeys = Object.keys(finalReducers) |
| 142 | |
| 143 | class="cm">// This is used to make sure we don't warn about the same |
| 144 | class="cm">// keys multiple times. |
| 145 | let unexpectedKeyCache: { [key: string]: true } |
| 146 | if (process.env.NODE_ENV !== class="st">'production') { |
| 147 | unexpectedKeyCache = {} |
| 148 | } |
| 149 | |
| 150 | let shapeAssertionError: unknown |
| 151 | try { |
| 152 | assertReducerShape(finalReducers) |
| 153 | } catch (e) { |
| 154 | shapeAssertionError = e |
| 155 | } |
| 156 | |
| 157 | return function combination( |
| 158 | state: StateFromReducersMapObject<typeof reducers> = {}, |
| 159 | action: Action |
| 160 | ) { |
| 161 | if (shapeAssertionError) { |
| 162 | throw shapeAssertionError |
| 163 | } |
| 164 | |
| 165 | if (process.env.NODE_ENV !== class="st">'production') { |
| 166 | const warningMessage = getUnexpectedStateShapeWarningMessage( |
| 167 | state, |
| 168 | finalReducers, |
| 169 | action, |
| 170 | unexpectedKeyCache |
| 171 | ) |
| 172 | if (warningMessage) { |
| 173 | warning(warningMessage) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | let hasChanged = false |
| 178 | const nextState: StateFromReducersMapObject<typeof reducers> = {} |
| 179 | for (let i = 0; i < finalReducerKeys.length; i++) { |
| 180 | const key = finalReducerKeys[i] |
no test coverage detected