Skip to content
Myr

Some additional comments, improvement in error handling

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

authored by Michel Weststrate · committed by aleclarson · parent e9f274e · Browse files · 3 files+12 added−5 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+12 added−5 removed

  • other:+12 added−5 removed

3 files+12 added−5 removed

modified:src/es5.js+2 added
9 unmodified lines
10 DRAFT_STATE11} from "./common"12import {ImmerScope} from "./scope"1314// property descriptors are recycled to make sure we don't create a get and set closure per property,15// but share them all instead16const descriptors = {}1718export function willFinalize(scope, result, isReplaced) {19 scope.drafts.forEach(draft => {
216 unmodified lines
modified:src/immer.js+6 added-4 removed
55 unmodified lines
56 // Only plain objects, arrays, and "immerable classes" are drafted.57 if (isDraftable(base)) {58 const scope = ImmerScope.enter()59 const baseDraft = this.createDraft(base)60 let hasError = true61 try {62 result = recipe.call(baseDraft, baseDraft)62 } catch (error) {63 scope.revoke()64 throw error63 hasError = false64 } finally {65 // finally instead of catch + rethrow better preserves original stack66 if (hasError) scope.revoke()67 else scope.leave()68 }66 scope.leave()69 if (result instanceof Promise) {70 return result.then(71 result => {72 scope.usePatches(patchListener)
190 unmodified lines
modified:src/proxy.js+4 added-1 removed