immer.umd.development.js 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.immer = {}));
  5. }(this, (function (exports) { 'use strict';
  6. var _ref;
  7. // Should be no imports here!
  8. // Some things that should be evaluated before all else...
  9. // We only want to know if non-polyfilled symbols are available
  10. var hasSymbol = typeof Symbol !== "undefined" && typeof
  11. /*#__PURE__*/
  12. Symbol("x") === "symbol";
  13. var hasMap = typeof Map !== "undefined";
  14. var hasSet = typeof Set !== "undefined";
  15. var hasProxies = typeof Proxy !== "undefined" && typeof Proxy.revocable !== "undefined" && typeof Reflect !== "undefined";
  16. /**
  17. * The sentinel value returned by producers to replace the draft with undefined.
  18. */
  19. var NOTHING = hasSymbol ?
  20. /*#__PURE__*/
  21. Symbol.for("immer-nothing") : (_ref = {}, _ref["immer-nothing"] = true, _ref);
  22. /**
  23. * To let Immer treat your class instances as plain immutable objects
  24. * (albeit with a custom prototype), you must define either an instance property
  25. * or a static property on each of your custom classes.
  26. *
  27. * Otherwise, your class instance will never be drafted, which means it won't be
  28. * safe to mutate in a produce callback.
  29. */
  30. var DRAFTABLE = hasSymbol ?
  31. /*#__PURE__*/
  32. Symbol.for("immer-draftable") : "__$immer_draftable";
  33. var DRAFT_STATE = hasSymbol ?
  34. /*#__PURE__*/
  35. Symbol.for("immer-state") : "__$immer_state"; // Even a polyfilled Symbol might provide Symbol.iterator
  36. var iteratorSymbol = typeof Symbol != "undefined" && Symbol.iterator || "@@iterator";
  37. var errors = {
  38. 0: "Illegal state",
  39. 1: "Immer drafts cannot have computed properties",
  40. 2: "This object has been frozen and should not be mutated",
  41. 3: function _(data) {
  42. return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
  43. },
  44. 4: "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
  45. 5: "Immer forbids circular references",
  46. 6: "The first or second argument to `produce` must be a function",
  47. 7: "The third argument to `produce` must be a function or undefined",
  48. 8: "First argument to `createDraft` must be a plain object, an array, or an immerable object",
  49. 9: "First argument to `finishDraft` must be a draft returned by `createDraft`",
  50. 10: "The given draft is already finalized",
  51. 11: "Object.defineProperty() cannot be used on an Immer draft",
  52. 12: "Object.setPrototypeOf() cannot be used on an Immer draft",
  53. 13: "Immer only supports deleting array indices",
  54. 14: "Immer only supports setting array indices and the 'length' property",
  55. 15: function _(path) {
  56. return "Cannot apply patch, path doesn't resolve: " + path;
  57. },
  58. 16: 'Sets cannot have "replace" patches.',
  59. 17: function _(op) {
  60. return "Unsupported patch operation: " + op;
  61. },
  62. 18: function _(plugin) {
  63. return "The plugin for '" + plugin + "' has not been loaded into Immer. To enable the plugin, import and call `enable" + plugin + "()` when initializing your application.";
  64. },
  65. 20: "Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",
  66. 21: function _(thing) {
  67. return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '" + thing + "'";
  68. },
  69. 22: function _(thing) {
  70. return "'current' expects a draft, got: " + thing;
  71. },
  72. 23: function _(thing) {
  73. return "'original' expects a draft, got: " + thing;
  74. },
  75. 24: "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
  76. };
  77. function die(error) {
  78. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  79. args[_key - 1] = arguments[_key];
  80. }
  81. {
  82. var e = errors[error];
  83. var msg = !e ? "unknown error nr: " + error : typeof e === "function" ? e.apply(null, args) : e;
  84. throw new Error("[Immer] " + msg);
  85. }
  86. }
  87. /** Returns true if the given value is an Immer draft */
  88. /*#__PURE__*/
  89. function isDraft(value) {
  90. return !!value && !!value[DRAFT_STATE];
  91. }
  92. /** Returns true if the given value can be drafted by Immer */
  93. /*#__PURE__*/
  94. function isDraftable(value) {
  95. var _value$constructor;
  96. if (!value) return false;
  97. return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor[DRAFTABLE]) || isMap(value) || isSet(value);
  98. }
  99. var objectCtorString =
  100. /*#__PURE__*/
  101. Object.prototype.constructor.toString();
  102. /*#__PURE__*/
  103. function isPlainObject(value) {
  104. if (!value || typeof value !== "object") return false;
  105. var proto = Object.getPrototypeOf(value);
  106. if (proto === null) {
  107. return true;
  108. }
  109. var Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
  110. if (Ctor === Object) return true;
  111. return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
  112. }
  113. function original(value) {
  114. if (!isDraft(value)) die(23, value);
  115. return value[DRAFT_STATE].base_;
  116. }
  117. /*#__PURE__*/
  118. var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
  119. return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
  120. } :
  121. /* istanbul ignore next */
  122. Object.getOwnPropertyNames;
  123. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors(target) {
  124. // Polyfill needed for Hermes and IE, see https://github.com/facebook/hermes/issues/274
  125. var res = {};
  126. ownKeys(target).forEach(function (key) {
  127. res[key] = Object.getOwnPropertyDescriptor(target, key);
  128. });
  129. return res;
  130. };
  131. function each(obj, iter, enumerableOnly) {
  132. if (enumerableOnly === void 0) {
  133. enumerableOnly = false;
  134. }
  135. if (getArchtype(obj) === 0
  136. /* Object */
  137. ) {
  138. (enumerableOnly ? Object.keys : ownKeys)(obj).forEach(function (key) {
  139. if (!enumerableOnly || typeof key !== "symbol") iter(key, obj[key], obj);
  140. });
  141. } else {
  142. obj.forEach(function (entry, index) {
  143. return iter(index, entry, obj);
  144. });
  145. }
  146. }
  147. /*#__PURE__*/
  148. function getArchtype(thing) {
  149. /* istanbul ignore next */
  150. var state = thing[DRAFT_STATE];
  151. return state ? state.type_ > 3 ? state.type_ - 4 // cause Object and Array map back from 4 and 5
  152. : state.type_ // others are the same
  153. : Array.isArray(thing) ? 1
  154. /* Array */
  155. : isMap(thing) ? 2
  156. /* Map */
  157. : isSet(thing) ? 3
  158. /* Set */
  159. : 0
  160. /* Object */
  161. ;
  162. }
  163. /*#__PURE__*/
  164. function has(thing, prop) {
  165. return getArchtype(thing) === 2
  166. /* Map */
  167. ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
  168. }
  169. /*#__PURE__*/
  170. function get(thing, prop) {
  171. // @ts-ignore
  172. return getArchtype(thing) === 2
  173. /* Map */
  174. ? thing.get(prop) : thing[prop];
  175. }
  176. /*#__PURE__*/
  177. function set(thing, propOrOldValue, value) {
  178. var t = getArchtype(thing);
  179. if (t === 2
  180. /* Map */
  181. ) thing.set(propOrOldValue, value);else if (t === 3
  182. /* Set */
  183. ) {
  184. thing.add(value);
  185. } else thing[propOrOldValue] = value;
  186. }
  187. /*#__PURE__*/
  188. function is(x, y) {
  189. // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
  190. if (x === y) {
  191. return x !== 0 || 1 / x === 1 / y;
  192. } else {
  193. return x !== x && y !== y;
  194. }
  195. }
  196. /*#__PURE__*/
  197. function isMap(target) {
  198. return hasMap && target instanceof Map;
  199. }
  200. /*#__PURE__*/
  201. function isSet(target) {
  202. return hasSet && target instanceof Set;
  203. }
  204. /*#__PURE__*/
  205. function latest(state) {
  206. return state.copy_ || state.base_;
  207. }
  208. /*#__PURE__*/
  209. function shallowCopy(base) {
  210. if (Array.isArray(base)) return Array.prototype.slice.call(base);
  211. var descriptors = getOwnPropertyDescriptors(base);
  212. delete descriptors[DRAFT_STATE];
  213. var keys = ownKeys(descriptors);
  214. for (var i = 0; i < keys.length; i++) {
  215. var key = keys[i];
  216. var desc = descriptors[key];
  217. if (desc.writable === false) {
  218. desc.writable = true;
  219. desc.configurable = true;
  220. } // like object.assign, we will read any _own_, get/set accessors. This helps in dealing
  221. // with libraries that trap values, like mobx or vue
  222. // unlike object.assign, non-enumerables will be copied as well
  223. if (desc.get || desc.set) descriptors[key] = {
  224. configurable: true,
  225. writable: true,
  226. enumerable: desc.enumerable,
  227. value: base[key]
  228. };
  229. }
  230. return Object.create(Object.getPrototypeOf(base), descriptors);
  231. }
  232. function freeze(obj, deep) {
  233. if (deep === void 0) {
  234. deep = false;
  235. }
  236. if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
  237. if (getArchtype(obj) > 1
  238. /* Map or Set */
  239. ) {
  240. obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
  241. }
  242. Object.freeze(obj);
  243. if (deep) each(obj, function (key, value) {
  244. return freeze(value, true);
  245. }, true);
  246. return obj;
  247. }
  248. function dontMutateFrozenCollections() {
  249. die(2);
  250. }
  251. function isFrozen(obj) {
  252. if (obj == null || typeof obj !== "object") return true; // See #600, IE dies on non-objects in Object.isFrozen
  253. return Object.isFrozen(obj);
  254. }
  255. /** Plugin utilities */
  256. var plugins = {};
  257. function getPlugin(pluginKey) {
  258. var plugin = plugins[pluginKey];
  259. if (!plugin) {
  260. die(18, pluginKey);
  261. } // @ts-ignore
  262. return plugin;
  263. }
  264. function loadPlugin(pluginKey, implementation) {
  265. if (!plugins[pluginKey]) plugins[pluginKey] = implementation;
  266. }
  267. var currentScope;
  268. function getCurrentScope() {
  269. if ( !currentScope) die(0);
  270. return currentScope;
  271. }
  272. function createScope(parent_, immer_) {
  273. return {
  274. drafts_: [],
  275. parent_: parent_,
  276. immer_: immer_,
  277. // Whenever the modified draft contains a draft from another scope, we
  278. // need to prevent auto-freezing so the unowned draft can be finalized.
  279. canAutoFreeze_: true,
  280. unfinalizedDrafts_: 0
  281. };
  282. }
  283. function usePatchesInScope(scope, patchListener) {
  284. if (patchListener) {
  285. getPlugin("Patches"); // assert we have the plugin
  286. scope.patches_ = [];
  287. scope.inversePatches_ = [];
  288. scope.patchListener_ = patchListener;
  289. }
  290. }
  291. function revokeScope(scope) {
  292. leaveScope(scope);
  293. scope.drafts_.forEach(revokeDraft); // @ts-ignore
  294. scope.drafts_ = null;
  295. }
  296. function leaveScope(scope) {
  297. if (scope === currentScope) {
  298. currentScope = scope.parent_;
  299. }
  300. }
  301. function enterScope(immer) {
  302. return currentScope = createScope(currentScope, immer);
  303. }
  304. function revokeDraft(draft) {
  305. var state = draft[DRAFT_STATE];
  306. if (state.type_ === 0
  307. /* ProxyObject */
  308. || state.type_ === 1
  309. /* ProxyArray */
  310. ) state.revoke_();else state.revoked_ = true;
  311. }
  312. function processResult(result, scope) {
  313. scope.unfinalizedDrafts_ = scope.drafts_.length;
  314. var baseDraft = scope.drafts_[0];
  315. var isReplaced = result !== undefined && result !== baseDraft;
  316. if (!scope.immer_.useProxies_) getPlugin("ES5").willFinalizeES5_(scope, result, isReplaced);
  317. if (isReplaced) {
  318. if (baseDraft[DRAFT_STATE].modified_) {
  319. revokeScope(scope);
  320. die(4);
  321. }
  322. if (isDraftable(result)) {
  323. // Finalize the result in case it contains (or is) a subset of the draft.
  324. result = finalize(scope, result);
  325. if (!scope.parent_) maybeFreeze(scope, result);
  326. }
  327. if (scope.patches_) {
  328. getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);
  329. }
  330. } else {
  331. // Finalize the base draft.
  332. result = finalize(scope, baseDraft, []);
  333. }
  334. revokeScope(scope);
  335. if (scope.patches_) {
  336. scope.patchListener_(scope.patches_, scope.inversePatches_);
  337. }
  338. return result !== NOTHING ? result : undefined;
  339. }
  340. function finalize(rootScope, value, path) {
  341. // Don't recurse in tho recursive data structures
  342. if (isFrozen(value)) return value;
  343. var state = value[DRAFT_STATE]; // A plain object, might need freezing, might contain drafts
  344. if (!state) {
  345. each(value, function (key, childValue) {
  346. return finalizeProperty(rootScope, state, value, key, childValue, path);
  347. }, true // See #590, don't recurse into non-enumerable of non drafted objects
  348. );
  349. return value;
  350. } // Never finalize drafts owned by another scope.
  351. if (state.scope_ !== rootScope) return value; // Unmodified draft, return the (frozen) original
  352. if (!state.modified_) {
  353. maybeFreeze(rootScope, state.base_, true);
  354. return state.base_;
  355. } // Not finalized yet, let's do that now
  356. if (!state.finalized_) {
  357. state.finalized_ = true;
  358. state.scope_.unfinalizedDrafts_--;
  359. var result = // For ES5, create a good copy from the draft first, with added keys and without deleted keys.
  360. state.type_ === 4
  361. /* ES5Object */
  362. || state.type_ === 5
  363. /* ES5Array */
  364. ? state.copy_ = shallowCopy(state.draft_) : state.copy_; // Finalize all children of the copy
  365. // For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628
  366. // To preserve insertion order in all cases we then clear the set
  367. // And we let finalizeProperty know it needs to re-add non-draft children back to the target
  368. var resultEach = result;
  369. var isSet = false;
  370. if (state.type_ === 3
  371. /* Set */
  372. ) {
  373. resultEach = new Set(result);
  374. result.clear();
  375. isSet = true;
  376. }
  377. each(resultEach, function (key, childValue) {
  378. return finalizeProperty(rootScope, state, result, key, childValue, path, isSet);
  379. }); // everything inside is frozen, we can freeze here
  380. maybeFreeze(rootScope, result, false); // first time finalizing, let's create those patches
  381. if (path && rootScope.patches_) {
  382. getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);
  383. }
  384. }
  385. return state.copy_;
  386. }
  387. function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
  388. if ( childValue === targetObject) die(5);
  389. if (isDraft(childValue)) {
  390. var path = rootPath && parentState && parentState.type_ !== 3
  391. /* Set */
  392. && // Set objects are atomic since they have no keys.
  393. !has(parentState.assigned_, prop) // Skip deep patches for assigned keys.
  394. ? rootPath.concat(prop) : undefined; // Drafts owned by `scope` are finalized here.
  395. var res = finalize(rootScope, childValue, path);
  396. set(targetObject, prop, res); // Drafts from another scope must prevented to be frozen
  397. // if we got a draft back from finalize, we're in a nested produce and shouldn't freeze
  398. if (isDraft(res)) {
  399. rootScope.canAutoFreeze_ = false;
  400. } else return;
  401. } else if (targetIsSet) {
  402. targetObject.add(childValue);
  403. } // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
  404. if (isDraftable(childValue) && !isFrozen(childValue)) {
  405. if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
  406. // optimization: if an object is not a draft, and we don't have to
  407. // deepfreeze everything, and we are sure that no drafts are left in the remaining object
  408. // cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.
  409. // This benefits especially adding large data tree's without further processing.
  410. // See add-data.js perf test
  411. return;
  412. }
  413. finalize(rootScope, childValue); // immer deep freezes plain objects, so if there is no parent state, we freeze as well
  414. if (!parentState || !parentState.scope_.parent_) maybeFreeze(rootScope, childValue);
  415. }
  416. }
  417. function maybeFreeze(scope, value, deep) {
  418. if (deep === void 0) {
  419. deep = false;
  420. }
  421. // we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects
  422. if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
  423. freeze(value, deep);
  424. }
  425. }
  426. /**
  427. * Returns a new draft of the `base` object.
  428. *
  429. * The second argument is the parent draft-state (used internally).
  430. */
  431. function createProxyProxy(base, parent) {
  432. var isArray = Array.isArray(base);
  433. var state = {
  434. type_: isArray ? 1
  435. /* ProxyArray */
  436. : 0
  437. /* ProxyObject */
  438. ,
  439. // Track which produce call this is associated with.
  440. scope_: parent ? parent.scope_ : getCurrentScope(),
  441. // True for both shallow and deep changes.
  442. modified_: false,
  443. // Used during finalization.
  444. finalized_: false,
  445. // Track which properties have been assigned (true) or deleted (false).
  446. assigned_: {},
  447. // The parent draft state.
  448. parent_: parent,
  449. // The base state.
  450. base_: base,
  451. // The base proxy.
  452. draft_: null,
  453. // The base copy with any updated values.
  454. copy_: null,
  455. // Called by the `produce` function.
  456. revoke_: null,
  457. isManual_: false
  458. }; // the traps must target something, a bit like the 'real' base.
  459. // but also, we need to be able to determine from the target what the relevant state is
  460. // (to avoid creating traps per instance to capture the state in closure,
  461. // and to avoid creating weird hidden properties as well)
  462. // So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)
  463. // Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
  464. var target = state;
  465. var traps = objectTraps;
  466. if (isArray) {
  467. target = [state];
  468. traps = arrayTraps;
  469. }
  470. var _Proxy$revocable = Proxy.revocable(target, traps),
  471. revoke = _Proxy$revocable.revoke,
  472. proxy = _Proxy$revocable.proxy;
  473. state.draft_ = proxy;
  474. state.revoke_ = revoke;
  475. return proxy;
  476. }
  477. /**
  478. * Object drafts
  479. */
  480. var objectTraps = {
  481. get: function get(state, prop) {
  482. if (prop === DRAFT_STATE) return state;
  483. var source = latest(state);
  484. if (!has(source, prop)) {
  485. // non-existing or non-own property...
  486. return readPropFromProto(state, source, prop);
  487. }
  488. var value = source[prop];
  489. if (state.finalized_ || !isDraftable(value)) {
  490. return value;
  491. } // Check for existing draft in modified state.
  492. // Assigned values are never drafted. This catches any drafts we created, too.
  493. if (value === peek(state.base_, prop)) {
  494. prepareCopy(state);
  495. return state.copy_[prop] = createProxy(state.scope_.immer_, value, state);
  496. }
  497. return value;
  498. },
  499. has: function has(state, prop) {
  500. return prop in latest(state);
  501. },
  502. ownKeys: function ownKeys(state) {
  503. return Reflect.ownKeys(latest(state));
  504. },
  505. set: function set(state, prop
  506. /* strictly not, but helps TS */
  507. , value) {
  508. var desc = getDescriptorFromProto(latest(state), prop);
  509. if (desc === null || desc === void 0 ? void 0 : desc.set) {
  510. // special case: if this write is captured by a setter, we have
  511. // to trigger it with the correct context
  512. desc.set.call(state.draft_, value);
  513. return true;
  514. }
  515. if (!state.modified_) {
  516. // the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)
  517. // from setting an existing property with value undefined to undefined (which is not a change)
  518. var current = peek(latest(state), prop); // special case, if we assigning the original value to a draft, we can ignore the assignment
  519. var currentState = current === null || current === void 0 ? void 0 : current[DRAFT_STATE];
  520. if (currentState && currentState.base_ === value) {
  521. state.copy_[prop] = value;
  522. state.assigned_[prop] = false;
  523. return true;
  524. }
  525. if (is(value, current) && (value !== undefined || has(state.base_, prop))) return true;
  526. prepareCopy(state);
  527. markChanged(state);
  528. }
  529. if (state.copy_[prop] === value && ( // special case: handle new props with value 'undefined'
  530. value !== undefined || prop in state.copy_) || // special case: NaN
  531. Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true; // @ts-ignore
  532. state.copy_[prop] = value;
  533. state.assigned_[prop] = true;
  534. return true;
  535. },
  536. deleteProperty: function deleteProperty(state, prop) {
  537. // The `undefined` check is a fast path for pre-existing keys.
  538. if (peek(state.base_, prop) !== undefined || prop in state.base_) {
  539. state.assigned_[prop] = false;
  540. prepareCopy(state);
  541. markChanged(state);
  542. } else {
  543. // if an originally not assigned property was deleted
  544. delete state.assigned_[prop];
  545. } // @ts-ignore
  546. if (state.copy_) delete state.copy_[prop];
  547. return true;
  548. },
  549. // Note: We never coerce `desc.value` into an Immer draft, because we can't make
  550. // the same guarantee in ES5 mode.
  551. getOwnPropertyDescriptor: function getOwnPropertyDescriptor(state, prop) {
  552. var owner = latest(state);
  553. var desc = Reflect.getOwnPropertyDescriptor(owner, prop);
  554. if (!desc) return desc;
  555. return {
  556. writable: true,
  557. configurable: state.type_ !== 1
  558. /* ProxyArray */
  559. || prop !== "length",
  560. enumerable: desc.enumerable,
  561. value: owner[prop]
  562. };
  563. },
  564. defineProperty: function defineProperty() {
  565. die(11);
  566. },
  567. getPrototypeOf: function getPrototypeOf(state) {
  568. return Object.getPrototypeOf(state.base_);
  569. },
  570. setPrototypeOf: function setPrototypeOf() {
  571. die(12);
  572. }
  573. };
  574. /**
  575. * Array drafts
  576. */
  577. var arrayTraps = {};
  578. each(objectTraps, function (key, fn) {
  579. // @ts-ignore
  580. arrayTraps[key] = function () {
  581. arguments[0] = arguments[0][0];
  582. return fn.apply(this, arguments);
  583. };
  584. });
  585. arrayTraps.deleteProperty = function (state, prop) {
  586. if ( isNaN(parseInt(prop))) die(13); // @ts-ignore
  587. return arrayTraps.set.call(this, state, prop, undefined);
  588. };
  589. arrayTraps.set = function (state, prop, value) {
  590. if ( prop !== "length" && isNaN(parseInt(prop))) die(14);
  591. return objectTraps.set.call(this, state[0], prop, value, state[0]);
  592. }; // Access a property without creating an Immer draft.
  593. function peek(draft, prop) {
  594. var state = draft[DRAFT_STATE];
  595. var source = state ? latest(state) : draft;
  596. return source[prop];
  597. }
  598. function readPropFromProto(state, source, prop) {
  599. var _desc$get;
  600. var desc = getDescriptorFromProto(source, prop);
  601. return desc ? "value" in desc ? desc.value : // This is a very special case, if the prop is a getter defined by the
  602. // prototype, we should invoke it with the draft as context!
  603. (_desc$get = desc.get) === null || _desc$get === void 0 ? void 0 : _desc$get.call(state.draft_) : undefined;
  604. }
  605. function getDescriptorFromProto(source, prop) {
  606. // 'in' checks proto!
  607. if (!(prop in source)) return undefined;
  608. var proto = Object.getPrototypeOf(source);
  609. while (proto) {
  610. var desc = Object.getOwnPropertyDescriptor(proto, prop);
  611. if (desc) return desc;
  612. proto = Object.getPrototypeOf(proto);
  613. }
  614. return undefined;
  615. }
  616. function markChanged(state) {
  617. if (!state.modified_) {
  618. state.modified_ = true;
  619. if (state.parent_) {
  620. markChanged(state.parent_);
  621. }
  622. }
  623. }
  624. function prepareCopy(state) {
  625. if (!state.copy_) {
  626. state.copy_ = shallowCopy(state.base_);
  627. }
  628. }
  629. var Immer =
  630. /*#__PURE__*/
  631. function () {
  632. function Immer(config) {
  633. var _this = this;
  634. this.useProxies_ = hasProxies;
  635. this.autoFreeze_ = true;
  636. /**
  637. * The `produce` function takes a value and a "recipe function" (whose
  638. * return value often depends on the base state). The recipe function is
  639. * free to mutate its first argument however it wants. All mutations are
  640. * only ever applied to a __copy__ of the base state.
  641. *
  642. * Pass only a function to create a "curried producer" which relieves you
  643. * from passing the recipe function every time.
  644. *
  645. * Only plain objects and arrays are made mutable. All other objects are
  646. * considered uncopyable.
  647. *
  648. * Note: This function is __bound__ to its `Immer` instance.
  649. *
  650. * @param {any} base - the initial state
  651. * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
  652. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  653. * @returns {any} a new state, or the initial state if nothing was modified
  654. */
  655. this.produce = function (base, recipe, patchListener) {
  656. // curried invocation
  657. if (typeof base === "function" && typeof recipe !== "function") {
  658. var defaultBase = recipe;
  659. recipe = base;
  660. var self = _this;
  661. return function curriedProduce(base) {
  662. var _this2 = this;
  663. if (base === void 0) {
  664. base = defaultBase;
  665. }
  666. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  667. args[_key - 1] = arguments[_key];
  668. }
  669. return self.produce(base, function (draft) {
  670. var _recipe;
  671. return (_recipe = recipe).call.apply(_recipe, [_this2, draft].concat(args));
  672. }); // prettier-ignore
  673. };
  674. }
  675. if (typeof recipe !== "function") die(6);
  676. if (patchListener !== undefined && typeof patchListener !== "function") die(7);
  677. var result; // Only plain objects, arrays, and "immerable classes" are drafted.
  678. if (isDraftable(base)) {
  679. var scope = enterScope(_this);
  680. var proxy = createProxy(_this, base, undefined);
  681. var hasError = true;
  682. try {
  683. result = recipe(proxy);
  684. hasError = false;
  685. } finally {
  686. // finally instead of catch + rethrow better preserves original stack
  687. if (hasError) revokeScope(scope);else leaveScope(scope);
  688. }
  689. if (typeof Promise !== "undefined" && result instanceof Promise) {
  690. return result.then(function (result) {
  691. usePatchesInScope(scope, patchListener);
  692. return processResult(result, scope);
  693. }, function (error) {
  694. revokeScope(scope);
  695. throw error;
  696. });
  697. }
  698. usePatchesInScope(scope, patchListener);
  699. return processResult(result, scope);
  700. } else if (!base || typeof base !== "object") {
  701. result = recipe(base);
  702. if (result === undefined) result = base;
  703. if (result === NOTHING) result = undefined;
  704. if (_this.autoFreeze_) freeze(result, true);
  705. if (patchListener) {
  706. var p = [];
  707. var ip = [];
  708. getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
  709. patchListener(p, ip);
  710. }
  711. return result;
  712. } else die(21, base);
  713. };
  714. this.produceWithPatches = function (base, recipe) {
  715. // curried invocation
  716. if (typeof base === "function") {
  717. return function (state) {
  718. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  719. args[_key2 - 1] = arguments[_key2];
  720. }
  721. return _this.produceWithPatches(state, function (draft) {
  722. return base.apply(void 0, [draft].concat(args));
  723. });
  724. };
  725. }
  726. var patches, inversePatches;
  727. var result = _this.produce(base, recipe, function (p, ip) {
  728. patches = p;
  729. inversePatches = ip;
  730. });
  731. if (typeof Promise !== "undefined" && result instanceof Promise) {
  732. return result.then(function (nextState) {
  733. return [nextState, patches, inversePatches];
  734. });
  735. }
  736. return [result, patches, inversePatches];
  737. };
  738. if (typeof (config === null || config === void 0 ? void 0 : config.useProxies) === "boolean") this.setUseProxies(config.useProxies);
  739. if (typeof (config === null || config === void 0 ? void 0 : config.autoFreeze) === "boolean") this.setAutoFreeze(config.autoFreeze);
  740. }
  741. var _proto = Immer.prototype;
  742. _proto.createDraft = function createDraft(base) {
  743. if (!isDraftable(base)) die(8);
  744. if (isDraft(base)) base = current(base);
  745. var scope = enterScope(this);
  746. var proxy = createProxy(this, base, undefined);
  747. proxy[DRAFT_STATE].isManual_ = true;
  748. leaveScope(scope);
  749. return proxy;
  750. };
  751. _proto.finishDraft = function finishDraft(draft, patchListener) {
  752. var state = draft && draft[DRAFT_STATE];
  753. {
  754. if (!state || !state.isManual_) die(9);
  755. if (state.finalized_) die(10);
  756. }
  757. var scope = state.scope_;
  758. usePatchesInScope(scope, patchListener);
  759. return processResult(undefined, scope);
  760. }
  761. /**
  762. * Pass true to automatically freeze all copies created by Immer.
  763. *
  764. * By default, auto-freezing is enabled.
  765. */
  766. ;
  767. _proto.setAutoFreeze = function setAutoFreeze(value) {
  768. this.autoFreeze_ = value;
  769. }
  770. /**
  771. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  772. * always faster than using ES5 proxies.
  773. *
  774. * By default, feature detection is used, so calling this is rarely necessary.
  775. */
  776. ;
  777. _proto.setUseProxies = function setUseProxies(value) {
  778. if (value && !hasProxies) {
  779. die(20);
  780. }
  781. this.useProxies_ = value;
  782. };
  783. _proto.applyPatches = function applyPatches(base, patches) {
  784. // If a patch replaces the entire state, take that replacement as base
  785. // before applying patches
  786. var i;
  787. for (i = patches.length - 1; i >= 0; i--) {
  788. var patch = patches[i];
  789. if (patch.path.length === 0 && patch.op === "replace") {
  790. base = patch.value;
  791. break;
  792. }
  793. } // If there was a patch that replaced the entire state, start from the
  794. // patch after that.
  795. if (i > -1) {
  796. patches = patches.slice(i + 1);
  797. }
  798. var applyPatchesImpl = getPlugin("Patches").applyPatches_;
  799. if (isDraft(base)) {
  800. // N.B: never hits if some patch a replacement, patches are never drafts
  801. return applyPatchesImpl(base, patches);
  802. } // Otherwise, produce a copy of the base state.
  803. return this.produce(base, function (draft) {
  804. return applyPatchesImpl(draft, patches);
  805. });
  806. };
  807. return Immer;
  808. }();
  809. function createProxy(immer, value, parent) {
  810. // precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
  811. var draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : immer.useProxies_ ? createProxyProxy(value, parent) : getPlugin("ES5").createES5Proxy_(value, parent);
  812. var scope = parent ? parent.scope_ : getCurrentScope();
  813. scope.drafts_.push(draft);
  814. return draft;
  815. }
  816. function current(value) {
  817. if (!isDraft(value)) die(22, value);
  818. return currentImpl(value);
  819. }
  820. function currentImpl(value) {
  821. if (!isDraftable(value)) return value;
  822. var state = value[DRAFT_STATE];
  823. var copy;
  824. var archType = getArchtype(value);
  825. if (state) {
  826. if (!state.modified_ && (state.type_ < 4 || !getPlugin("ES5").hasChanges_(state))) return state.base_; // Optimization: avoid generating new drafts during copying
  827. state.finalized_ = true;
  828. copy = copyHelper(value, archType);
  829. state.finalized_ = false;
  830. } else {
  831. copy = copyHelper(value, archType);
  832. }
  833. each(copy, function (key, childValue) {
  834. if (state && get(state.base_, key) === childValue) return; // no need to copy or search in something that didn't change
  835. set(copy, key, currentImpl(childValue));
  836. }); // In the future, we might consider freezing here, based on the current settings
  837. return archType === 3
  838. /* Set */
  839. ? new Set(copy) : copy;
  840. }
  841. function copyHelper(value, archType) {
  842. // creates a shallow copy, even if it is a map or set
  843. switch (archType) {
  844. case 2
  845. /* Map */
  846. :
  847. return new Map(value);
  848. case 3
  849. /* Set */
  850. :
  851. // Set will be cloned as array temporarily, so that we can replace individual items
  852. return Array.from(value);
  853. }
  854. return shallowCopy(value);
  855. }
  856. function enableES5() {
  857. function willFinalizeES5_(scope, result, isReplaced) {
  858. if (!isReplaced) {
  859. if (scope.patches_) {
  860. markChangesRecursively(scope.drafts_[0]);
  861. } // This is faster when we don't care about which attributes changed.
  862. markChangesSweep(scope.drafts_);
  863. } // When a child draft is returned, look for changes.
  864. else if (isDraft(result) && result[DRAFT_STATE].scope_ === scope) {
  865. markChangesSweep(scope.drafts_);
  866. }
  867. }
  868. function createES5Draft(isArray, base) {
  869. if (isArray) {
  870. var draft = new Array(base.length);
  871. for (var i = 0; i < base.length; i++) {
  872. Object.defineProperty(draft, "" + i, proxyProperty(i, true));
  873. }
  874. return draft;
  875. } else {
  876. var _descriptors = getOwnPropertyDescriptors(base);
  877. delete _descriptors[DRAFT_STATE];
  878. var keys = ownKeys(_descriptors);
  879. for (var _i = 0; _i < keys.length; _i++) {
  880. var key = keys[_i];
  881. _descriptors[key] = proxyProperty(key, isArray || !!_descriptors[key].enumerable);
  882. }
  883. return Object.create(Object.getPrototypeOf(base), _descriptors);
  884. }
  885. }
  886. function createES5Proxy_(base, parent) {
  887. var isArray = Array.isArray(base);
  888. var draft = createES5Draft(isArray, base);
  889. var state = {
  890. type_: isArray ? 5
  891. /* ES5Array */
  892. : 4
  893. /* ES5Object */
  894. ,
  895. scope_: parent ? parent.scope_ : getCurrentScope(),
  896. modified_: false,
  897. finalized_: false,
  898. assigned_: {},
  899. parent_: parent,
  900. // base is the object we are drafting
  901. base_: base,
  902. // draft is the draft object itself, that traps all reads and reads from either the base (if unmodified) or copy (if modified)
  903. draft_: draft,
  904. copy_: null,
  905. revoked_: false,
  906. isManual_: false
  907. };
  908. Object.defineProperty(draft, DRAFT_STATE, {
  909. value: state,
  910. // enumerable: false <- the default
  911. writable: true
  912. });
  913. return draft;
  914. } // property descriptors are recycled to make sure we don't create a get and set closure per property,
  915. // but share them all instead
  916. var descriptors = {};
  917. function proxyProperty(prop, enumerable) {
  918. var desc = descriptors[prop];
  919. if (desc) {
  920. desc.enumerable = enumerable;
  921. } else {
  922. descriptors[prop] = desc = {
  923. configurable: true,
  924. enumerable: enumerable,
  925. get: function get() {
  926. var state = this[DRAFT_STATE];
  927. assertUnrevoked(state); // @ts-ignore
  928. return objectTraps.get(state, prop);
  929. },
  930. set: function set(value) {
  931. var state = this[DRAFT_STATE];
  932. assertUnrevoked(state); // @ts-ignore
  933. objectTraps.set(state, prop, value);
  934. }
  935. };
  936. }
  937. return desc;
  938. } // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
  939. function markChangesSweep(drafts) {
  940. // The natural order of drafts in the `scope` array is based on when they
  941. // were accessed. By processing drafts in reverse natural order, we have a
  942. // better chance of processing leaf nodes first. When a leaf node is known to
  943. // have changed, we can avoid any traversal of its ancestor nodes.
  944. for (var i = drafts.length - 1; i >= 0; i--) {
  945. var state = drafts[i][DRAFT_STATE];
  946. if (!state.modified_) {
  947. switch (state.type_) {
  948. case 5
  949. /* ES5Array */
  950. :
  951. if (hasArrayChanges(state)) markChanged(state);
  952. break;
  953. case 4
  954. /* ES5Object */
  955. :
  956. if (hasObjectChanges(state)) markChanged(state);
  957. break;
  958. }
  959. }
  960. }
  961. }
  962. function markChangesRecursively(object) {
  963. if (!object || typeof object !== "object") return;
  964. var state = object[DRAFT_STATE];
  965. if (!state) return;
  966. var base_ = state.base_,
  967. draft_ = state.draft_,
  968. assigned_ = state.assigned_,
  969. type_ = state.type_;
  970. if (type_ === 4
  971. /* ES5Object */
  972. ) {
  973. // Look for added keys.
  974. // probably there is a faster way to detect changes, as sweep + recurse seems to do some
  975. // unnecessary work.
  976. // also: probably we can store the information we detect here, to speed up tree finalization!
  977. each(draft_, function (key) {
  978. if (key === DRAFT_STATE) return; // The `undefined` check is a fast path for pre-existing keys.
  979. if (base_[key] === undefined && !has(base_, key)) {
  980. assigned_[key] = true;
  981. markChanged(state);
  982. } else if (!assigned_[key]) {
  983. // Only untouched properties trigger recursion.
  984. markChangesRecursively(draft_[key]);
  985. }
  986. }); // Look for removed keys.
  987. each(base_, function (key) {
  988. // The `undefined` check is a fast path for pre-existing keys.
  989. if (draft_[key] === undefined && !has(draft_, key)) {
  990. assigned_[key] = false;
  991. markChanged(state);
  992. }
  993. });
  994. } else if (type_ === 5
  995. /* ES5Array */
  996. ) {
  997. if (hasArrayChanges(state)) {
  998. markChanged(state);
  999. assigned_.length = true;
  1000. }
  1001. if (draft_.length < base_.length) {
  1002. for (var i = draft_.length; i < base_.length; i++) {
  1003. assigned_[i] = false;
  1004. }
  1005. } else {
  1006. for (var _i2 = base_.length; _i2 < draft_.length; _i2++) {
  1007. assigned_[_i2] = true;
  1008. }
  1009. } // Minimum count is enough, the other parts has been processed.
  1010. var min = Math.min(draft_.length, base_.length);
  1011. for (var _i3 = 0; _i3 < min; _i3++) {
  1012. // Only untouched indices trigger recursion.
  1013. if (!draft_.hasOwnProperty(_i3)) {
  1014. assigned_[_i3] = true;
  1015. }
  1016. if (assigned_[_i3] === undefined) markChangesRecursively(draft_[_i3]);
  1017. }
  1018. }
  1019. }
  1020. function hasObjectChanges(state) {
  1021. var base_ = state.base_,
  1022. draft_ = state.draft_; // Search for added keys and changed keys. Start at the back, because
  1023. // non-numeric keys are ordered by time of definition on the object.
  1024. var keys = ownKeys(draft_);
  1025. for (var i = keys.length - 1; i >= 0; i--) {
  1026. var key = keys[i];
  1027. if (key === DRAFT_STATE) continue;
  1028. var baseValue = base_[key]; // The `undefined` check is a fast path for pre-existing keys.
  1029. if (baseValue === undefined && !has(base_, key)) {
  1030. return true;
  1031. } // Once a base key is deleted, future changes go undetected, because its
  1032. // descriptor is erased. This branch detects any missed changes.
  1033. else {
  1034. var value = draft_[key];
  1035. var _state = value && value[DRAFT_STATE];
  1036. if (_state ? _state.base_ !== baseValue : !is(value, baseValue)) {
  1037. return true;
  1038. }
  1039. }
  1040. } // At this point, no keys were added or changed.
  1041. // Compare key count to determine if keys were deleted.
  1042. var baseIsDraft = !!base_[DRAFT_STATE];
  1043. return keys.length !== ownKeys(base_).length + (baseIsDraft ? 0 : 1); // + 1 to correct for DRAFT_STATE
  1044. }
  1045. function hasArrayChanges(state) {
  1046. var draft_ = state.draft_;
  1047. if (draft_.length !== state.base_.length) return true; // See #116
  1048. // If we first shorten the length, our array interceptors will be removed.
  1049. // If after that new items are added, result in the same original length,
  1050. // those last items will have no intercepting property.
  1051. // So if there is no own descriptor on the last position, we know that items were removed and added
  1052. // N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
  1053. // the last one
  1054. // last descriptor can be not a trap, if the array was extended
  1055. var descriptor = Object.getOwnPropertyDescriptor(draft_, draft_.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
  1056. if (descriptor && !descriptor.get) return true; // if we miss a property, it has been deleted, so array probobaly changed
  1057. for (var i = 0; i < draft_.length; i++) {
  1058. if (!draft_.hasOwnProperty(i)) return true;
  1059. } // For all other cases, we don't have to compare, as they would have been picked up by the index setters
  1060. return false;
  1061. }
  1062. function hasChanges_(state) {
  1063. return state.type_ === 4
  1064. /* ES5Object */
  1065. ? hasObjectChanges(state) : hasArrayChanges(state);
  1066. }
  1067. function assertUnrevoked(state
  1068. /*ES5State | MapState | SetState*/
  1069. ) {
  1070. if (state.revoked_) die(3, JSON.stringify(latest(state)));
  1071. }
  1072. loadPlugin("ES5", {
  1073. createES5Proxy_: createES5Proxy_,
  1074. willFinalizeES5_: willFinalizeES5_,
  1075. hasChanges_: hasChanges_
  1076. });
  1077. }
  1078. function enablePatches() {
  1079. var REPLACE = "replace";
  1080. var ADD = "add";
  1081. var REMOVE = "remove";
  1082. function generatePatches_(state, basePath, patches, inversePatches) {
  1083. switch (state.type_) {
  1084. case 0
  1085. /* ProxyObject */
  1086. :
  1087. case 4
  1088. /* ES5Object */
  1089. :
  1090. case 2
  1091. /* Map */
  1092. :
  1093. return generatePatchesFromAssigned(state, basePath, patches, inversePatches);
  1094. case 5
  1095. /* ES5Array */
  1096. :
  1097. case 1
  1098. /* ProxyArray */
  1099. :
  1100. return generateArrayPatches(state, basePath, patches, inversePatches);
  1101. case 3
  1102. /* Set */
  1103. :
  1104. return generateSetPatches(state, basePath, patches, inversePatches);
  1105. }
  1106. }
  1107. function generateArrayPatches(state, basePath, patches, inversePatches) {
  1108. var base_ = state.base_,
  1109. assigned_ = state.assigned_;
  1110. var copy_ = state.copy_; // Reduce complexity by ensuring `base` is never longer.
  1111. if (copy_.length < base_.length) {
  1112. var _ref = [copy_, base_];
  1113. base_ = _ref[0];
  1114. copy_ = _ref[1];
  1115. var _ref2 = [inversePatches, patches];
  1116. patches = _ref2[0];
  1117. inversePatches = _ref2[1];
  1118. } // Process replaced indices.
  1119. for (var i = 0; i < base_.length; i++) {
  1120. if (assigned_[i] && copy_[i] !== base_[i]) {
  1121. var path = basePath.concat([i]);
  1122. patches.push({
  1123. op: REPLACE,
  1124. path: path,
  1125. // Need to maybe clone it, as it can in fact be the original value
  1126. // due to the base/copy inversion at the start of this function
  1127. value: clonePatchValueIfNeeded(copy_[i])
  1128. });
  1129. inversePatches.push({
  1130. op: REPLACE,
  1131. path: path,
  1132. value: clonePatchValueIfNeeded(base_[i])
  1133. });
  1134. }
  1135. } // Process added indices.
  1136. for (var _i = base_.length; _i < copy_.length; _i++) {
  1137. var _path = basePath.concat([_i]);
  1138. patches.push({
  1139. op: ADD,
  1140. path: _path,
  1141. // Need to maybe clone it, as it can in fact be the original value
  1142. // due to the base/copy inversion at the start of this function
  1143. value: clonePatchValueIfNeeded(copy_[_i])
  1144. });
  1145. }
  1146. if (base_.length < copy_.length) {
  1147. inversePatches.push({
  1148. op: REPLACE,
  1149. path: basePath.concat(["length"]),
  1150. value: base_.length
  1151. });
  1152. }
  1153. } // This is used for both Map objects and normal objects.
  1154. function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
  1155. var base_ = state.base_,
  1156. copy_ = state.copy_;
  1157. each(state.assigned_, function (key, assignedValue) {
  1158. var origValue = get(base_, key);
  1159. var value = get(copy_, key);
  1160. var op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;
  1161. if (origValue === value && op === REPLACE) return;
  1162. var path = basePath.concat(key);
  1163. patches.push(op === REMOVE ? {
  1164. op: op,
  1165. path: path
  1166. } : {
  1167. op: op,
  1168. path: path,
  1169. value: value
  1170. });
  1171. inversePatches.push(op === ADD ? {
  1172. op: REMOVE,
  1173. path: path
  1174. } : op === REMOVE ? {
  1175. op: ADD,
  1176. path: path,
  1177. value: clonePatchValueIfNeeded(origValue)
  1178. } : {
  1179. op: REPLACE,
  1180. path: path,
  1181. value: clonePatchValueIfNeeded(origValue)
  1182. });
  1183. });
  1184. }
  1185. function generateSetPatches(state, basePath, patches, inversePatches) {
  1186. var base_ = state.base_,
  1187. copy_ = state.copy_;
  1188. var i = 0;
  1189. base_.forEach(function (value) {
  1190. if (!copy_.has(value)) {
  1191. var path = basePath.concat([i]);
  1192. patches.push({
  1193. op: REMOVE,
  1194. path: path,
  1195. value: value
  1196. });
  1197. inversePatches.unshift({
  1198. op: ADD,
  1199. path: path,
  1200. value: value
  1201. });
  1202. }
  1203. i++;
  1204. });
  1205. i = 0;
  1206. copy_.forEach(function (value) {
  1207. if (!base_.has(value)) {
  1208. var path = basePath.concat([i]);
  1209. patches.push({
  1210. op: ADD,
  1211. path: path,
  1212. value: value
  1213. });
  1214. inversePatches.unshift({
  1215. op: REMOVE,
  1216. path: path,
  1217. value: value
  1218. });
  1219. }
  1220. i++;
  1221. });
  1222. }
  1223. function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {
  1224. patches.push({
  1225. op: REPLACE,
  1226. path: [],
  1227. value: replacement === NOTHING ? undefined : replacement
  1228. });
  1229. inversePatches.push({
  1230. op: REPLACE,
  1231. path: [],
  1232. value: baseValue
  1233. });
  1234. }
  1235. function applyPatches_(draft, patches) {
  1236. patches.forEach(function (patch) {
  1237. var path = patch.path,
  1238. op = patch.op;
  1239. var base = draft;
  1240. for (var i = 0; i < path.length - 1; i++) {
  1241. var parentType = getArchtype(base);
  1242. var p = path[i];
  1243. if (typeof p !== "string" && typeof p !== "number") {
  1244. p = "" + p;
  1245. } // See #738, avoid prototype pollution
  1246. if ((parentType === 0
  1247. /* Object */
  1248. || parentType === 1
  1249. /* Array */
  1250. ) && (p === "__proto__" || p === "constructor")) die(24);
  1251. if (typeof base === "function" && p === "prototype") die(24);
  1252. base = get(base, p);
  1253. if (typeof base !== "object") die(15, path.join("/"));
  1254. }
  1255. var type = getArchtype(base);
  1256. var value = deepClonePatchValue(patch.value); // used to clone patch to ensure original patch is not modified, see #411
  1257. var key = path[path.length - 1];
  1258. switch (op) {
  1259. case REPLACE:
  1260. switch (type) {
  1261. case 2
  1262. /* Map */
  1263. :
  1264. return base.set(key, value);
  1265. /* istanbul ignore next */
  1266. case 3
  1267. /* Set */
  1268. :
  1269. die(16);
  1270. default:
  1271. // if value is an object, then it's assigned by reference
  1272. // in the following add or remove ops, the value field inside the patch will also be modifyed
  1273. // so we use value from the cloned patch
  1274. // @ts-ignore
  1275. return base[key] = value;
  1276. }
  1277. case ADD:
  1278. switch (type) {
  1279. case 1
  1280. /* Array */
  1281. :
  1282. return key === "-" ? base.push(value) : base.splice(key, 0, value);
  1283. case 2
  1284. /* Map */
  1285. :
  1286. return base.set(key, value);
  1287. case 3
  1288. /* Set */
  1289. :
  1290. return base.add(value);
  1291. default:
  1292. return base[key] = value;
  1293. }
  1294. case REMOVE:
  1295. switch (type) {
  1296. case 1
  1297. /* Array */
  1298. :
  1299. return base.splice(key, 1);
  1300. case 2
  1301. /* Map */
  1302. :
  1303. return base.delete(key);
  1304. case 3
  1305. /* Set */
  1306. :
  1307. return base.delete(patch.value);
  1308. default:
  1309. return delete base[key];
  1310. }
  1311. default:
  1312. die(17, op);
  1313. }
  1314. });
  1315. return draft;
  1316. }
  1317. function deepClonePatchValue(obj) {
  1318. if (!isDraftable(obj)) return obj;
  1319. if (Array.isArray(obj)) return obj.map(deepClonePatchValue);
  1320. if (isMap(obj)) return new Map(Array.from(obj.entries()).map(function (_ref3) {
  1321. var k = _ref3[0],
  1322. v = _ref3[1];
  1323. return [k, deepClonePatchValue(v)];
  1324. }));
  1325. if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue));
  1326. var cloned = Object.create(Object.getPrototypeOf(obj));
  1327. for (var key in obj) {
  1328. cloned[key] = deepClonePatchValue(obj[key]);
  1329. }
  1330. if (has(obj, DRAFTABLE)) cloned[DRAFTABLE] = obj[DRAFTABLE];
  1331. return cloned;
  1332. }
  1333. function clonePatchValueIfNeeded(obj) {
  1334. if (isDraft(obj)) {
  1335. return deepClonePatchValue(obj);
  1336. } else return obj;
  1337. }
  1338. loadPlugin("Patches", {
  1339. applyPatches_: applyPatches_,
  1340. generatePatches_: generatePatches_,
  1341. generateReplacementPatches_: generateReplacementPatches_
  1342. });
  1343. }
  1344. // types only!
  1345. function enableMapSet() {
  1346. /* istanbul ignore next */
  1347. var _extendStatics = function extendStatics(d, b) {
  1348. _extendStatics = Object.setPrototypeOf || {
  1349. __proto__: []
  1350. } instanceof Array && function (d, b) {
  1351. d.__proto__ = b;
  1352. } || function (d, b) {
  1353. for (var p in b) {
  1354. if (b.hasOwnProperty(p)) d[p] = b[p];
  1355. }
  1356. };
  1357. return _extendStatics(d, b);
  1358. }; // Ugly hack to resolve #502 and inherit built in Map / Set
  1359. function __extends(d, b) {
  1360. _extendStatics(d, b);
  1361. function __() {
  1362. this.constructor = d;
  1363. }
  1364. d.prototype = ( // @ts-ignore
  1365. __.prototype = b.prototype, new __());
  1366. }
  1367. var DraftMap = function (_super) {
  1368. __extends(DraftMap, _super); // Create class manually, cause #502
  1369. function DraftMap(target, parent) {
  1370. this[DRAFT_STATE] = {
  1371. type_: 2
  1372. /* Map */
  1373. ,
  1374. parent_: parent,
  1375. scope_: parent ? parent.scope_ : getCurrentScope(),
  1376. modified_: false,
  1377. finalized_: false,
  1378. copy_: undefined,
  1379. assigned_: undefined,
  1380. base_: target,
  1381. draft_: this,
  1382. isManual_: false,
  1383. revoked_: false
  1384. };
  1385. return this;
  1386. }
  1387. var p = DraftMap.prototype;
  1388. Object.defineProperty(p, "size", {
  1389. get: function get() {
  1390. return latest(this[DRAFT_STATE]).size;
  1391. } // enumerable: false,
  1392. // configurable: true
  1393. });
  1394. p.has = function (key) {
  1395. return latest(this[DRAFT_STATE]).has(key);
  1396. };
  1397. p.set = function (key, value) {
  1398. var state = this[DRAFT_STATE];
  1399. assertUnrevoked(state);
  1400. if (!latest(state).has(key) || latest(state).get(key) !== value) {
  1401. prepareMapCopy(state);
  1402. markChanged(state);
  1403. state.assigned_.set(key, true);
  1404. state.copy_.set(key, value);
  1405. state.assigned_.set(key, true);
  1406. }
  1407. return this;
  1408. };
  1409. p.delete = function (key) {
  1410. if (!this.has(key)) {
  1411. return false;
  1412. }
  1413. var state = this[DRAFT_STATE];
  1414. assertUnrevoked(state);
  1415. prepareMapCopy(state);
  1416. markChanged(state);
  1417. if (state.base_.has(key)) {
  1418. state.assigned_.set(key, false);
  1419. } else {
  1420. state.assigned_.delete(key);
  1421. }
  1422. state.copy_.delete(key);
  1423. return true;
  1424. };
  1425. p.clear = function () {
  1426. var state = this[DRAFT_STATE];
  1427. assertUnrevoked(state);
  1428. if (latest(state).size) {
  1429. prepareMapCopy(state);
  1430. markChanged(state);
  1431. state.assigned_ = new Map();
  1432. each(state.base_, function (key) {
  1433. state.assigned_.set(key, false);
  1434. });
  1435. state.copy_.clear();
  1436. }
  1437. };
  1438. p.forEach = function (cb, thisArg) {
  1439. var _this = this;
  1440. var state = this[DRAFT_STATE];
  1441. latest(state).forEach(function (_value, key, _map) {
  1442. cb.call(thisArg, _this.get(key), key, _this);
  1443. });
  1444. };
  1445. p.get = function (key) {
  1446. var state = this[DRAFT_STATE];
  1447. assertUnrevoked(state);
  1448. var value = latest(state).get(key);
  1449. if (state.finalized_ || !isDraftable(value)) {
  1450. return value;
  1451. }
  1452. if (value !== state.base_.get(key)) {
  1453. return value; // either already drafted or reassigned
  1454. } // despite what it looks, this creates a draft only once, see above condition
  1455. var draft = createProxy(state.scope_.immer_, value, state);
  1456. prepareMapCopy(state);
  1457. state.copy_.set(key, draft);
  1458. return draft;
  1459. };
  1460. p.keys = function () {
  1461. return latest(this[DRAFT_STATE]).keys();
  1462. };
  1463. p.values = function () {
  1464. var _this2 = this,
  1465. _ref;
  1466. var iterator = this.keys();
  1467. return _ref = {}, _ref[iteratorSymbol] = function () {
  1468. return _this2.values();
  1469. }, _ref.next = function next() {
  1470. var r = iterator.next();
  1471. /* istanbul ignore next */
  1472. if (r.done) return r;
  1473. var value = _this2.get(r.value);
  1474. return {
  1475. done: false,
  1476. value: value
  1477. };
  1478. }, _ref;
  1479. };
  1480. p.entries = function () {
  1481. var _this3 = this,
  1482. _ref2;
  1483. var iterator = this.keys();
  1484. return _ref2 = {}, _ref2[iteratorSymbol] = function () {
  1485. return _this3.entries();
  1486. }, _ref2.next = function next() {
  1487. var r = iterator.next();
  1488. /* istanbul ignore next */
  1489. if (r.done) return r;
  1490. var value = _this3.get(r.value);
  1491. return {
  1492. done: false,
  1493. value: [r.value, value]
  1494. };
  1495. }, _ref2;
  1496. };
  1497. p[iteratorSymbol] = function () {
  1498. return this.entries();
  1499. };
  1500. return DraftMap;
  1501. }(Map);
  1502. function proxyMap_(target, parent) {
  1503. // @ts-ignore
  1504. return new DraftMap(target, parent);
  1505. }
  1506. function prepareMapCopy(state) {
  1507. if (!state.copy_) {
  1508. state.assigned_ = new Map();
  1509. state.copy_ = new Map(state.base_);
  1510. }
  1511. }
  1512. var DraftSet = function (_super) {
  1513. __extends(DraftSet, _super); // Create class manually, cause #502
  1514. function DraftSet(target, parent) {
  1515. this[DRAFT_STATE] = {
  1516. type_: 3
  1517. /* Set */
  1518. ,
  1519. parent_: parent,
  1520. scope_: parent ? parent.scope_ : getCurrentScope(),
  1521. modified_: false,
  1522. finalized_: false,
  1523. copy_: undefined,
  1524. base_: target,
  1525. draft_: this,
  1526. drafts_: new Map(),
  1527. revoked_: false,
  1528. isManual_: false
  1529. };
  1530. return this;
  1531. }
  1532. var p = DraftSet.prototype;
  1533. Object.defineProperty(p, "size", {
  1534. get: function get() {
  1535. return latest(this[DRAFT_STATE]).size;
  1536. } // enumerable: true,
  1537. });
  1538. p.has = function (value) {
  1539. var state = this[DRAFT_STATE];
  1540. assertUnrevoked(state); // bit of trickery here, to be able to recognize both the value, and the draft of its value
  1541. if (!state.copy_) {
  1542. return state.base_.has(value);
  1543. }
  1544. if (state.copy_.has(value)) return true;
  1545. if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true;
  1546. return false;
  1547. };
  1548. p.add = function (value) {
  1549. var state = this[DRAFT_STATE];
  1550. assertUnrevoked(state);
  1551. if (!this.has(value)) {
  1552. prepareSetCopy(state);
  1553. markChanged(state);
  1554. state.copy_.add(value);
  1555. }
  1556. return this;
  1557. };
  1558. p.delete = function (value) {
  1559. if (!this.has(value)) {
  1560. return false;
  1561. }
  1562. var state = this[DRAFT_STATE];
  1563. assertUnrevoked(state);
  1564. prepareSetCopy(state);
  1565. markChanged(state);
  1566. return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) :
  1567. /* istanbul ignore next */
  1568. false);
  1569. };
  1570. p.clear = function () {
  1571. var state = this[DRAFT_STATE];
  1572. assertUnrevoked(state);
  1573. if (latest(state).size) {
  1574. prepareSetCopy(state);
  1575. markChanged(state);
  1576. state.copy_.clear();
  1577. }
  1578. };
  1579. p.values = function () {
  1580. var state = this[DRAFT_STATE];
  1581. assertUnrevoked(state);
  1582. prepareSetCopy(state);
  1583. return state.copy_.values();
  1584. };
  1585. p.entries = function entries() {
  1586. var state = this[DRAFT_STATE];
  1587. assertUnrevoked(state);
  1588. prepareSetCopy(state);
  1589. return state.copy_.entries();
  1590. };
  1591. p.keys = function () {
  1592. return this.values();
  1593. };
  1594. p[iteratorSymbol] = function () {
  1595. return this.values();
  1596. };
  1597. p.forEach = function forEach(cb, thisArg) {
  1598. var iterator = this.values();
  1599. var result = iterator.next();
  1600. while (!result.done) {
  1601. cb.call(thisArg, result.value, result.value, this);
  1602. result = iterator.next();
  1603. }
  1604. };
  1605. return DraftSet;
  1606. }(Set);
  1607. function proxySet_(target, parent) {
  1608. // @ts-ignore
  1609. return new DraftSet(target, parent);
  1610. }
  1611. function prepareSetCopy(state) {
  1612. if (!state.copy_) {
  1613. // create drafts for all entries to preserve insertion order
  1614. state.copy_ = new Set();
  1615. state.base_.forEach(function (value) {
  1616. if (isDraftable(value)) {
  1617. var draft = createProxy(state.scope_.immer_, value, state);
  1618. state.drafts_.set(value, draft);
  1619. state.copy_.add(draft);
  1620. } else {
  1621. state.copy_.add(value);
  1622. }
  1623. });
  1624. }
  1625. }
  1626. function assertUnrevoked(state
  1627. /*ES5State | MapState | SetState*/
  1628. ) {
  1629. if (state.revoked_) die(3, JSON.stringify(latest(state)));
  1630. }
  1631. loadPlugin("MapSet", {
  1632. proxyMap_: proxyMap_,
  1633. proxySet_: proxySet_
  1634. });
  1635. }
  1636. function enableAllPlugins() {
  1637. enableES5();
  1638. enableMapSet();
  1639. enablePatches();
  1640. }
  1641. var immer =
  1642. /*#__PURE__*/
  1643. new Immer();
  1644. /**
  1645. * The `produce` function takes a value and a "recipe function" (whose
  1646. * return value often depends on the base state). The recipe function is
  1647. * free to mutate its first argument however it wants. All mutations are
  1648. * only ever applied to a __copy__ of the base state.
  1649. *
  1650. * Pass only a function to create a "curried producer" which relieves you
  1651. * from passing the recipe function every time.
  1652. *
  1653. * Only plain objects and arrays are made mutable. All other objects are
  1654. * considered uncopyable.
  1655. *
  1656. * Note: This function is __bound__ to its `Immer` instance.
  1657. *
  1658. * @param {any} base - the initial state
  1659. * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
  1660. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  1661. * @returns {any} a new state, or the initial state if nothing was modified
  1662. */
  1663. var produce = immer.produce;
  1664. /**
  1665. * Like `produce`, but `produceWithPatches` always returns a tuple
  1666. * [nextState, patches, inversePatches] (instead of just the next state)
  1667. */
  1668. var produceWithPatches =
  1669. /*#__PURE__*/
  1670. immer.produceWithPatches.bind(immer);
  1671. /**
  1672. * Pass true to automatically freeze all copies created by Immer.
  1673. *
  1674. * Always freeze by default, even in production mode
  1675. */
  1676. var setAutoFreeze =
  1677. /*#__PURE__*/
  1678. immer.setAutoFreeze.bind(immer);
  1679. /**
  1680. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  1681. * always faster than using ES5 proxies.
  1682. *
  1683. * By default, feature detection is used, so calling this is rarely necessary.
  1684. */
  1685. var setUseProxies =
  1686. /*#__PURE__*/
  1687. immer.setUseProxies.bind(immer);
  1688. /**
  1689. * Apply an array of Immer patches to the first argument.
  1690. *
  1691. * This function is a producer, which means copy-on-write is in effect.
  1692. */
  1693. var applyPatches =
  1694. /*#__PURE__*/
  1695. immer.applyPatches.bind(immer);
  1696. /**
  1697. * Create an Immer draft from the given base state, which may be a draft itself.
  1698. * The draft can be modified until you finalize it with the `finishDraft` function.
  1699. */
  1700. var createDraft =
  1701. /*#__PURE__*/
  1702. immer.createDraft.bind(immer);
  1703. /**
  1704. * Finalize an Immer draft from a `createDraft` call, returning the base state
  1705. * (if no changes were made) or a modified copy. The draft must *not* be
  1706. * mutated afterwards.
  1707. *
  1708. * Pass a function as the 2nd argument to generate Immer patches based on the
  1709. * changes that were made.
  1710. */
  1711. var finishDraft =
  1712. /*#__PURE__*/
  1713. immer.finishDraft.bind(immer);
  1714. /**
  1715. * This function is actually a no-op, but can be used to cast an immutable type
  1716. * to an draft type and make TypeScript happy
  1717. *
  1718. * @param value
  1719. */
  1720. function castDraft(value) {
  1721. return value;
  1722. }
  1723. /**
  1724. * This function is actually a no-op, but can be used to cast a mutable type
  1725. * to an immutable type and make TypeScript happy
  1726. * @param value
  1727. */
  1728. function castImmutable(value) {
  1729. return value;
  1730. }
  1731. exports.Immer = Immer;
  1732. exports.applyPatches = applyPatches;
  1733. exports.castDraft = castDraft;
  1734. exports.castImmutable = castImmutable;
  1735. exports.createDraft = createDraft;
  1736. exports.current = current;
  1737. exports.default = produce;
  1738. exports.enableAllPlugins = enableAllPlugins;
  1739. exports.enableES5 = enableES5;
  1740. exports.enableMapSet = enableMapSet;
  1741. exports.enablePatches = enablePatches;
  1742. exports.finishDraft = finishDraft;
  1743. exports.freeze = freeze;
  1744. exports.immerable = DRAFTABLE;
  1745. exports.isDraft = isDraft;
  1746. exports.isDraftable = isDraftable;
  1747. exports.nothing = NOTHING;
  1748. exports.original = original;
  1749. exports.produce = produce;
  1750. exports.produceWithPatches = produceWithPatches;
  1751. exports.setAutoFreeze = setAutoFreeze;
  1752. exports.setUseProxies = setUseProxies;
  1753. Object.defineProperty(exports, '__esModule', { value: true });
  1754. })));
  1755. //# sourceMappingURL=immer.umd.development.js.map