@vve/immer 9.0.0-alpha.3 → 9.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/umd/index.js ADDED
@@ -0,0 +1,1134 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["VveImmer"] = factory();
8
+ else
9
+ root["VveImmer"] = factory();
10
+ })(self, () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ var __webpack_modules__ = ({
13
+
14
+ /***/ 376:
15
+ /***/ ((module) => {
16
+
17
+ var __dirname = "/";
18
+ (function(){var e={952:function(e){var t=e.exports={};var r;var n;function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}(function(){try{if(typeof setTimeout==="function"){r=setTimeout}else{r=defaultSetTimout}}catch(e){r=defaultSetTimout}try{if(typeof clearTimeout==="function"){n=clearTimeout}else{n=defaultClearTimeout}}catch(e){n=defaultClearTimeout}})();function runTimeout(e){if(r===setTimeout){return setTimeout(e,0)}if((r===defaultSetTimout||!r)&&setTimeout){r=setTimeout;return setTimeout(e,0)}try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}function runClearTimeout(e){if(n===clearTimeout){return clearTimeout(e)}if((n===defaultClearTimeout||!n)&&clearTimeout){n=clearTimeout;return clearTimeout(e)}try{return n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}var i=[];var o=false;var u;var a=-1;function cleanUpNextTick(){if(!o||!u){return}o=false;if(u.length){i=u.concat(i)}else{a=-1}if(i.length){drainQueue()}}function drainQueue(){if(o){return}var e=runTimeout(cleanUpNextTick);o=true;var t=i.length;while(t){u=i;i=[];while(++a<t){if(u){u[a].run()}}a=-1;t=i.length}u=null;o=false;runClearTimeout(e)}t.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1){for(var r=1;r<arguments.length;r++){t[r-1]=arguments[r]}}i.push(new Item(e,t));if(i.length===1&&!o){runTimeout(drainQueue)}};function Item(e,t){this.fun=e;this.array=t}Item.prototype.run=function(){this.fun.apply(null,this.array)};t.title="browser";t.browser=true;t.env={};t.argv=[];t.version="";t.versions={};function noop(){}t.on=noop;t.addListener=noop;t.once=noop;t.off=noop;t.removeListener=noop;t.removeAllListeners=noop;t.emit=noop;t.prependListener=noop;t.prependOnceListener=noop;t.listeners=function(e){return[]};t.binding=function(e){throw new Error("process.binding is not supported")};t.cwd=function(){return"/"};t.chdir=function(e){throw new Error("process.chdir is not supported")};t.umask=function(){return 0}}};var t={};function __nccwpck_require__(r){var n=t[r];if(n!==undefined){return n.exports}var i=t[r]={exports:{}};var o=true;try{e[r](i,i.exports,__nccwpck_require__);o=false}finally{if(o)delete t[r]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(952);module.exports=r})();
19
+
20
+ /***/ })
21
+
22
+ /******/ });
23
+ /************************************************************************/
24
+ /******/ // The module cache
25
+ /******/ var __webpack_module_cache__ = {};
26
+ /******/
27
+ /******/ // The require function
28
+ /******/ function __webpack_require__(moduleId) {
29
+ /******/ // Check if module is in cache
30
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
31
+ /******/ if (cachedModule !== undefined) {
32
+ /******/ return cachedModule.exports;
33
+ /******/ }
34
+ /******/ // Create a new module (and put it into the cache)
35
+ /******/ var module = __webpack_module_cache__[moduleId] = {
36
+ /******/ // no module.id needed
37
+ /******/ // no module.loaded needed
38
+ /******/ exports: {}
39
+ /******/ };
40
+ /******/
41
+ /******/ // Execute the module function
42
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
43
+ /******/
44
+ /******/ // Return the exports of the module
45
+ /******/ return module.exports;
46
+ /******/ }
47
+ /******/
48
+ /************************************************************************/
49
+ /******/ /* webpack/runtime/define property getters */
50
+ /******/ (() => {
51
+ /******/ // define getter functions for harmony exports
52
+ /******/ __webpack_require__.d = (exports, definition) => {
53
+ /******/ for(var key in definition) {
54
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
55
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
56
+ /******/ }
57
+ /******/ }
58
+ /******/ };
59
+ /******/ })();
60
+ /******/
61
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
62
+ /******/ (() => {
63
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
64
+ /******/ })();
65
+ /******/
66
+ /******/ /* webpack/runtime/make namespace object */
67
+ /******/ (() => {
68
+ /******/ // define __esModule on exports
69
+ /******/ __webpack_require__.r = (exports) => {
70
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
71
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
72
+ /******/ }
73
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
74
+ /******/ };
75
+ /******/ })();
76
+ /******/
77
+ /************************************************************************/
78
+ var __webpack_exports__ = {};
79
+ // This entry need to be wrapped in an IIFE because it need to be in strict mode.
80
+ (() => {
81
+ "use strict";
82
+ // ESM COMPAT FLAG
83
+ __webpack_require__.r(__webpack_exports__);
84
+
85
+ // EXPORTS
86
+ __webpack_require__.d(__webpack_exports__, {
87
+ DRAFT_STATE: () => (/* reexport */ DRAFT_STATE),
88
+ Immer: () => (/* reexport */ Immer),
89
+ applyPatches: () => (/* binding */ src_applyPatches),
90
+ createDraft: () => (/* binding */ createDraft),
91
+ "default": () => (/* binding */ src),
92
+ finishDraft: () => (/* binding */ finishDraft),
93
+ immerable: () => (/* reexport */ DRAFTABLE),
94
+ isDraft: () => (/* reexport */ isDraft),
95
+ isDraftable: () => (/* reexport */ isDraftable),
96
+ nothing: () => (/* reexport */ NOTHING),
97
+ original: () => (/* reexport */ original),
98
+ produce: () => (/* binding */ produce),
99
+ setAutoFreeze: () => (/* binding */ setAutoFreeze),
100
+ setUseProxies: () => (/* binding */ setUseProxies)
101
+ });
102
+
103
+ // NAMESPACE OBJECT: ./src/es5.js
104
+ var es5_namespaceObject = {};
105
+ __webpack_require__.r(es5_namespaceObject);
106
+ __webpack_require__.d(es5_namespaceObject, {
107
+ createProxy: () => (createProxy),
108
+ willFinalize: () => (willFinalize)
109
+ });
110
+
111
+ // NAMESPACE OBJECT: ./src/proxy.js
112
+ var proxy_namespaceObject = {};
113
+ __webpack_require__.r(proxy_namespaceObject);
114
+ __webpack_require__.d(proxy_namespaceObject, {
115
+ createProxy: () => (proxy_createProxy),
116
+ willFinalize: () => (proxy_willFinalize)
117
+ });
118
+
119
+ ;// CONCATENATED MODULE: ./src/common.js
120
+ var NOTHING = typeof Symbol !== "undefined" ? Symbol("immer-nothing") : {
121
+ ["immer-nothing"]: true
122
+ };
123
+ var DRAFTABLE = typeof Symbol !== "undefined" && Symbol.for ? Symbol.for("immer-draftable") : "__$immer_draftable";
124
+ var DRAFT_STATE = typeof Symbol !== "undefined" && Symbol.for ? Symbol.for("immer-state") : "__$immer_state";
125
+ function isDraft(value) {
126
+ return !!value && !!value[DRAFT_STATE];
127
+ }
128
+ function isDraftable(value) {
129
+ if (!value || typeof value !== "object") return false;
130
+ if (Array.isArray(value)) return true;
131
+ var proto = Object.getPrototypeOf(value);
132
+ if (!proto || proto === Object.prototype) return true;
133
+ return !!value[DRAFTABLE] || !!value.constructor[DRAFTABLE];
134
+ }
135
+ function original(value) {
136
+ if (value && value[DRAFT_STATE]) {
137
+ return value[DRAFT_STATE].base;
138
+ }
139
+ // otherwise return undefined
140
+ }
141
+
142
+ var common_assign = Object.assign || function assign(target, value) {
143
+ for (var key in value) {
144
+ if (has(value, key)) {
145
+ target[key] = value[key];
146
+ }
147
+ }
148
+ return target;
149
+ };
150
+ var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? obj => Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)) : Object.getOwnPropertyNames;
151
+ function shallowCopy(base) {
152
+ var invokeGetters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
153
+ if (Array.isArray(base)) return base.slice();
154
+ var clone = Object.create(Object.getPrototypeOf(base));
155
+ ownKeys(base).forEach(key => {
156
+ if (key === DRAFT_STATE) {
157
+ return; // Never copy over draft state.
158
+ }
159
+
160
+ var desc = Object.getOwnPropertyDescriptor(base, key);
161
+ var value = desc.value;
162
+ if (desc.get) {
163
+ if (!invokeGetters) {
164
+ throw new Error("Immer drafts cannot have computed properties");
165
+ }
166
+ value = desc.get.call(base);
167
+ }
168
+ if (desc.enumerable) {
169
+ clone[key] = value;
170
+ } else {
171
+ Object.defineProperty(clone, key, {
172
+ value,
173
+ writable: true,
174
+ configurable: true
175
+ });
176
+ }
177
+ });
178
+ return clone;
179
+ }
180
+ function each(value, cb) {
181
+ if (Array.isArray(value)) {
182
+ for (var i = 0; i < value.length; i++) cb(i, value[i], value);
183
+ } else {
184
+ ownKeys(value).forEach(key => cb(key, value[key], value));
185
+ }
186
+ }
187
+ function isEnumerable(base, prop) {
188
+ var desc = Object.getOwnPropertyDescriptor(base, prop);
189
+ return !!desc && desc.enumerable;
190
+ }
191
+ function has(thing, prop) {
192
+ return Object.prototype.hasOwnProperty.call(thing, prop);
193
+ }
194
+ function is(x, y) {
195
+ // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
196
+ if (x === y) {
197
+ return x !== 0 || 1 / x === 1 / y;
198
+ } else {
199
+ return x !== x && y !== y;
200
+ }
201
+ }
202
+ ;// CONCATENATED MODULE: ./src/scope.js
203
+
204
+
205
+ /** Each scope represents a `produce` call. */
206
+ class ImmerScope {
207
+ constructor(parent) {
208
+ this.drafts = [];
209
+ this.parent = parent;
210
+
211
+ // Whenever the modified draft contains a draft from another scope, we
212
+ // need to prevent auto-freezing so the unowned draft can be finalized.
213
+ this.canAutoFreeze = true;
214
+
215
+ // To avoid prototype lookups:
216
+ this.patches = null;
217
+ }
218
+ usePatches(patchListener) {
219
+ if (patchListener) {
220
+ this.patches = [];
221
+ this.inversePatches = [];
222
+ this.patchListener = patchListener;
223
+ }
224
+ }
225
+ revoke(keepAlive) {
226
+ this.leave();
227
+ keepAlive || this.drafts.forEach(revoke);
228
+ this.drafts = null; // Make draft-related methods throw.
229
+ }
230
+
231
+ leave() {
232
+ if (this === ImmerScope.current) {
233
+ ImmerScope.current = this.parent;
234
+ }
235
+ }
236
+ }
237
+ ImmerScope.current = null;
238
+ ImmerScope.enter = function () {
239
+ return this.current = new ImmerScope(this.current);
240
+ };
241
+ function revoke(draft) {
242
+ draft[DRAFT_STATE].revoke();
243
+ }
244
+ ;// CONCATENATED MODULE: ./src/es5.js
245
+
246
+
247
+
248
+
249
+
250
+ // property descriptors are recycled to make sure we don't create a get and set closure per property,
251
+ // but share them all instead
252
+ var descriptors = {};
253
+ var noop = () => {};
254
+ function willFinalize(scope, result, isReplaced) {
255
+ scope.drafts.forEach(draft => {
256
+ draft[DRAFT_STATE].finalizing = true;
257
+ });
258
+ if (!isReplaced) {
259
+ if (scope.patches) {
260
+ markChangesRecursively(scope.drafts[0]);
261
+ }
262
+ // This is faster when we don't care about which attributes changed.
263
+ markChangesSweep(scope.drafts);
264
+ }
265
+ // When a child draft is returned, look for changes.
266
+ else if (isDraft(result) && result[DRAFT_STATE].scope === scope) {
267
+ markChangesSweep(scope.drafts);
268
+ }
269
+ }
270
+ function createProxy(base, parent) {
271
+ var isArray = Array.isArray(base);
272
+ var draft = clonePotentialDraft(base);
273
+ each(draft, prop => {
274
+ proxyProperty(draft, prop, isArray || isEnumerable(base, prop));
275
+ });
276
+
277
+ // See "proxy.js" for property documentation.
278
+ var scope = parent ? parent.scope : ImmerScope.current;
279
+ var state = {
280
+ scope,
281
+ modified: false,
282
+ finalizing: false,
283
+ // es5 only
284
+ finalized: false,
285
+ assigned: {},
286
+ parent,
287
+ base,
288
+ draft,
289
+ copy: null,
290
+ revoke: es5_revoke,
291
+ revoked: false // es5 only
292
+ };
293
+
294
+ createHiddenProperty(draft, DRAFT_STATE, state);
295
+ scope.drafts.push(draft);
296
+ return draft;
297
+ }
298
+ function es5_revoke() {
299
+ this.revoked = true;
300
+ }
301
+ function source(state) {
302
+ return state.copy || state.base;
303
+ }
304
+
305
+ // Access a property without creating an Immer draft.
306
+ function peek(draft, prop) {
307
+ var state = draft[DRAFT_STATE];
308
+ if (state && !state.finalizing) {
309
+ state.finalizing = true;
310
+ var value = draft[prop];
311
+ state.finalizing = false;
312
+ return value;
313
+ }
314
+ return draft[prop];
315
+ }
316
+ function get(state, prop) {
317
+ assertUnrevoked(state);
318
+ var value = peek(source(state), prop);
319
+ if (state.finalizing) return value;
320
+ // Create a draft if the value is unmodified.
321
+ if (value === peek(state.base, prop) && isDraftable(value)) {
322
+ prepareCopy(state);
323
+ return state.copy[prop] = createProxy(value, state);
324
+ }
325
+ return value;
326
+ }
327
+ function set(state, prop, value) {
328
+ assertUnrevoked(state);
329
+ state.assigned[prop] = true;
330
+ if (!state.modified) {
331
+ if (is(value, peek(source(state), prop))) return;
332
+ markChanged(state);
333
+ prepareCopy(state);
334
+ }
335
+ state.copy[prop] = value;
336
+ }
337
+ function markChanged(state) {
338
+ if (!state.modified) {
339
+ state.modified = true;
340
+ if (state.parent) markChanged(state.parent);
341
+ }
342
+ }
343
+ function prepareCopy(state) {
344
+ if (!state.copy) state.copy = clonePotentialDraft(state.base);
345
+ }
346
+ function clonePotentialDraft(base) {
347
+ var state = base && base[DRAFT_STATE];
348
+ if (state) {
349
+ state.finalizing = true;
350
+ var draft = shallowCopy(state.draft, true);
351
+ state.finalizing = false;
352
+ return draft;
353
+ }
354
+ return shallowCopy(base);
355
+ }
356
+ function proxyProperty(draft, prop, enumerable) {
357
+ var desc = descriptors[prop];
358
+ if (desc) {
359
+ desc.enumerable = enumerable;
360
+ } else {
361
+ descriptors[prop] = desc = {
362
+ configurable: true,
363
+ enumerable,
364
+ get() {
365
+ return get(this[DRAFT_STATE], prop);
366
+ },
367
+ set(value) {
368
+ set(this[DRAFT_STATE], prop, value);
369
+ }
370
+ };
371
+ }
372
+ Object.defineProperty(draft, prop, desc);
373
+ }
374
+ function assertUnrevoked(state) {
375
+ if (state.revoked === true) throw new Error("Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + JSON.stringify(source(state)));
376
+ }
377
+
378
+ // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
379
+ function markChangesSweep(drafts) {
380
+ // The natural order of drafts in the `scope` array is based on when they
381
+ // were accessed. By processing drafts in reverse natural order, we have a
382
+ // better chance of processing leaf nodes first. When a leaf node is known to
383
+ // have changed, we can avoid any traversal of its ancestor nodes.
384
+ for (var i = drafts.length - 1; i >= 0; i--) {
385
+ var state = drafts[i][DRAFT_STATE];
386
+ if (!state.modified) {
387
+ if (Array.isArray(state.base)) {
388
+ if (hasArrayChanges(state)) markChanged(state);
389
+ } else if (hasObjectChanges(state)) markChanged(state);
390
+ }
391
+ }
392
+ }
393
+ function markChangesRecursively(object) {
394
+ if (!object || typeof object !== "object") return;
395
+ var state = object[DRAFT_STATE];
396
+ if (!state) return;
397
+ var base = state.base,
398
+ draft = state.draft,
399
+ assigned = state.assigned;
400
+ if (!Array.isArray(object)) {
401
+ // Look for added keys.
402
+ Object.keys(draft).forEach(key => {
403
+ // The `undefined` check is a fast path for pre-existing keys.
404
+ if (base[key] === undefined && !has(base, key)) {
405
+ assigned[key] = true;
406
+ markChanged(state);
407
+ } else if (!assigned[key]) {
408
+ // Only untouched properties trigger recursion.
409
+ markChangesRecursively(draft[key]);
410
+ }
411
+ });
412
+ // Look for removed keys.
413
+ Object.keys(base).forEach(key => {
414
+ // The `undefined` check is a fast path for pre-existing keys.
415
+ if (draft[key] === undefined && !has(draft, key)) {
416
+ assigned[key] = false;
417
+ markChanged(state);
418
+ }
419
+ });
420
+ } else if (hasArrayChanges(state)) {
421
+ markChanged(state);
422
+ assigned.length = true;
423
+ if (draft.length < base.length) {
424
+ for (var i = draft.length; i < base.length; i++) assigned[i] = false;
425
+ } else {
426
+ for (var _i = base.length; _i < draft.length; _i++) assigned[_i] = true;
427
+ }
428
+ for (var _i2 = 0; _i2 < draft.length; _i2++) {
429
+ // Only untouched indices trigger recursion.
430
+ if (assigned[_i2] === undefined) markChangesRecursively(draft[_i2]);
431
+ }
432
+ }
433
+ }
434
+ function hasObjectChanges(state) {
435
+ var base = state.base,
436
+ draft = state.draft;
437
+
438
+ // Search for added keys and changed keys. Start at the back, because
439
+ // non-numeric keys are ordered by time of definition on the object.
440
+ var keys = Object.keys(draft);
441
+ for (var i = keys.length - 1; i >= 0; i--) {
442
+ var key = keys[i];
443
+ var baseValue = base[key];
444
+ // The `undefined` check is a fast path for pre-existing keys.
445
+ if (baseValue === undefined && !has(base, key)) {
446
+ return true;
447
+ }
448
+ // Once a base key is deleted, future changes go undetected, because its
449
+ // descriptor is erased. This branch detects any missed changes.
450
+ else {
451
+ var value = draft[key];
452
+ var _state = value && value[DRAFT_STATE];
453
+ if (_state ? _state.base !== baseValue : !is(value, baseValue)) {
454
+ return true;
455
+ }
456
+ }
457
+ }
458
+
459
+ // At this point, no keys were added or changed.
460
+ // Compare key count to determine if keys were deleted.
461
+ return keys.length !== Object.keys(base).length;
462
+ }
463
+ function hasArrayChanges(state) {
464
+ var draft = state.draft;
465
+ if (draft.length !== state.base.length) return true;
466
+ // See #116
467
+ // If we first shorten the length, our array interceptors will be removed.
468
+ // If after that new items are added, result in the same original length,
469
+ // those last items will have no intercepting property.
470
+ // So if there is no own descriptor on the last position, we know that items were removed and added
471
+ // N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
472
+ // the last one
473
+ var descriptor = Object.getOwnPropertyDescriptor(draft, draft.length - 1);
474
+ // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
475
+ if (descriptor && !descriptor.get) return true;
476
+ // For all other cases, we don't have to compare, as they would have been picked up by the index setters
477
+ return false;
478
+ }
479
+ function createHiddenProperty(target, prop, value) {
480
+ Object.defineProperty(target, prop, {
481
+ value: value,
482
+ enumerable: false,
483
+ writable: true
484
+ });
485
+ }
486
+ ;// CONCATENATED MODULE: ./src/proxy.js
487
+
488
+
489
+
490
+
491
+
492
+ // Do nothing before being finalized.
493
+ function proxy_willFinalize() {}
494
+ function proxy_createProxy(base, parent) {
495
+ var scope = parent ? parent.scope : ImmerScope.current;
496
+ var state = {
497
+ // Track which produce call this is associated with.
498
+ scope,
499
+ // True for both shallow and deep changes.
500
+ modified: false,
501
+ // Used during finalization.
502
+ finalized: false,
503
+ // Track which properties have been assigned (true) or deleted (false).
504
+ assigned: {},
505
+ // The parent draft state.
506
+ parent,
507
+ // The base state.
508
+ base,
509
+ // The base proxy.
510
+ draft: null,
511
+ // Any property proxies.
512
+ drafts: {},
513
+ // The base copy with any updated values.
514
+ copy: null,
515
+ // Called by the `produce` function.
516
+ revoke: null
517
+ };
518
+ var _ref = Array.isArray(base) ?
519
+ // [state] is used for arrays, to make sure the proxy is array-ish and not violate invariants,
520
+ // although state itself is an object
521
+ Proxy.revocable([state], arrayTraps) : Proxy.revocable(state, objectTraps),
522
+ revoke = _ref.revoke,
523
+ proxy = _ref.proxy;
524
+ state.draft = proxy;
525
+ state.revoke = revoke;
526
+ scope.drafts.push(proxy);
527
+ return proxy;
528
+ }
529
+ var objectTraps = {
530
+ get: proxy_get,
531
+ has(target, prop) {
532
+ return prop in proxy_source(target);
533
+ },
534
+ ownKeys(target) {
535
+ return Reflect.ownKeys(proxy_source(target));
536
+ },
537
+ set: proxy_set,
538
+ deleteProperty,
539
+ getOwnPropertyDescriptor,
540
+ defineProperty() {
541
+ throw new Error("Object.defineProperty() cannot be used on an Immer draft"); // prettier-ignore
542
+ },
543
+
544
+ getPrototypeOf(target) {
545
+ return Object.getPrototypeOf(target.base);
546
+ },
547
+ setPrototypeOf() {
548
+ throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft"); // prettier-ignore
549
+ }
550
+ };
551
+
552
+ var arrayTraps = {};
553
+ each(objectTraps, (key, fn) => {
554
+ arrayTraps[key] = function () {
555
+ arguments[0] = arguments[0][0];
556
+ return fn.apply(this, arguments);
557
+ };
558
+ });
559
+ arrayTraps.deleteProperty = function (state, prop) {
560
+ if (isNaN(parseInt(prop))) {
561
+ throw new Error("Immer only supports deleting array indices"); // prettier-ignore
562
+ }
563
+
564
+ return objectTraps.deleteProperty.call(this, state[0], prop);
565
+ };
566
+ arrayTraps.set = function (state, prop, value) {
567
+ if (prop !== "length" && isNaN(parseInt(prop))) {
568
+ throw new Error("Immer only supports setting array indices and the 'length' property"); // prettier-ignore
569
+ }
570
+
571
+ return objectTraps.set.call(this, state[0], prop, value);
572
+ };
573
+
574
+ // returns the object we should be reading the current value from, which is base, until some change has been made
575
+ function proxy_source(state) {
576
+ return state.copy || state.base;
577
+ }
578
+
579
+ // Access a property without creating an Immer draft.
580
+ function proxy_peek(draft, prop) {
581
+ var state = draft[DRAFT_STATE];
582
+ var desc = Reflect.getOwnPropertyDescriptor(state ? proxy_source(state) : draft, prop);
583
+ return desc && desc.value;
584
+ }
585
+ function proxy_get(state, prop) {
586
+ if (prop === DRAFT_STATE) return state;
587
+ var drafts = state.drafts;
588
+
589
+ // Check for existing draft in unmodified state.
590
+ if (!state.modified && has(drafts, prop)) {
591
+ return drafts[prop];
592
+ }
593
+ var value = proxy_source(state)[prop];
594
+ if (state.finalized || !isDraftable(value)) {
595
+ return value;
596
+ }
597
+
598
+ // Check for existing draft in modified state.
599
+ if (state.modified) {
600
+ // Assigned values are never drafted. This catches any drafts we created, too.
601
+ if (value !== proxy_peek(state.base, prop)) return value;
602
+ // Store drafts on the copy (when one exists).
603
+ drafts = state.copy;
604
+ }
605
+ return drafts[prop] = proxy_createProxy(value, state);
606
+ }
607
+ function proxy_set(state, prop, value) {
608
+ if (!state.modified) {
609
+ var baseValue = proxy_peek(state.base, prop);
610
+ // Optimize based on value's truthiness. Truthy values are guaranteed to
611
+ // never be undefined, so we can avoid the `in` operator. Lastly, truthy
612
+ // values may be drafts, but falsy values are never drafts.
613
+ var isUnchanged = value ? is(baseValue, value) || value === state.drafts[prop] : is(baseValue, value) && prop in state.base;
614
+ if (isUnchanged) return true;
615
+ proxy_markChanged(state);
616
+ }
617
+ state.assigned[prop] = true;
618
+ state.copy[prop] = value;
619
+ return true;
620
+ }
621
+ function deleteProperty(state, prop) {
622
+ // The `undefined` check is a fast path for pre-existing keys.
623
+ if (proxy_peek(state.base, prop) !== undefined || prop in state.base) {
624
+ state.assigned[prop] = false;
625
+ proxy_markChanged(state);
626
+ }
627
+ if (state.copy) delete state.copy[prop];
628
+ return true;
629
+ }
630
+
631
+ // Note: We never coerce `desc.value` into an Immer draft, because we can't make
632
+ // the same guarantee in ES5 mode.
633
+ function getOwnPropertyDescriptor(state, prop) {
634
+ var owner = proxy_source(state);
635
+ var desc = Reflect.getOwnPropertyDescriptor(owner, prop);
636
+ if (desc) {
637
+ desc.writable = true;
638
+ desc.configurable = !Array.isArray(owner) || prop !== "length";
639
+ }
640
+ return desc;
641
+ }
642
+ function proxy_markChanged(state) {
643
+ if (!state.modified) {
644
+ state.modified = true;
645
+ state.copy = common_assign(shallowCopy(state.base), state.drafts);
646
+ state.drafts = null;
647
+ if (state.parent) proxy_markChanged(state.parent);
648
+ }
649
+ }
650
+ ;// CONCATENATED MODULE: ./src/patches.js
651
+
652
+ function generatePatches(state, basePath, patches, inversePatches) {
653
+ Array.isArray(state.base) ? generateArrayPatches(state, basePath, patches, inversePatches) : generateObjectPatches(state, basePath, patches, inversePatches);
654
+ }
655
+ function generateArrayPatches(state, basePath, patches, inversePatches) {
656
+ var base = state.base,
657
+ copy = state.copy,
658
+ assigned = state.assigned;
659
+
660
+ // Reduce complexity by ensuring `base` is never longer.
661
+ if (copy.length < base.length) {
662
+ ;
663
+ var _ref = [copy, base];
664
+ base = _ref[0];
665
+ copy = _ref[1];
666
+ var _ref2 = [inversePatches, patches];
667
+ patches = _ref2[0];
668
+ inversePatches = _ref2[1];
669
+ }
670
+ var delta = copy.length - base.length;
671
+
672
+ // Find the first replaced index.
673
+ var start = 0;
674
+ while (base[start] === copy[start] && start < base.length) {
675
+ ++start;
676
+ }
677
+
678
+ // Find the last replaced index. Search from the end to optimize splice patches.
679
+ var end = base.length;
680
+ while (end > start && base[end - 1] === copy[end + delta - 1]) {
681
+ --end;
682
+ }
683
+
684
+ // Process replaced indices.
685
+ for (var i = start; i < end; ++i) {
686
+ if (assigned[i] && copy[i] !== base[i]) {
687
+ var path = basePath.concat([i]);
688
+ patches.push({
689
+ op: "replace",
690
+ path,
691
+ value: copy[i]
692
+ });
693
+ inversePatches.push({
694
+ op: "replace",
695
+ path,
696
+ value: base[i]
697
+ });
698
+ }
699
+ }
700
+ var useRemove = end != base.length;
701
+ var replaceCount = patches.length;
702
+
703
+ // Process added indices.
704
+ for (var _i = end + delta - 1; _i >= end; --_i) {
705
+ var _path = basePath.concat([_i]);
706
+ patches[replaceCount + _i - end] = {
707
+ op: "add",
708
+ path: _path,
709
+ value: copy[_i]
710
+ };
711
+ if (useRemove) {
712
+ inversePatches.push({
713
+ op: "remove",
714
+ path: _path
715
+ });
716
+ }
717
+ }
718
+
719
+ // One "replace" patch reverses all non-splicing "add" patches.
720
+ if (!useRemove) {
721
+ inversePatches.push({
722
+ op: "replace",
723
+ path: basePath.concat(["length"]),
724
+ value: base.length
725
+ });
726
+ }
727
+ }
728
+ function generateObjectPatches(state, basePath, patches, inversePatches) {
729
+ var base = state.base,
730
+ copy = state.copy;
731
+ each(state.assigned, (key, assignedValue) => {
732
+ var origValue = base[key];
733
+ var value = copy[key];
734
+ var op = !assignedValue ? "remove" : key in base ? "replace" : "add";
735
+ if (origValue === value && op === "replace") return;
736
+ var path = basePath.concat(key);
737
+ patches.push(op === "remove" ? {
738
+ op,
739
+ path
740
+ } : {
741
+ op,
742
+ path,
743
+ value
744
+ });
745
+ inversePatches.push(op === "add" ? {
746
+ op: "remove",
747
+ path
748
+ } : op === "remove" ? {
749
+ op: "add",
750
+ path,
751
+ value: origValue
752
+ } : {
753
+ op: "replace",
754
+ path,
755
+ value: origValue
756
+ });
757
+ });
758
+ }
759
+ function applyPatches(draft, patches) {
760
+ for (var i = 0; i < patches.length; i++) {
761
+ var patch = patches[i];
762
+ var path = patch.path;
763
+ if (path.length === 0 && patch.op === "replace") {
764
+ draft = patch.value;
765
+ } else {
766
+ var base = draft;
767
+ for (var _i2 = 0; _i2 < path.length - 1; _i2++) {
768
+ base = base[path[_i2]];
769
+ if (!base || typeof base !== "object") throw new Error("Cannot apply patch, path doesn't resolve: " + path.join("/")); // prettier-ignore
770
+ }
771
+
772
+ var key = path[path.length - 1];
773
+ switch (patch.op) {
774
+ case "replace":
775
+ base[key] = patch.value;
776
+ break;
777
+ case "add":
778
+ if (Array.isArray(base)) {
779
+ // TODO: support "foo/-" paths for appending to an array
780
+ base.splice(key, 0, patch.value);
781
+ } else {
782
+ base[key] = patch.value;
783
+ }
784
+ break;
785
+ case "remove":
786
+ if (Array.isArray(base)) {
787
+ base.splice(key, 1);
788
+ } else {
789
+ delete base[key];
790
+ }
791
+ break;
792
+ default:
793
+ throw new Error("Unsupported patch operation: " + patch.op);
794
+ }
795
+ }
796
+ }
797
+ return draft;
798
+ }
799
+ ;// CONCATENATED MODULE: ./src/immer.js
800
+ /* provided dependency */ var process = __webpack_require__(376);
801
+
802
+
803
+
804
+
805
+
806
+ function verifyMinified() {}
807
+ var configDefaults = {
808
+ useProxies: typeof Proxy !== "undefined" && typeof Reflect !== "undefined",
809
+ autoFreeze: typeof process !== "undefined" ? "production" !== "production" : verifyMinified.name === "verifyMinified",
810
+ onAssign: null,
811
+ onDelete: null,
812
+ onCopy: null
813
+ };
814
+ class Immer {
815
+ constructor(config) {
816
+ common_assign(this, configDefaults, config);
817
+ this.setUseProxies(this.useProxies);
818
+ this.produce = this.produce.bind(this);
819
+ }
820
+ produce(base, recipe, patchListener) {
821
+ // curried invocation
822
+ if (typeof base === "function" && typeof recipe !== "function") {
823
+ var defaultBase = recipe;
824
+ recipe = base;
825
+ var self = this;
826
+ return function curriedProduce() {
827
+ var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultBase;
828
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
829
+ args[_key - 1] = arguments[_key];
830
+ }
831
+ return self.produce(base, draft => recipe.call(this, draft, ...args)); // prettier-ignore
832
+ };
833
+ }
834
+
835
+ // prettier-ignore
836
+ {
837
+ if (typeof recipe !== "function") {
838
+ throw new Error("The first or second argument to `produce` must be a function");
839
+ }
840
+ if (patchListener !== undefined && typeof patchListener !== "function") {
841
+ throw new Error("The third argument to `produce` must be a function or undefined");
842
+ }
843
+ }
844
+ var result;
845
+
846
+ // Only plain objects, arrays, and "immerable classes" are drafted.
847
+ if (isDraftable(base)) {
848
+ var scope = ImmerScope.enter();
849
+ var proxy = this.createProxy(base);
850
+ var hasError = true;
851
+ try {
852
+ result = recipe(proxy);
853
+ hasError = false;
854
+ } finally {
855
+ // finally instead of catch + rethrow better preserves original stack
856
+ if (hasError) scope.revoke();else scope.leave();
857
+ }
858
+ if (result instanceof Promise) {
859
+ return result.then(result => {
860
+ scope.usePatches(patchListener);
861
+ return this.processResult(result, scope);
862
+ }, error => {
863
+ scope.revoke();
864
+ throw error;
865
+ });
866
+ }
867
+ scope.usePatches(patchListener);
868
+ return this.processResult(result, scope);
869
+ } else {
870
+ result = recipe(base);
871
+ if (result === undefined) return base;
872
+ return result !== NOTHING ? result : undefined;
873
+ }
874
+ }
875
+ createDraft(base) {
876
+ if (!isDraftable(base)) {
877
+ throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object"); // prettier-ignore
878
+ }
879
+
880
+ var scope = ImmerScope.enter();
881
+ var proxy = this.createProxy(base, null);
882
+ proxy[DRAFT_STATE].isManual = true;
883
+ scope.leave();
884
+ return proxy;
885
+ }
886
+ finishDraft(draft, patchListener, keepAlive) {
887
+ var state = draft && draft[DRAFT_STATE];
888
+ if (!state || !state.isManual) {
889
+ throw new Error("First argument to `finishDraft` must be a draft returned by `createDraft`"); // prettier-ignore
890
+ }
891
+
892
+ if (state.finalized) {
893
+ throw new Error("The given draft is already finalized"); // prettier-ignore
894
+ }
895
+
896
+ var scope = state.scope;
897
+ scope.usePatches(patchListener);
898
+ return this.processResult(undefined, scope, keepAlive);
899
+ }
900
+ setAutoFreeze(value) {
901
+ this.autoFreeze = value;
902
+ }
903
+ setUseProxies(value) {
904
+ this.useProxies = value;
905
+ common_assign(this, value ? proxy_namespaceObject : es5_namespaceObject);
906
+ }
907
+ applyPatches(base, patches) {
908
+ // Mutate the base state when a draft is passed.
909
+ if (isDraft(base)) {
910
+ return applyPatches(base, patches);
911
+ }
912
+ // Otherwise, produce a copy of the base state.
913
+ return this.produce(base, draft => applyPatches(draft, patches));
914
+ }
915
+ /** @internal */
916
+ processResult(result, scope, keepAlive) {
917
+ var baseDraft = scope.drafts[0];
918
+ var isReplaced = result !== undefined && result !== baseDraft;
919
+ this.willFinalize(scope, result, isReplaced);
920
+ if (isReplaced) {
921
+ if (baseDraft[DRAFT_STATE].modified) {
922
+ scope.revoke(keepAlive);
923
+ throw new Error("An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."); // prettier-ignore
924
+ }
925
+
926
+ if (isDraftable(result)) {
927
+ // Finalize the result in case it contains (or is) a subset of the draft.
928
+ result = this.finalize(result, null, scope);
929
+ }
930
+ if (scope.patches) {
931
+ scope.patches.push({
932
+ op: "replace",
933
+ path: [],
934
+ value: result
935
+ });
936
+ scope.inversePatches.push({
937
+ op: "replace",
938
+ path: [],
939
+ value: baseDraft[DRAFT_STATE].base
940
+ });
941
+ }
942
+ } else {
943
+ // Finalize the base draft.
944
+ result = this.finalize(baseDraft, [], scope, keepAlive);
945
+ }
946
+ scope.revoke(keepAlive);
947
+ if (scope.patches) {
948
+ scope.patchListener(scope.patches, scope.inversePatches);
949
+ }
950
+ return result !== NOTHING ? result : undefined;
951
+ }
952
+ /**
953
+ * @internal
954
+ * Finalize a draft, returning either the unmodified base state or a modified
955
+ * copy of the base state.
956
+ */
957
+ finalize(draft, path, scope, keepAlive) {
958
+ var state = draft[DRAFT_STATE];
959
+ if (!state) {
960
+ if (Object.isFrozen(draft)) return draft;
961
+ return this.finalizeTree(draft, null, scope);
962
+ }
963
+ // Never finalize drafts owned by another scope.
964
+ if (state.scope !== scope) {
965
+ return draft;
966
+ }
967
+ if (!state.modified) {
968
+ return state.base;
969
+ }
970
+ if (!state.finalized) {
971
+ if (!keepAlive) state.finalized = true;
972
+ this.finalizeTree(state.draft, path, scope);
973
+ if (this.onDelete) {
974
+ // The `assigned` object is unreliable with ES5 drafts.
975
+ if (this.useProxies) {
976
+ var assigned = state.assigned;
977
+ for (var prop in assigned) {
978
+ if (!assigned[prop]) this.onDelete(state, prop);
979
+ }
980
+ } else {
981
+ var base = state.base,
982
+ copy = state.copy;
983
+ each(base, prop => {
984
+ if (!has(copy, prop)) this.onDelete(state, prop);
985
+ });
986
+ }
987
+ }
988
+ if (this.onCopy) {
989
+ this.onCopy(state);
990
+ }
991
+
992
+ // At this point, all descendants of `state.copy` have been finalized,
993
+ // so we can be sure that `scope.canAutoFreeze` is accurate.
994
+ if (this.autoFreeze && scope.canAutoFreeze) {
995
+ Object.freeze(state.copy);
996
+ }
997
+ if (path && scope.patches) {
998
+ generatePatches(state, path, scope.patches, scope.inversePatches);
999
+ }
1000
+ }
1001
+ return state.copy;
1002
+ }
1003
+ /**
1004
+ * @internal
1005
+ * Finalize all drafts in the given state tree.
1006
+ */
1007
+ finalizeTree(root, rootPath, scope) {
1008
+ var state = root[DRAFT_STATE];
1009
+ if (state) {
1010
+ if (!this.useProxies) {
1011
+ // Create the final copy, with added keys and without deleted keys.
1012
+ state.copy = shallowCopy(state.draft, true);
1013
+ }
1014
+ root = state.copy;
1015
+ }
1016
+ var needPatches = !!rootPath && !!scope.patches;
1017
+ var finalizeProperty = (prop, value, parent) => {
1018
+ if (value === parent) {
1019
+ throw Error("Immer forbids circular references");
1020
+ }
1021
+
1022
+ // In the `finalizeTree` method, only the `root` object may be a draft.
1023
+ var isDraftProp = !!state && parent === root;
1024
+ if (isDraft(value)) {
1025
+ var path = isDraftProp && needPatches && !state.assigned[prop] ? rootPath.concat(prop) : null;
1026
+
1027
+ // Drafts owned by `scope` are finalized here.
1028
+ value = this.finalize(value, path, scope);
1029
+
1030
+ // Drafts from another scope must prevent auto-freezing.
1031
+ if (isDraft(value)) {
1032
+ scope.canAutoFreeze = false;
1033
+ }
1034
+
1035
+ // Preserve non-enumerable properties.
1036
+ if (Array.isArray(parent) || isEnumerable(parent, prop)) {
1037
+ parent[prop] = value;
1038
+ } else {
1039
+ Object.defineProperty(parent, prop, {
1040
+ value
1041
+ });
1042
+ }
1043
+
1044
+ // Unchanged drafts are never passed to the `onAssign` hook.
1045
+ if (isDraftProp && value === state.base[prop]) return;
1046
+ }
1047
+ // Unchanged draft properties are ignored.
1048
+ else if (isDraftProp && is(value, state.base[prop])) {
1049
+ return;
1050
+ }
1051
+ // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
1052
+ else if (isDraftable(value) && !Object.isFrozen(value)) {
1053
+ each(value, finalizeProperty);
1054
+ }
1055
+ if (isDraftProp && this.onAssign) {
1056
+ this.onAssign(state, prop, value);
1057
+ }
1058
+ };
1059
+ each(root, finalizeProperty);
1060
+ return root;
1061
+ }
1062
+ }
1063
+ ;// CONCATENATED MODULE: ./src/index.js
1064
+
1065
+ var immer = new Immer();
1066
+
1067
+ /**
1068
+ * The `produce` function takes a value and a "recipe function" (whose
1069
+ * return value often depends on the base state). The recipe function is
1070
+ * free to mutate its first argument however it wants. All mutations are
1071
+ * only ever applied to a __copy__ of the base state.
1072
+ *
1073
+ * Pass only a function to create a "curried producer" which relieves you
1074
+ * from passing the recipe function every time.
1075
+ *
1076
+ * Only plain objects and arrays are made mutable. All other objects are
1077
+ * considered uncopyable.
1078
+ *
1079
+ * Note: This function is __bound__ to its `Immer` instance.
1080
+ *
1081
+ * @param {any} base - the initial state
1082
+ * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
1083
+ * @param {Function} patchListener - optional function that will be called with all the patches produced here
1084
+ * @returns {any} a new state, or the initial state if nothing was modified
1085
+ */
1086
+ var produce = immer.produce;
1087
+ /* harmony default export */ var src = (produce);
1088
+
1089
+ /**
1090
+ * Pass true to automatically freeze all copies created by Immer.
1091
+ *
1092
+ * By default, auto-freezing is disabled in production.
1093
+ */
1094
+ var setAutoFreeze = immer.setAutoFreeze.bind(immer);
1095
+
1096
+ /**
1097
+ * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
1098
+ * always faster than using ES5 proxies.
1099
+ *
1100
+ * By default, feature detection is used, so calling this is rarely necessary.
1101
+ */
1102
+ var setUseProxies = immer.setUseProxies.bind(immer);
1103
+
1104
+ /**
1105
+ * Apply an array of Immer patches to the first argument.
1106
+ *
1107
+ * This function is a producer, which means copy-on-write is in effect.
1108
+ */
1109
+ var src_applyPatches = immer.applyPatches.bind(immer);
1110
+
1111
+ /**
1112
+ * Create an Immer draft from the given base state, which may be a draft itself.
1113
+ * The draft can be modified until you finalize it with the `finishDraft` function.
1114
+ */
1115
+ var createDraft = immer.createDraft.bind(immer);
1116
+
1117
+ /**
1118
+ * Finalize an Immer draft from a `createDraft` call, returning the base state
1119
+ * (if no changes were made) or a modified copy. The draft must *not* be
1120
+ * mutated afterwards.
1121
+ *
1122
+ * Pass a function as the 2nd argument to generate Immer patches based on the
1123
+ * changes that were made.
1124
+ */
1125
+ var finishDraft = immer.finishDraft.bind(immer);
1126
+
1127
+
1128
+ })();
1129
+
1130
+ /******/ return __webpack_exports__;
1131
+ /******/ })()
1132
+ ;
1133
+ });
1134
+ //# sourceMappingURL=index.js.map