如果看不清楚,可以查看https://segmentfault.com/a/1190000018394259
import { ActionTypes } from './createStore'
import isPlainObject from 'lodash/isPlainObject'
import warning from './utils/warning'
/**
* ActionTypes 是这个
* export const ActionTypes = {
* INIT: '@@redux/INIT'
* }
*/
function getUndefinedStateErrorMessage(key, action) { //函数名翻译为获取未定义的state错误信息
const actionType = action && action.type
const actionName = (actionType && `"${actionType.toString()}"`) || 'an action'
return (
`Given action ${actionName}, reducer "${key}" returned undefined. ` +
`To ignore an action, you must explicitly return the previous state. ` +
`If you want this reducer to hold no value, you can return null instead of undefined.`
)
//对于action xxx ,reducer yyy 返回undefined
//一定要很明确的返回之前的state,这样就可以忽略一个action
//如果你想这个reducer没有返回值,你可以返回null而不是undefined
}
//获取与预期不符的state的结构警告信息
function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
const reducerKeys = Object.keys(reducers)
const argumentName = action && action.type === ActionTypes.INIT ?
'preloadedState argument passed to createStore' :
'previous state received by the reducer'
if (reducerKeys.length === 0) {
return (
'Store does not have a valid reducer. Make sure the argument passed ' +
'to combineReducers is an object whose values are reducers.'
)
}
if (!isPlainObject(inputState)) {
return (
`The ${argumentName} has unexpected type of "` +