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

Function getUnexpectedStateShapeWarningMessage

src/combineReducers.ts:14–60  ·  src/combineReducers.ts::getUnexpectedStateShapeWarningMessage
(
  inputState: object,
  reducers: { [key: string]: Reducer<any, any, any> },
  action: Action,
  unexpectedKeyCache: { [key: string]: true }
)

Source from the content-addressed store, hash-verified

12import { kindOf } from class="st">'./utils/kindOf'
13
14function getUnexpectedStateShapeWarningMessage(
15 inputState: object,
16 reducers: { [key: string]: Reducer<any, any, any> },
17 action: Action,
18 unexpectedKeyCache: { [key: string]: true }
19) {
20 const reducerKeys = Object.keys(reducers)
21 const argumentName =
22 action && action.type === ActionTypes.INIT
23 ? class="st">'preloadedState argument passed to createStore'
24 : class="st">'previous state received by the reducer'
25
26 if (reducerKeys.length === 0) {
27 return (
28 class="st">'Store does not have a valid reducer. Make sure the argument passed ' +
29 class="st">'to combineReducers is an object whose values are reducers.'
30 )
31 }
32
33 if (!isPlainObject(inputState)) {
34 return (
35 `The ${argumentName} has unexpected type of "${kindOf(
36 inputState
37 )}". Expected argument to be an object with the following ` +
38 `keys: class="st">"${reducerKeys.join('", class="st">"')}"`
39 )
40 }
41
42 const unexpectedKeys = Object.keys(inputState).filter(
43 key => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]
44 )
45
46 unexpectedKeys.forEach(key => {
47 unexpectedKeyCache[key] = true
48 })
49
50 if (action && action.type === ActionTypes.REPLACE) return
51
52 if (unexpectedKeys.length > 0) {
53 return (
54 `Unexpected ${unexpectedKeys.length > 1 ? class="st">'keys' : class="st">'key'} ` +
55 `class="st">"${unexpectedKeys.join('", class="st">"')}" found in ${argumentName}. ` +
56 `Expected to find one of the known reducer keys instead: ` +
57 `class="st">"${reducerKeys.join('", class="st">"')}". Unexpected keys will be ignored.`
58 )
59 }
60}
61
62function assertReducerShape(reducers: {
63 [key: string]: Reducer<any, any, any>

Callers 1

combineReducersFunction · 0.85

Calls 2

kindOfFunction · 0.90
isPlainObjectFunction · 0.85

Tested by

no test coverage detected