MCPcopy
hub / github.com/reduxjs/redux / combineReducers

Function combineReducers

src/combineReducers.ts:123–201  ·  src/combineReducers.ts::combineReducers
(reducers: {
  [key: string]: Reducer<any, any, any>
})

Source from the content-addressed store, hash-verified

121 >
122 : never
123export 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]

Callers 14

store.tsFile · 0.85
simpleFunction · 0.85
discriminatedFunction · 0.85
typeGuardsFunction · 0.85
index.jsFile · 0.85
index.jsFile · 0.85
index.jsFile · 0.85
index.jsFile · 0.85
index.jsFile · 0.85
index.jsFile · 0.85

Calls 4

warningFunction · 0.85
assertReducerShapeFunction · 0.85
reducerFunction · 0.50

Tested by

no test coverage detected