if (typeof producer !== "function") throw new Error("if first argument is not a function, the second argument to produce should be a function")
if (patchListener !== undefined && typeof patchListener !== "function") throw new Error("the third argument of a producer should not be set or a function")
}
// if state is a primitive, don't bother proxying at all
if (typeof baseState !== "object" || baseState === null) {
// avoid proxying anything except plain objects and arrays
if (!isProxyable(baseState)) {
const returnValue = producer(baseState)
return returnValue === undefined
? baseState
: normalizeResult(returnValue)
}
if (!isProxyable(baseState))
throw new Error(
`the first argument to an immer producer should be a primitive, plain object or array, got ${typeof baseState}: "${baseState}"`
)
return normalizeResult(
getUseProxies()
? produceProxy(baseState, producer, patchListener)
: produceEs5(baseState, producer, patchListener)