Skip to content
Myr

proxy.js

This file

Path

src/proxy.js

428 lines · 11.9 KiB · JavaScript

Last changed by

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

History of this file

Take it

The walk stopped after 200 commits: lines older than 53e9ce8 point at it.

perf: proxy assignaleclarsonbefore adoption53e9ce8

lines 1–6why, one step back
1"use strict"
2import {3 assign,4 each,5 has,6 is,

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

lines 7–8why, one step back
7 isDraftable,
8 isDraft,

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 9why, one step back
9 isMap,

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

line 10why, one step back
10 isSet,

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 11why, one step back
11 shallowCopy,

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 12–15why, one step back
12 DRAFT_STATE,
13 assignMap,14 assignSet,15 original

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 16why, one step back
16} from "./common"

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

line 17why, one step back
17import {ImmerScope} from "./scope"

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 18why, one step back
18

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

lines 19–21why, one step back
19// Do nothing before being finalized.
20export function willFinalize() {}21

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 22–26why, one step back
22/**
23 * Returns a new draft of the `base` object.24 *25 * The second argument is the parent draft-state (used internally).26 */

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

lines 27–28why, one step back
27export function createProxy(base, parent) {
28 const scope = parent ? parent.scope : ImmerScope.current

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

line 29why, one step back
29 const state = {

feat: passing drafts to producealeclarsonbefore adoption9c53415

line 30why, one step back
30 // Track which produce call this is associated with.

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

line 31why, one step back
31 scope,

feat: passing drafts to producealeclarsonbefore adoption9c53415

lines 32–38why, one step back
32 // True for both shallow and deep changes.
33 modified: false,34 // Used during finalization.35 finalized: false,36 // Track which properties have been assigned (true) or deleted (false).37 assigned: {},38 // The parent draft state.

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

line 39why, one step back
39 parent,

feat: passing drafts to producealeclarsonbefore adoption9c53415

line 40why, one step back
40 // The base state.

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

line 41why, one step back
41 base,

feat: passing drafts to producealeclarsonbefore adoption9c53415

lines 42–46why, one step back
42 // The base proxy.
43 draft: null,44 // Any property proxies.45 drafts: {},46 // The base copy with any updated values.

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

line 47why, one step back
47 copy: null,

feat: passing drafts to producealeclarsonbefore adoption9c53415

lines 48–49why, one step back
48 // Called by the `produce` function.
49 revoke: null

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

lines 50–51why, one step back
50 }
51

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

lines 52–58why, one step back
52 let proxyTarget = state
53 let traps = objectTraps54 if (Array.isArray(base)) {55 proxyTarget = [state]56 traps = arrayTraps57 } else if (isMap(base)) {58 traps = mapTraps

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

lines 59–61why, one step back
59 // Maps need to support non-primitive keys and objects do not support other objects as keys
60 state.drafts = new Map()61 state.assigned = new Map()

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 62–65why, one step back
62 } else if (isSet(base)) {
63 traps = setTraps64 // We use values of a Set as keys and objects do not support other objects as keys65 state.drafts = new Map()

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

line 66why, one step back
66 // Sets do not need .assigned override since you cannot really assign (read as 'replace') any value in s Set. You can only add or remove values

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 67why, one step back
67 }

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

line 68why, one step back
68

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

lines 69–70why, one step back
69 const {revoke, proxy} = Proxy.revocable(proxyTarget, traps)
70

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

lines 71–73why, one step back
71 state.draft = proxy
72 state.revoke = revoke73

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

line 74why, one step back
74 scope.drafts.push(proxy)

feat: add `Immer` classaleclarsonbefore adoptionecd04dc

lines 75–77why, one step back
75 return proxy
76}77

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 78–81why, one step back
78/**
79 * Object drafts80 */81

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 82why, one step back
82const objectTraps = {

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 83–91why, one step back
83 get(state, prop) {
84 if (prop === DRAFT_STATE) return state85 let {drafts} = state8687 // Check for existing draft in unmodified state.88 if (!state.modified && has(drafts, prop)) {89 return drafts[prop]90 }91

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 92why, one step back
92 const value = latest(state)[prop]

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 93–106why, one step back
93 if (state.finalized || !isDraftable(value)) {
94 return value95 }9697 // Check for existing draft in modified state.98 if (state.modified) {99 // Assigned values are never drafted. This catches any drafts we created, too.100 if (value !== peek(state.base, prop)) return value101 // Store drafts on the copy (when one exists).102 drafts = state.copy103 }104105 return (drafts[prop] = createProxy(value, state))106 },

nit: argument namesAlec Larsonbefore adoptiona674a78

line 107why, one step back
107 has(state, prop) {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 108why, one step back
108 return prop in latest(state)

chore: reorganize src/proxy.jsAlec Larsonbefore adoptione809ffc

line 109why, one step back
109 },

nit: argument namesAlec Larsonbefore adoptiona674a78

line 110why, one step back
110 ownKeys(state) {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 111why, one step back
111 return Reflect.ownKeys(latest(state))

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 112why, one step back
112 },

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 113–140why, one step back
113 set(state, prop, value) {
114 if (!state.modified) {115 const baseValue = peek(state.base, prop)116 // Optimize based on value's truthiness. Truthy values are guaranteed to117 // never be undefined, so we can avoid the `in` operator. Lastly, truthy118 // values may be drafts, but falsy values are never drafts.119 const isUnchanged = value120 ? is(baseValue, value) || value === state.drafts[prop]121 : is(baseValue, value) && prop in state.base122 if (isUnchanged) return true123 markChanged(state)124 }125 state.assigned[prop] = true126 state.copy[prop] = value127 return true128 },129 deleteProperty(state, prop) {130 // The `undefined` check is a fast path for pre-existing keys.131 if (peek(state.base, prop) !== undefined || prop in state.base) {132 state.assigned[prop] = false133 markChanged(state)134 }135 if (state.copy) delete state.copy[prop]136 return true137 },138 // Note: We never coerce `desc.value` into an Immer draft, because we can't make139 // the same guarantee in ES5 mode.140 getOwnPropertyDescriptor(state, prop) {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 141why, one step back
141 const owner = latest(state)

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 142–148why, one step back
142 const desc = Reflect.getOwnPropertyDescriptor(owner, prop)
143 if (desc) {144 desc.writable = true145 desc.configurable = !Array.isArray(owner) || prop !== "length"146 }147 return desc148 },

feat: limited class supportaleclarsonbefore adoption9877d64

lines 149–151why, one step back
149 defineProperty() {
150 throw new Error("Object.defineProperty() cannot be used on an Immer draft") // prettier-ignore151 },

nit: argument namesAlec Larsonbefore adoptiona674a78

lines 152–153why, one step back
152 getPrototypeOf(state) {
153 return Object.getPrototypeOf(state.base)

fix: Object.getPrototypeOf with a draftaleclarsonbefore adoptiond5d07e8

line 154why, one step back
154 },

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 155why, one step back
155 setPrototypeOf() {

feat: limited class supportaleclarsonbefore adoption9877d64

line 156why, one step back
156 throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft") // prettier-ignore

perf: proxy assignaleclarsonbefore adoption53e9ce8

lines 157–159why, one step back
157 }
158}159

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 160–163why, one step back
160/**
161 * Array drafts162 */163

perf: proxy assignaleclarsonbefore adoption53e9ce8

lines 164–171why, one step back
164const arrayTraps = {}
165each(objectTraps, (key, fn) => {166 arrayTraps[key] = function() {167 arguments[0] = arguments[0][0]168 return fn.apply(this, arguments)169 }170})171arrayTraps.deleteProperty = function(state, prop) {

feat: limited class supportaleclarsonbefore adoption9877d64

lines 172–174why, one step back
172 if (isNaN(parseInt(prop))) {
173 throw new Error("Immer only supports deleting array indices") // prettier-ignore174 }

perf: proxy assignaleclarsonbefore adoption53e9ce8

lines 175–177why, one step back
175 return objectTraps.deleteProperty.call(this, state[0], prop)
176}177arrayTraps.set = function(state, prop, value) {

feat: limited class supportaleclarsonbefore adoption9877d64

lines 178–180why, one step back
178 if (prop !== "length" && isNaN(parseInt(prop))) {
179 throw new Error("Immer only supports setting array indices and the 'length' property") // prettier-ignore180 }

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 181why, one step back
181 return objectTraps.set.call(this, state[0], prop, value)

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

lines 182–183why, one step back
182}
183

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

lines 184–196why, one step back
184// Used by Map and Set drafts
185const reflectTraps = makeReflectTraps([186 "ownKeys",187 "has",188 "set",189 "deleteProperty",190 "defineProperty",191 "getOwnPropertyDescriptor",192 "preventExtensions",193 "isExtensible",194 "getPrototypeOf"195])196

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 197–200why, one step back
197/**
198 * Map drafts199 */200

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

line 201why, one step back
201const mapTraps = makeTrapsForGetters({

fix: add Map getter for DRAFT_STATE, make isEnumerable more resilientkeenondrumsbefore adoption7bbec0a

line 202why, one step back
202 [DRAFT_STATE]: state => state,

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

lines 203–204why, one step back
203 size: state => latest(state).size,
204 has: state => key => latest(state).has(key),

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

line 205why, one step back
205 set: state => (key, value) => {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

lines 206–207why, one step back
206 const values = latest(state)
207 if (!values.has(key) || values.get(key) !== value) {

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

line 208why, one step back
208 markChanged(state)

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

line 209why, one step back
209 state.assigned.set(key, true)

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 210–211why, one step back
210 state.copy.set(key, value)
211 }

fix: Map.prototype.set should return a draftAndrey Goncharovbefore adoption7001201

line 212why, one step back
212 return state.draft

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 213–214why, one step back
213 },
214 delete: state => key => {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 215why, one step back
215 if (latest(state).has(key)) {

feat: `onDelete` for `Maps`keenondrumsbefore adoption1ca49ef

lines 216–220why, one step back
216 markChanged(state)
217 state.assigned.set(key, false)218 return state.copy.delete(key)219 }220 return false

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 221–223why, one step back
221 },
222 clear: state => () => {223 markChanged(state)

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

line 224why, one step back
224 state.assigned = new Map()

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 225why, one step back
225 for (const key of latest(state).keys()) {

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

line 226why, one step back
226 state.assigned.set(key, false)

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 227why, one step back
227 }

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 228–230why, one step back
228 return state.copy.clear()
229 },230 forEach: (state, _, receiver) => (cb, thisArg) =>

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 231why, one step back
231 latest(state).forEach((_, key, map) => {

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 232–235why, one step back
232 const value = receiver.get(key)
233 cb.call(thisArg, value, key, map)234 }),235 get: state => key => {

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

lines 236–237why, one step back
236 if (!state.modified && state.drafts.has(key)) {
237 return state.drafts.get(key)

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 238why, one step back
238 }

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 239–241why, one step back
239
240 if (state.modified && state.copy.has(key)) {241 return state.copy.get(key)

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 242why, one step back
242 }

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

line 243why, one step back
243

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 244why, one step back
244 const value = latest(state).get(key)

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 245–247why, one step back
245
246 if (state.finalized || !isDraftable(value)) {247 return value

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

lines 248–249why, one step back
248 }
249

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

line 250why, one step back
250 const draft = createProxy(value, state)

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 251why, one step back
251

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

line 252why, one step back
252 if (!state.modified) {

feat: add support of non-primitive keys for `Maps`keenondrumsbefore adoption6501ec5

line 253why, one step back
253 state.drafts.set(key, draft)

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 254–256why, one step back
254 } else {
255 state.copy.set(key, draft)256 }

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 257why, one step back
257

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 258–259why, one step back
258 return draft
259 },

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 260why, one step back
260 keys: state => () => latest(state).keys(),

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 261–263why, one step back
261 values: iterateMapValues,
262 entries: iterateMapValues,263 [Symbol.iterator]: iterateMapValues

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

line 264why, one step back
264})

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 265why, one step back
265

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 266–270why, one step back
266/** Map.prototype.values _-or-_ Map.prototype.entries */
267function iterateMapValues(state, prop, receiver) {268 const getYieldable =269 prop === "values" ? (key, value) => value : (key, value) => [key, value]270

fix: remove "function*" syntaxAlec Larsonbefore adoption08d88b8

line 271why, one step back
271 return () => {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 272why, one step back
272 const iterator = latest(state)[Symbol.iterator]()

fix: remove "function*" syntaxAlec Larsonbefore adoption08d88b8

lines 273–281why, one step back
273 return makeIterable(() => {
274 const result = iterator.next()275 if (!result.done) {276 const [key] = result.value277 const value = receiver.get(key)278 result.value = getYieldable(key, value)279 }280 return result281 })

feat: `Map` drafts and patcheskeenondrumsbefore adoption30db0f3

line 282why, one step back
282 }

feat: `Map` supportkeenondrumsbefore adoption8276a6c

lines 283–284why, one step back
283}
284

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

line 285why, one step back
285/**

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 286–288why, one step back
286 * Set drafts
287 */288

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

line 289why, one step back
289const setTraps = makeTrapsForGetters({

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

line 290why, one step back
290 [DRAFT_STATE]: state => state,

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

lines 291–292why, one step back
291 size: state => latest(state).size,
292 has: state => key => latest(state).has(key),

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

line 293why, one step back
293 add: state => value => {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 294why, one step back
294 if (!latest(state).has(value)) {

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 295–319why, one step back
295 markChanged(state)
296 state.copy.add(value)297 }298 return state.draft299 },300 delete: state => value => {301 markChanged(state)302 return state.copy.delete(value)303 },304 clear: state => () => {305 markChanged(state)306 return state.copy.clear()307 },308 forEach: state => (cb, thisArg) => {309 const iterator = iterateSetValues(state)()310 let result = iterator.next()311 while (!result.done) {312 cb.call(thisArg, result.value, result.value, state.draft)313 result = iterator.next()314 }315 },316 keys: iterateSetValues,317 values: iterateSetValues,318 entries: iterateSetValues,319 [Symbol.iterator]: iterateSetValues

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

line 320why, one step back
320})

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 321–323why, one step back
321
322function iterateSetValues(state, prop) {323 return () => {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 324why, one step back
324 const iterator = latest(state)[Symbol.iterator]()

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 325–356why, one step back
325
326 return makeIterable(() => {327 const result = iterator.next()328 if (!result.done) {329 const valueWrapped = wrapSetValue(state, result.value)330 result.value = valueWrapped331 if (prop === "entries") {332 result.value = [valueWrapped, valueWrapped]333 }334 }335 return result336 })337 }338}339340function wrapSetValue(state, value) {341 const key = original(value) || value342 let draft = state.drafts.get(key)343 if (!draft) {344 if (state.finalized || !isDraftable(value)) {345 return value346 }347 draft = createProxy(value, state)348 state.drafts.set(key, draft)349 if (state.modified) {350 state.copy.add(draft)351 }352 }353 return draft354}355356/**

chore: reorganize src/proxy.jsAlec Larsonbefore adoption3163a7d

lines 357–359why, one step back
357 * Helpers
358 */359

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

lines 360–361why, one step back
360// Retrieve the latest values of the draft.
361function latest(state) {

fix: revert Map supportAlec Larsonbefore adoption47529d3

lines 362–363why, one step back
362 return state.copy || state.base
363}

chore: reorganize src/proxy.jsAlec Larsonbefore adoptione809ffc

line 364why, one step back
364

fix: revert Map supportAlec Larsonbefore adoption47529d3

lines 365–368why, one step back
365// Access a property without creating an Immer draft.
366function peek(draft, prop) {367 const state = draft[DRAFT_STATE]368 const desc = Reflect.getOwnPropertyDescriptor(

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 369why, one step back
369 state ? latest(state) : draft,

fix: revert Map supportAlec Larsonbefore adoption47529d3

lines 370–372why, one step back
370 prop
371 )372 return desc && desc.value

perf: proxy assignaleclarsonbefore adoption53e9ce8

lines 373–377why, one step back
373}
374375function markChanged(state) {376 if (!state.modified) {377 state.modified = true

refactor: markChanged functionAlec Larsonbefore adoption5857d63

lines 378–389why, one step back
378
379 const {base, drafts, parent} = state380 const copy = shallowCopy(base)381382 if (isSet(base)) {383 // Note: The `drafts` property is preserved for Set objects, since384 // we need to keep track of which values are drafted.385 assignSet(copy, drafts)386 } else {387 // Merge nested drafts into the copy.388 if (isMap(base)) assignMap(copy, drafts)389 else assign(copy, drafts)

feat: `Set` draftsAndrey Goncharovbefore adoption4355b63

lines 390–391why, one step back
390 state.drafts = null
391 }

refactor: markChanged functionAlec Larsonbefore adoption5857d63

lines 392–396why, one step back
392
393 state.copy = copy394 if (parent) {395 markChanged(parent)396 }

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 397why, one step back
397 }

fix: remove "function*" syntaxAlec Larsonbefore adoption08d88b8

lines 398–405why, one step back
398}
399400function makeIterable(next) {401 let self402 return (self = {403 [Symbol.iterator]: () => self,404 next405 })

refactor: traps for Maps and Setskeenondrumsbefore adoptiondd82d89

lines 406–407why, one step back
406}
407

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 408why, one step back
408/** Create traps that all use the `Reflect` API on the `latest(state)` */

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

lines 409–410why, one step back
409function makeReflectTraps(names) {
410 return names.reduce((traps, name) => {

refactor: rename "source" helper to "latest"Alec Larsonbefore adoptioneba300f

line 411why, one step back
411 traps[name] = (state, ...args) => Reflect[name](latest(state), ...args)

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

lines 412–415why, one step back
412 return traps
413 }, {})414}415

refactor: traps for Maps and Setskeenondrumsbefore adoptiondd82d89

lines 416–417why, one step back
416function makeTrapsForGetters(getters) {
417 return {

refactor: makeTrapsForGetters functionAlec Larsonbefore adoption5093fd0

line 418why, one step back
418 ...reflectTraps,

refactor: traps for Maps and Setskeenondrumsbefore adoptiondd82d89

lines 419–422why, one step back
419 get(state, prop, receiver) {
420 return getters.hasOwnProperty(prop)421 ? getters[prop](state, prop, receiver)422 : Reflect.get(state, prop, receiver)

fix: add more traps for Maps and SetsAndrey Goncharovbefore adoption930b4ab

lines 423–425why, one step back
423 },
424 setPrototypeOf(state) {425 throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft") // prettier-ignore

refactor: traps for Maps and Setskeenondrumsbefore adoptiondd82d89

lines 426–427why, one step back
426 }
427 }

perf: proxy assignaleclarsonbefore adoption53e9ce8

line 428why, one step back
428}