Skip to content
Myr

fix: recursive produce call in async recipe

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

authored by aleclarson · committed by aleclarson · parent e266f4b · Browse files · 2 files+26 added−18 removed
This commit

State

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

Diff stats

2 files+26 added−18 removed

  • other:+26 added−18 removed

2 files+26 added−18 removed

modified:src/immer.js+22 added-18 removed
173 unmodified lines
174 if (this.onCopy) {175 this.onCopy(state)176 }177178 // Nested producers must never auto-freeze their result,179 // because it may contain drafts from parent producers.180 if (this.autoFreeze && !scope.parent) {178 // At this point, all descendants of `state.copy` have been finalized,179 // so we can be sure that `scope.canAutoFreeze` is accurate.180 if (this.autoFreeze && scope.canAutoFreeze) {181 Object.freeze(state.copy)182 }183184 if (path && scope.patches) {
10 unmodified lines
195 /**196 * @internal197 * Finalize all drafts in the given state tree.198 */199 finalizeTree(root, path, scope) {199 finalizeTree(root, rootPath, scope) {200 const state = root[DRAFT_STATE]201 if (state) {202 if (!this.useProxies) {203 state.finalizing = true
2 unmodified lines
206 }207 root = state.copy208 }209210 const {onAssign} = this210 const needPatches = !!rootPath && !!scope.patches211 const finalizeProperty = (prop, value, parent) => {212 if (value === parent) {213 throw Error("Immer forbids circular references")214 }215216 // The only possible draft (in the scope of a `finalizeTree` call) is the `root` object.217 const inDraft = !!state && parent === root216 // In the `finalizeTree` method, only the `root` object may be a draft.217 const isDraftProp = !!state && parent === root218219 if (isDraft(value)) {220 const needPatches =221 inDraft && path && scope.patches && !state.assigned[prop]220 const path =221 isDraftProp && needPatches && !state.assigned[prop]222 ? rootPath.concat(prop)223 : null224223 value = this.finalize(224 value,225 needPatches ? path.concat(prop) : null,226 scope227 )225 // Drafts owned by `scope` are finalized here.226 value = this.finalize(value, path, scope)227228 // Drafts from another scope must prevent auto-freezing.229 if (isDraft(value)) {230 scope.canAutoFreeze = false231 }232233 // Preserve non-enumerable properties.234 if (Array.isArray(parent) || isEnumerable(parent, prop)) {235 parent[prop] = value236 } else {237 Object.defineProperty(parent, prop, {value})238 }239240 // Unchanged drafts are never passed to the `onAssign` hook.237 if (inDraft && value === state.base[prop]) return241 if (isDraftProp && value === state.base[prop]) return242 }243 // Unchanged draft properties are ignored.240 else if (inDraft && is(value, state.base[prop])) {244 else if (isDraftProp && is(value, state.base[prop])) {245 return246 }247 // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.248 else if (isDraftable(value) && !Object.isFrozen(value)) {249 each(value, finalizeProperty)250 }251248 if (inDraft && onAssign) {249 onAssign(state, prop, value)252 if (isDraftProp && this.onAssign) {253 this.onAssign(state, prop, value)254 }255 }256257 each(root, finalizeProperty)
3 unmodified lines
modified:src/scope.js+4 added