Skip to content
Myr

nit: dedupe some code

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by aleclarson · committed by aleclarson · parent d83f4b5 · Browse files · 3 files+11 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+11 added−16 removed

  • other:+11 added−16 removed

3 files+11 added−16 removed

modified:src/es5.js-6 removed
2 unmodified lines
34import {5 is,6 isProxyable,7 isProxy,7 PROXY_STATE,8 shallowCopy,9 RETURNED_AND_MODIFIED_ERROR,10 has,
193 unmodified lines
204 return false205}206207export function produceEs5(baseState, producer, patchListener) {209 if (isProxy(baseState)) {210 // See #100, don't nest producers211 const returnValue = producer.call(baseState, baseState)212 return returnValue === undefined ? baseState : returnValue213 }208 const prevStates = states209 states = []210 const patches = patchListener && []211 const inversePatches = patchListener && []
43 unmodified lines
modified:src/immer.js+9 added-1 removed
modified:src/proxy.js+2 added-9 removed
149 unmodified lines
150 return proxy.proxy151}152153export function produceProxy(baseState, producer, patchListener) {154 if (isProxy(baseState)) {155 // See #100, don't nest producers156 const returnValue = producer.call(baseState, baseState)157 return returnValue === undefined ? baseState : returnValue158 }154 const previousProxies = proxies155 proxies = []156 const patches = patchListener && []157 const inversePatches = patchListener && []158 try {159 // create proxy for root160 const rootProxy = createProxy(undefined, baseState)166 // execute the thunk161 // execute the producer function162 const returnValue = producer.call(rootProxy, rootProxy)163 // and finalize the modified proxy164 let result165 // check whether the draft was modified and/or a value was returned
1 unmodified line
167 // something was returned, and it wasn't the proxy itself168 if (rootProxy[PROXY_STATE].modified)169 throw new Error(RETURNED_AND_MODIFIED_ERROR)170176 // See #117177 // Should we just throw when returning a proxy which is not the root, but a subset of the original state?178 // Looks like a wrongly modeled reducer171 // we need to finalize the return value in case it's a subset of the draft172 result = finalize(returnValue)173 if (patches) {174 patches.push({op: "replace", path: [], value: result})175 inversePatches.push({op: "replace", path: [], value: baseState})
12 unmodified lines