Skip to content
Myr

fix(es5): onDelete hook

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

The `assigned` map cannot be trusted in es5, because of perf optimizations when a patch listener is not used.

authored by aleclarson · committed by Alec Larson · parent 5ff645c · Browse files · 1 file+13 added−3 removed
This commit

State

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

Diff stats

1 file+13 added−3 removed

  • other:+13 added−3 removed

1 file+13 added−3 removed

modified:src/immer.js+13 added-3 removed
2 unmodified lines
3import {generatePatches} from "./patches"4import {5 assign,6 each,7 has,8 is,9 isDraft,10 isDraftable,11 shallowCopy,
123 unmodified lines
135 if (!state.finalized) {136 state.finalized = true137 this.finalizeTree(state.draft, path, patches, inversePatches)138 if (this.onDelete) {139 // The `assigned` object is unreliable with ES5 drafts.140 if (this.useProxies) {138 const {assigned} = state139 for (const prop in assigned)140 assigned[prop] || this.onDelete(state, prop)141 const {assigned} = state142 for (const prop in assigned) {143 if (!assigned[prop]) this.onDelete(state, prop)144 }145 } else {146 const {base, copy} = state147 eachOwn(base, prop => {148 if (!has(copy, prop)) this.onDelete(state, prop)149 })150 }151 }152 if (this.onCopy) this.onCopy(state)153154 // Nested producers must never auto-freeze their result,
68 unmodified lines