Comparing version 1.11.0 to 1.11.1
@@ -98,5 +98,5 @@ 'use strict'; | ||
var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : function (obj) { | ||
var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) { | ||
return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)); | ||
}; | ||
} : Object.getOwnPropertyNames; | ||
@@ -103,0 +103,0 @@ function shallowCopy(base) { |
@@ -94,5 +94,5 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : function (obj) { | ||
var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) { | ||
return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)); | ||
}; | ||
} : Object.getOwnPropertyNames; | ||
@@ -99,0 +99,0 @@ function shallowCopy(base) { |
@@ -1,2 +0,2 @@ | ||
var e,r;e=this,r=function(e){"use strict";var r,t,n,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},a=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),f="undefined"!=typeof Symbol?Symbol("immer-nothing"):(n=!0,(t="immer-nothing")in(r={})?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r),u="undefined"!=typeof Symbol?Symbol("immer-draftable"):"__$immer_draftable",c="undefined"!=typeof Symbol?Symbol("immer-state"):"__$immer_state";function s(e){return!!e&&!!e[c]}function l(e){if(!e||"object"!==(void 0===e?"undefined":o(e)))return!1;if(Array.isArray(e))return!0;var r=Object.getPrototypeOf(e);return!r||r===Object.prototype||(!!e[u]||!!e.constructor[u])}var p=Object.assign||function(e,r){for(var t in r)b(r,t)&&(e[t]=r[t]);return e},d="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))};function h(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(Array.isArray(e))return e.slice();var t=Object.create(Object.getPrototypeOf(e));return d(e).forEach(function(n){if(n!==c){var o=Object.getOwnPropertyDescriptor(e,n);if(o.get){if(!r)throw new Error("Immer drafts cannot have computed properties");o.value=o.get.call(e)}o.enumerable?t[n]=o.value:Object.defineProperty(t,n,{value:o.value,writable:!0,configurable:!0})}}),t}function y(e,r){if(Array.isArray(e))for(var t=0;t<e.length;t++)r(t,e[t],e);else d(e).forEach(function(t){return r(t,e[t],e)})}function v(e,r){return Object.getOwnPropertyDescriptor(e,r).enumerable}function b(e,r){return Object.prototype.hasOwnProperty.call(e,r)}function g(e,r){return e===r?0!==e||1/e==1/r:e!=e&&r!=r}function m(e,r,t,n){Array.isArray(e.base)?function(e,r,t,n){for(var o=e.base,i=e.copy,a=e.assigned,f=Math.min(o.length,i.length),u=0;u<f;u++)if(a[u]&&o[u]!==i[u]){var c=r.concat(u);t.push({op:"replace",path:c,value:i[u]}),n.push({op:"replace",path:c,value:o[u]})}if(f<i.length){for(var s=f;s<i.length;s++)t.push({op:"add",path:r.concat(s),value:i[s]});n.push({op:"replace",path:r.concat("length"),value:o.length})}else if(f<o.length){t.push({op:"replace",path:r.concat("length"),value:i.length});for(var l=f;l<o.length;l++)n.push({op:"add",path:r.concat(l),value:o[l]})}}(e,r,t,n):function(e,r,t,n){var o=e.base,i=e.copy;y(e.assigned,function(e,a){var f=o[e],u=i[e],c=a?e in o?"replace":"add":"remove";if(f!==u||"replace"!==c){var s=r.concat(e);t.push("remove"===c?{op:c,path:s}:{op:c,path:s,value:u}),n.push("add"===c?{op:"remove",path:s}:"remove"===c?{op:"add",path:s,value:f}:{op:"replace",path:s,value:f})}})}(e,r,t,n)}var w={},O=[],P=function(){return O[O.length-1]};function j(e,r){var t=Array.isArray(e),n=x(e);y(n,function(r){!function(e,r,t){var n=w[r];n?n.enumerable=t:w[r]=n={configurable:!0,enumerable:t,get:function(){return function(e,r){S(e);var t=A(e)[r];if(!e.finalizing&&t===e.base[r]&&l(t))return k(e),e.copy[r]=j(t,e);return t}(this[c],r)},set:function(e){!function(e,r,t){if(S(e),e.assigned[r]=!0,!e.modified){if(g(A(e)[r],t))return;E(e),k(e)}e.copy[r]=t}(this[c],r,e)}};Object.defineProperty(e,r,n)}(n,r,t||v(e,r))});var o,i,a,f={scope:r?r.scope:P(),modified:!1,finalizing:!1,finalized:!1,assigned:{},parent:r,base:e,draft:n,copy:null,revoke:z,revoked:!1};return o=n,i=c,a=f,Object.defineProperty(o,i,{value:a,enumerable:!1,writable:!0}),f.scope.push(f),n}function z(){this.revoked=!0}function A(e){return e.copy||e.base}function E(e){e.modified||(e.modified=!0,e.parent&&E(e.parent))}function k(e){e.copy||(e.copy=x(e.base))}function x(e){var r=e&&e[c];if(r){r.finalizing=!0;var t=h(r.draft,!0);return r.finalizing=!1,t}return h(e)}function S(e){if(!0===e.revoked)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(A(e)))}function D(e){for(var r=e.base,t=e.draft,n=Object.keys(t),o=n.length-1;o>=0;o--)if(void 0===r[n[o]]&&!b(r,n[o]))return!0;return n.length!==Object.keys(r).length}function F(e){var r=e.draft;if(r.length!==e.base.length)return!0;var t=Object.getOwnPropertyDescriptor(r,r.length-1);return!(!t||t.get)}var I=Object.freeze({scopes:O,currentScope:P,willFinalize:function(e,r,t){var n=P();n.forEach(function(e){return e.finalizing=!0}),void 0!==e&&e!==r||(t&&function e(r){if(r&&"object"===(void 0===r?"undefined":o(r))){var t=r[c];if(t){var n=t.base,i=t.draft,a=t.assigned;if(Array.isArray(r)){if(F(t)){if(E(t),a.length=!0,i.length<n.length)for(var f=i.length;f<n.length;f++)a[f]=!1;else for(var u=n.length;u<i.length;u++)a[u]=!0;for(var s=0;s<i.length;s++)void 0===a[s]&&e(i[s])}}else Object.keys(i).forEach(function(r){void 0!==n[r]||b(n,r)?a[r]||e(i[r]):(a[r]=!0,E(t))}),Object.keys(n).forEach(function(e){void 0!==i[e]||b(i,e)||(a[e]=!1,E(t))})}}}(r),function(e){for(var r=e.length-1;r>=0;r--){var t=e[r];!1===t.modified&&(Array.isArray(t.base)?F(t)&&E(t):D(t)&&E(t))}}(n))},createDraft:j}),_=[],N=function(){return _[_.length-1]};function C(e,r){var t={scope:r?r.scope:N(),modified:!1,finalized:!1,assigned:{},parent:r,base:e,draft:null,drafts:{},copy:null,revoke:null},n=Array.isArray(e)?Proxy.revocable([t],U):Proxy.revocable(t,R),o=n.revoke,i=n.proxy;return t.draft=i,t.revoke=o,t.scope.push(t),i}var R={get:function(e,r){if(r===c)return e;var t=e.drafts;if(!e.modified&&b(t,r))return t[r];var n=K(e)[r];if(e.finalized||!l(n))return n;if(e.modified){if(n!==e.base[r])return n;t=e.copy}return t[r]=C(n,e)},has:function(e,r){return r in K(e)},ownKeys:function(e){return Reflect.ownKeys(K(e))},set:function(e,r,t){if(!e.modified){var n=t?g(e.base[r],t)||t===e.drafts[r]:g(e.base[r],t)&&r in e.base;if(n)return!0;T(e)}return e.assigned[r]=!0,e.copy[r]=t,!0},deleteProperty:function(e,r){(void 0!==e.base[r]||r in e.base)&&(e.assigned[r]=!1,T(e));e.copy&&delete e.copy[r];return!0},getOwnPropertyDescriptor:function(e,r){var t=K(e),n=Reflect.getOwnPropertyDescriptor(t,r);n&&(n.writable=!0,n.configurable=!Array.isArray(t)||"length"!==r);return n},defineProperty:function(){throw new Error("Object.defineProperty() cannot be used on an Immer draft")},getPrototypeOf:function(e){return Object.getPrototypeOf(e.base)},setPrototypeOf:function(){throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft")}},U={};function K(e){return e.copy||e.base}function T(e){e.modified||(e.modified=!0,e.copy=p(h(e.base),e.drafts),e.drafts=null,e.parent&&T(e.parent))}y(R,function(e,r){U[e]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}}),U.deleteProperty=function(e,r){if(isNaN(parseInt(r)))throw new Error("Immer only supports deleting array indices");return R.deleteProperty.call(this,e[0],r)},U.set=function(e,r,t){if("length"!==r&&isNaN(parseInt(r)))throw new Error("Immer only supports setting array indices and the 'length' property");return R.set.call(this,e[0],r,t)};var M=Object.freeze({scopes:_,currentScope:N,willFinalize:function(){},createDraft:C});var $={useProxies:"undefined"!=typeof Proxy&&"undefined"!=typeof Reflect,autoFreeze:"undefined"!=typeof process?"production"!==process.env.NODE_ENV:"verifyMinified"===function(){}.name,onAssign:null,onDelete:null,onCopy:null},J=function(){function e(r){i(this,e),p(this,$,r),this.setUseProxies(this.useProxies),this.produce=this.produce.bind(this)}return a(e,[{key:"produce",value:function(e,r,t){var n=this;if("function"==typeof e&&"function"!=typeof r){var o=r;return r=e,function(){for(var e=arguments.length,t=Array(e>1?e-1:0),i=1;i<e;i++)t[i-1]=arguments[i];var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o;return n.produce(a,function(e){var n;return(n=r).call.apply(n,[e,e].concat(t))})}}if("function"!=typeof r)throw new Error("if first argument is not a function, the second argument to produce should be a function");if(void 0!==t&&"function"!=typeof t)throw new Error("the third argument of a producer should not be set or a function");var i=void 0;if(l(e)){this.scopes.push([]);var a=this.createDraft(e);try{i=r.call(a,a),this.willFinalize(i,a,!!t);var u=t&&[],s=t&&[];if(void 0===i||i===a)i=this.finalize(a,[],u,s);else{if(a[c].modified)throw new Error("An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.");l(i)&&(i=this.finalize(i)),t&&(u.push({op:"replace",path:[],value:i}),s.push({op:"replace",path:[],value:e}))}}finally{this.currentScope().forEach(function(e){return e.revoke()}),this.scopes.pop()}t&&t(u,s)}else if(void 0===(i=r(e)))return e;return i===f?void 0:i}},{key:"setAutoFreeze",value:function(e){this.autoFreeze=e}},{key:"setUseProxies",value:function(e){this.useProxies=e,p(this,e?M:I)}},{key:"finalize",value:function(e,r,t,n){var o=this,i=e[c];if(!i)return Object.isFrozen(e)?e:this.finalizeTree(e);if(i.scope!==this.currentScope())return e;if(!i.modified)return i.base;if(!i.finalized){if(i.finalized=!0,this.finalizeTree(i.draft,r,t,n),this.onDelete)if(this.useProxies){var a=i.assigned;for(var f in a)a[f]||this.onDelete(i,f)}else{var u=i.base,s=i.copy;y(u,function(e){b(s,e)||o.onDelete(i,e)})}this.onCopy&&this.onCopy(i),this.autoFreeze&&1===this.scopes.length&&Object.freeze(i.copy),t&&m(i,r,t,n)}return i.copy}},{key:"finalizeTree",value:function(e,r,t,n){var o=this,i=e[c];i&&(this.useProxies||(i.finalizing=!0,i.copy=h(i.draft,!0),i.finalizing=!1),e=i.copy);var a=this.onAssign;return y(e,function f(u,c,p){if(c===p)throw Error("Immer forbids circular references");var d=!!i&&p===e;if(s(c)){if(c=t&&d&&!i.assigned[u]?o.finalize(c,r.concat(u),t,n):o.finalize(c),Array.isArray(p)||v(p,u)?p[u]=c:Object.defineProperty(p,u,{value:c}),d&&c===i.base[u])return}else{if(d&&g(c,i.base[u]))return;l(c)&&!Object.isFrozen(c)&&y(c,f)}d&&a&&a(i,u,c)}),e}}]),e}(),V=new J,q=V.produce,B=q(function(e,r){for(var t=0;t<r.length;t++){var n=r[t],i=n.path;if(0===i.length&&"replace"===n.op)e=n.value;else{for(var a=e,f=0;f<i.length-1;f++)if(!(a=a[i[f]])||"object"!==(void 0===a?"undefined":o(a)))throw new Error("Cannot apply patch, path doesn't resolve: "+i.join("/"));var u=i[i.length-1];switch(n.op){case"replace":case"add":a[u]=n.value;break;case"remove":if(Array.isArray(a)){if(u!==a.length-1)throw new Error("Only the last index of an array can be removed, index: "+u+", length: "+a.length);a.length-=1}else delete a[u];break;default:throw new Error("Unsupported patch operation: "+n.op)}}}return e});e.produce=q,e.default=q,e.setAutoFreeze=function(e){return V.setAutoFreeze(e)},e.setUseProxies=function(e){return V.setUseProxies(e)},e.applyPatches=B,e.Immer=J,e.original=function(e){if(e&&e[c])return e[c].base},e.isDraft=s,e.nothing=f,e.immerable=u,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.immer={}); | ||
var e,r;e=this,r=function(e){"use strict";var r,t,n,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},a=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),f="undefined"!=typeof Symbol?Symbol("immer-nothing"):(n=!0,(t="immer-nothing")in(r={})?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r),u="undefined"!=typeof Symbol?Symbol("immer-draftable"):"__$immer_draftable",c="undefined"!=typeof Symbol?Symbol("immer-state"):"__$immer_state";function s(e){return!!e&&!!e[c]}function l(e){if(!e||"object"!==(void 0===e?"undefined":o(e)))return!1;if(Array.isArray(e))return!0;var r=Object.getPrototypeOf(e);return!r||r===Object.prototype||(!!e[u]||!!e.constructor[u])}var p=Object.assign||function(e,r){for(var t in r)b(r,t)&&(e[t]=r[t]);return e},d="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames;function h(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(Array.isArray(e))return e.slice();var t=Object.create(Object.getPrototypeOf(e));return d(e).forEach(function(n){if(n!==c){var o=Object.getOwnPropertyDescriptor(e,n);if(o.get){if(!r)throw new Error("Immer drafts cannot have computed properties");o.value=o.get.call(e)}o.enumerable?t[n]=o.value:Object.defineProperty(t,n,{value:o.value,writable:!0,configurable:!0})}}),t}function y(e,r){if(Array.isArray(e))for(var t=0;t<e.length;t++)r(t,e[t],e);else d(e).forEach(function(t){return r(t,e[t],e)})}function v(e,r){return Object.getOwnPropertyDescriptor(e,r).enumerable}function b(e,r){return Object.prototype.hasOwnProperty.call(e,r)}function g(e,r){return e===r?0!==e||1/e==1/r:e!=e&&r!=r}function m(e,r,t,n){Array.isArray(e.base)?function(e,r,t,n){for(var o=e.base,i=e.copy,a=e.assigned,f=Math.min(o.length,i.length),u=0;u<f;u++)if(a[u]&&o[u]!==i[u]){var c=r.concat(u);t.push({op:"replace",path:c,value:i[u]}),n.push({op:"replace",path:c,value:o[u]})}if(f<i.length){for(var s=f;s<i.length;s++)t.push({op:"add",path:r.concat(s),value:i[s]});n.push({op:"replace",path:r.concat("length"),value:o.length})}else if(f<o.length){t.push({op:"replace",path:r.concat("length"),value:i.length});for(var l=f;l<o.length;l++)n.push({op:"add",path:r.concat(l),value:o[l]})}}(e,r,t,n):function(e,r,t,n){var o=e.base,i=e.copy;y(e.assigned,function(e,a){var f=o[e],u=i[e],c=a?e in o?"replace":"add":"remove";if(f!==u||"replace"!==c){var s=r.concat(e);t.push("remove"===c?{op:c,path:s}:{op:c,path:s,value:u}),n.push("add"===c?{op:"remove",path:s}:"remove"===c?{op:"add",path:s,value:f}:{op:"replace",path:s,value:f})}})}(e,r,t,n)}var w={},O=[],P=function(){return O[O.length-1]};function j(e,r){var t=Array.isArray(e),n=x(e);y(n,function(r){!function(e,r,t){var n=w[r];n?n.enumerable=t:w[r]=n={configurable:!0,enumerable:t,get:function(){return function(e,r){S(e);var t=A(e)[r];if(!e.finalizing&&t===e.base[r]&&l(t))return k(e),e.copy[r]=j(t,e);return t}(this[c],r)},set:function(e){!function(e,r,t){if(S(e),e.assigned[r]=!0,!e.modified){if(g(A(e)[r],t))return;E(e),k(e)}e.copy[r]=t}(this[c],r,e)}};Object.defineProperty(e,r,n)}(n,r,t||v(e,r))});var o,i,a,f={scope:r?r.scope:P(),modified:!1,finalizing:!1,finalized:!1,assigned:{},parent:r,base:e,draft:n,copy:null,revoke:z,revoked:!1};return o=n,i=c,a=f,Object.defineProperty(o,i,{value:a,enumerable:!1,writable:!0}),f.scope.push(f),n}function z(){this.revoked=!0}function A(e){return e.copy||e.base}function E(e){e.modified||(e.modified=!0,e.parent&&E(e.parent))}function k(e){e.copy||(e.copy=x(e.base))}function x(e){var r=e&&e[c];if(r){r.finalizing=!0;var t=h(r.draft,!0);return r.finalizing=!1,t}return h(e)}function S(e){if(!0===e.revoked)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(A(e)))}function D(e){for(var r=e.base,t=e.draft,n=Object.keys(t),o=n.length-1;o>=0;o--)if(void 0===r[n[o]]&&!b(r,n[o]))return!0;return n.length!==Object.keys(r).length}function F(e){var r=e.draft;if(r.length!==e.base.length)return!0;var t=Object.getOwnPropertyDescriptor(r,r.length-1);return!(!t||t.get)}var I=Object.freeze({scopes:O,currentScope:P,willFinalize:function(e,r,t){var n=P();n.forEach(function(e){return e.finalizing=!0}),void 0!==e&&e!==r||(t&&function e(r){if(r&&"object"===(void 0===r?"undefined":o(r))){var t=r[c];if(t){var n=t.base,i=t.draft,a=t.assigned;if(Array.isArray(r)){if(F(t)){if(E(t),a.length=!0,i.length<n.length)for(var f=i.length;f<n.length;f++)a[f]=!1;else for(var u=n.length;u<i.length;u++)a[u]=!0;for(var s=0;s<i.length;s++)void 0===a[s]&&e(i[s])}}else Object.keys(i).forEach(function(r){void 0!==n[r]||b(n,r)?a[r]||e(i[r]):(a[r]=!0,E(t))}),Object.keys(n).forEach(function(e){void 0!==i[e]||b(i,e)||(a[e]=!1,E(t))})}}}(r),function(e){for(var r=e.length-1;r>=0;r--){var t=e[r];!1===t.modified&&(Array.isArray(t.base)?F(t)&&E(t):D(t)&&E(t))}}(n))},createDraft:j}),N=[],_=function(){return N[N.length-1]};function C(e,r){var t={scope:r?r.scope:_(),modified:!1,finalized:!1,assigned:{},parent:r,base:e,draft:null,drafts:{},copy:null,revoke:null},n=Array.isArray(e)?Proxy.revocable([t],U):Proxy.revocable(t,R),o=n.revoke,i=n.proxy;return t.draft=i,t.revoke=o,t.scope.push(t),i}var R={get:function(e,r){if(r===c)return e;var t=e.drafts;if(!e.modified&&b(t,r))return t[r];var n=K(e)[r];if(e.finalized||!l(n))return n;if(e.modified){if(n!==e.base[r])return n;t=e.copy}return t[r]=C(n,e)},has:function(e,r){return r in K(e)},ownKeys:function(e){return Reflect.ownKeys(K(e))},set:function(e,r,t){if(!e.modified){var n=t?g(e.base[r],t)||t===e.drafts[r]:g(e.base[r],t)&&r in e.base;if(n)return!0;T(e)}return e.assigned[r]=!0,e.copy[r]=t,!0},deleteProperty:function(e,r){(void 0!==e.base[r]||r in e.base)&&(e.assigned[r]=!1,T(e));e.copy&&delete e.copy[r];return!0},getOwnPropertyDescriptor:function(e,r){var t=K(e),n=Reflect.getOwnPropertyDescriptor(t,r);n&&(n.writable=!0,n.configurable=!Array.isArray(t)||"length"!==r);return n},defineProperty:function(){throw new Error("Object.defineProperty() cannot be used on an Immer draft")},getPrototypeOf:function(e){return Object.getPrototypeOf(e.base)},setPrototypeOf:function(){throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft")}},U={};function K(e){return e.copy||e.base}function T(e){e.modified||(e.modified=!0,e.copy=p(h(e.base),e.drafts),e.drafts=null,e.parent&&T(e.parent))}y(R,function(e,r){U[e]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}}),U.deleteProperty=function(e,r){if(isNaN(parseInt(r)))throw new Error("Immer only supports deleting array indices");return R.deleteProperty.call(this,e[0],r)},U.set=function(e,r,t){if("length"!==r&&isNaN(parseInt(r)))throw new Error("Immer only supports setting array indices and the 'length' property");return R.set.call(this,e[0],r,t)};var M=Object.freeze({scopes:N,currentScope:_,willFinalize:function(){},createDraft:C});var $={useProxies:"undefined"!=typeof Proxy&&"undefined"!=typeof Reflect,autoFreeze:"undefined"!=typeof process?"production"!==process.env.NODE_ENV:"verifyMinified"===function(){}.name,onAssign:null,onDelete:null,onCopy:null},J=function(){function e(r){i(this,e),p(this,$,r),this.setUseProxies(this.useProxies),this.produce=this.produce.bind(this)}return a(e,[{key:"produce",value:function(e,r,t){var n=this;if("function"==typeof e&&"function"!=typeof r){var o=r;return r=e,function(){for(var e=arguments.length,t=Array(e>1?e-1:0),i=1;i<e;i++)t[i-1]=arguments[i];var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o;return n.produce(a,function(e){var n;return(n=r).call.apply(n,[e,e].concat(t))})}}if("function"!=typeof r)throw new Error("if first argument is not a function, the second argument to produce should be a function");if(void 0!==t&&"function"!=typeof t)throw new Error("the third argument of a producer should not be set or a function");var i=void 0;if(l(e)){this.scopes.push([]);var a=this.createDraft(e);try{i=r.call(a,a),this.willFinalize(i,a,!!t);var u=t&&[],s=t&&[];if(void 0===i||i===a)i=this.finalize(a,[],u,s);else{if(a[c].modified)throw new Error("An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.");l(i)&&(i=this.finalize(i)),t&&(u.push({op:"replace",path:[],value:i}),s.push({op:"replace",path:[],value:e}))}}finally{this.currentScope().forEach(function(e){return e.revoke()}),this.scopes.pop()}t&&t(u,s)}else if(void 0===(i=r(e)))return e;return i===f?void 0:i}},{key:"setAutoFreeze",value:function(e){this.autoFreeze=e}},{key:"setUseProxies",value:function(e){this.useProxies=e,p(this,e?M:I)}},{key:"finalize",value:function(e,r,t,n){var o=this,i=e[c];if(!i)return Object.isFrozen(e)?e:this.finalizeTree(e);if(i.scope!==this.currentScope())return e;if(!i.modified)return i.base;if(!i.finalized){if(i.finalized=!0,this.finalizeTree(i.draft,r,t,n),this.onDelete)if(this.useProxies){var a=i.assigned;for(var f in a)a[f]||this.onDelete(i,f)}else{var u=i.base,s=i.copy;y(u,function(e){b(s,e)||o.onDelete(i,e)})}this.onCopy&&this.onCopy(i),this.autoFreeze&&1===this.scopes.length&&Object.freeze(i.copy),t&&m(i,r,t,n)}return i.copy}},{key:"finalizeTree",value:function(e,r,t,n){var o=this,i=e[c];i&&(this.useProxies||(i.finalizing=!0,i.copy=h(i.draft,!0),i.finalizing=!1),e=i.copy);var a=this.onAssign;return y(e,function f(u,c,p){if(c===p)throw Error("Immer forbids circular references");var d=!!i&&p===e;if(s(c)){if(c=t&&d&&!i.assigned[u]?o.finalize(c,r.concat(u),t,n):o.finalize(c),Array.isArray(p)||v(p,u)?p[u]=c:Object.defineProperty(p,u,{value:c}),d&&c===i.base[u])return}else{if(d&&g(c,i.base[u]))return;l(c)&&!Object.isFrozen(c)&&y(c,f)}d&&a&&a(i,u,c)}),e}}]),e}(),V=new J,q=V.produce,B=q(function(e,r){for(var t=0;t<r.length;t++){var n=r[t],i=n.path;if(0===i.length&&"replace"===n.op)e=n.value;else{for(var a=e,f=0;f<i.length-1;f++)if(!(a=a[i[f]])||"object"!==(void 0===a?"undefined":o(a)))throw new Error("Cannot apply patch, path doesn't resolve: "+i.join("/"));var u=i[i.length-1];switch(n.op){case"replace":case"add":a[u]=n.value;break;case"remove":if(Array.isArray(a)){if(u!==a.length-1)throw new Error("Only the last index of an array can be removed, index: "+u+", length: "+a.length);a.length-=1}else delete a[u];break;default:throw new Error("Unsupported patch operation: "+n.op)}}}return e});e.produce=q,e.default=q,e.setAutoFreeze=function(e){return V.setAutoFreeze(e)},e.setUseProxies=function(e){return V.setUseProxies(e)},e.applyPatches=B,e.Immer=J,e.original=function(e){if(e&&e[c])return e[c].base},e.isDraft=s,e.nothing=f,e.immerable=u,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.immer={}); | ||
//# sourceMappingURL=immer.umd.js.map |
{ | ||
"name": "immer", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"description": "Create your next immutable state by mutating the current one", | ||
@@ -5,0 +5,0 @@ "main": "dist/immer.js", |
@@ -100,3 +100,3 @@ <img src="images/immer-logo.png" height="200px" align="right"/> | ||
- Boilerplate reduction. Less noise, more concise code. | ||
- Small: bundled and minified: 2KB. | ||
- Small [![size](http://img.badgesize.io/https://cdn.jsdelivr.net/npm/immer/dist/immer.umd.js?compression=gzip)](http://img.badgesize.io/https://cdn.jsdelivr.net/npm/immer/dist/immer.umd.js) | ||
@@ -538,66 +538,53 @@ Read further to see all these benefits explained. | ||
## Limitations | ||
## Supported object types | ||
Immer supports the following types of data: | ||
Only plain objects and arrays are automatically drafted by Immer. This means other object types should never be mutated **unless** you added the exported `immerable` symbol to the object itself, its prototype, or its class constructor. In that case, the object is essentially an immutable plain object with a custom prototype. | ||
1. All kinds of primitive values | ||
1. `Date` instances, but: only if not mutated, see below | ||
1. Arrays, but: non-standard attributes are not supported (like: `array.test = "Test"`) | ||
1. Plain objects (objects that have as prototype either `null` or `Object`) | ||
1. Functions, assuming they aren't mutated | ||
1. Other value types (like class instances) can be stored in the tree, but note that Immer won't work _inside_ those objects. In other words, if you modify a class instance, this will _not_ result in clone and unmodified original, but just in a modified original. | ||
For arrays, only numeric properties and the `length` property can be mutated. Custom properties are not preserved on arrays. | ||
# Pitfalls | ||
When working with `Date` objects, you should always create a new `Date` instance instead of mutating an existing `Date` object. | ||
1. Don't redefine draft like, `draft = myCoolNewState`. Instead, either modify the `draft` or return a new state. See [Returning data from producers](#returning-data-from-producers). | ||
1. Immer assumes your state to be a unidirectional tree. That is, no object should appear twice in the tree, and there should be no circular references. | ||
1. Class instances are not, and will not have first-class support. Read [here](https://github.com/mweststrate/immer/issues/155#issuecomment-407725592) why classes are a conceptual mismatch (and technically extremely challenging) | ||
1. For example, working with `Date` objects is no problem, just make sure you never modify them (by using methods like `setYear` on an existing instance). Instead, always create fresh `Date` instances. Which is probably what you were unconsciously doing already. | ||
1. Since Immer uses proxies, reading huge amounts of data from state comes with an overhead (especially in the ES5 implementation). If this ever becomes an issue (measure before you optimize!), do the current state analysis before entering the producer function or read from the `currentState` rather than the `draftState`. Also, realize that immer is opt-in everywhere, so it is perfectly fine to manually write super performance critical reducers, and use immer for all the normal ones. Also note that `original` can be used to get the original state of an object, which is cheaper to read. | ||
1. Some debuggers (at least Node 6 is known) have trouble debugging when Proxies are in play. Node 8 is known to work correctly. | ||
1. Always try to pull `produce` 'up', for example `for (let x of y) produce(base, d => d.push(x))` is exponentially slower than `produce(base, d => { for (let x of y) d.push(x)})` | ||
1. It is possible to return values from producers, except, it is not possible to return `undefined` that way, as it is indistinguishable from not updating the draft at all! If you want to replace the draft with `undefined`, just return `nothing` from the producer. | ||
1. Immer does not support built-in data-structures like `Map` and `Set`. However, it is fine to just immutably "update" them yourself but still leverage immer wherever possible: | ||
Built-in classes like `Map` and `Set` are not supported. As a workaround, you should clone them before mutating them in a producer: | ||
```javascript | ||
```js | ||
const state = { | ||
title: "hello", | ||
tokenSet: new Set() | ||
set: new Set(), | ||
map: new Map() | ||
} | ||
const nextState = produce(state, draft => { | ||
draft.title = draft.title.toUpperCase() // let immer do it's job | ||
// don't use the operations onSet, as that mutates the instance! | ||
// draft.tokenSet.add("c1342") | ||
// Don't use any Set methods, as that mutates the instance! | ||
draft.set.add("foo") // ❌ | ||
// instead: clone the set (once!) | ||
const newSet = new Set(draft.tokenSet) | ||
// mutate the clone (just in this producer) | ||
newSet.add("c1342") | ||
// update the draft with the new set | ||
draft.tokenSet = newSet | ||
}) | ||
``` | ||
// 1. Instead, clone the set (just once) | ||
const newSet = new Set(draft.set) // ✅ | ||
Or a deep update in maps (well, don't use maps for this use case, but as an example): | ||
// 2. Mutate the clone (just in this producer) | ||
newSet.add("foo") | ||
```javascript | ||
const state = { | ||
users: new Map(["michel", {name: "miche"}]) | ||
} | ||
// 3. Update the draft with the new set | ||
draft.set = newSet | ||
const nextState = produce(state, draft => { | ||
const newUsers = new Map(draft.users) | ||
// mutate the new map and set a _new_ user object | ||
// but leverage produce again to base the new user object on the original one | ||
newUsers.set( | ||
"michel", | ||
produce(draft.users.get("michel"), draft => { | ||
draft.name = "michel" | ||
}) | ||
) | ||
draft.users = newUsers | ||
// Similarly, don't use any Map methods. | ||
draft.map.set("foo", "bar") // ❌ | ||
// 1. Instead, clone the map (just once) | ||
const newMap = new Map(draft.map) // ✅ | ||
// 2. Mutate it | ||
newMap.set("foo", "bar") | ||
// 3. Update the draft | ||
draft.map = newMap | ||
}) | ||
``` | ||
# Pitfalls | ||
1. Don't redefine draft like, `draft = myCoolNewState`. Instead, either modify the `draft` or return a new state. See [Returning data from producers](#returning-data-from-producers). | ||
1. Immer assumes your state to be a unidirectional tree. That is, no object should appear twice in the tree, and there should be no circular references. | ||
1. Since Immer uses proxies, reading huge amounts of data from state comes with an overhead (especially in the ES5 implementation). If this ever becomes an issue (measure before you optimize!), do the current state analysis before entering the producer function or read from the `currentState` rather than the `draftState`. Also, realize that immer is opt-in everywhere, so it is perfectly fine to manually write super performance critical reducers, and use immer for all the normal ones. Also note that `original` can be used to get the original state of an object, which is cheaper to read. | ||
1. Some debuggers (at least Node 6 is known) have trouble debugging when Proxies are in play. Node 8 is known to work correctly. | ||
1. Always try to pull `produce` 'up', for example `for (let x of y) produce(base, d => d.push(x))` is exponentially slower than `produce(base, d => { for (let x of y) d.push(x)})` | ||
1. It is possible to return values from producers, except, it is not possible to return `undefined` that way, as it is indistinguishable from not updating the draft at all! If you want to replace the draft with `undefined`, just return `nothing` from the producer. | ||
## Cool things built with immer | ||
@@ -604,0 +591,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
264455
711