UNPKG

7.23 kBJavaScriptView Raw
1/* (c) 2016, Richard Feldman, github.com/rtfeldman/seamless-immutable/blob/master/LICENSE */!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b,c){a(b,c,function(){throw new g("The "+c+" method cannot be invoked on an Immutable data structure.")})}function c(b){a(b,K,!0)}function d(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,K)):!0}function e(a,b){return a===b||a!==a&&b!==b}function f(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function g(a){var b=new Error(a);return b.__proto__=g,b}function h(a,d){c(a);for(var e in d)d.hasOwnProperty(e)&&b(a,d[e]);return Object.freeze(a),a}function i(b,c){var d=b[c];a(b,c,function(){return F(d.apply(b,arguments))})}function j(a,b,c){var d=c&&c.deep;if(a in this&&(d&&this[a]!==b&&f(b)&&f(this[a])&&(b=this[a].merge(b,{deep:!0,mode:"replace"})),e(this[a],b)))return this;var g=q.call(this);return g[a]=F(b),l(g)}function k(a,b,c){var d=a[0];if(1===a.length)return j.call(this,d,b,c);var e,f=a.slice(1),g=this[d];if("object"==typeof g&&null!==g&&"function"==typeof g.setIn)e=g.setIn(f,b);else{var h=f[0];e=""!==h&&isFinite(h)?k.call(Q,f,b):w.call(R,f,b)}if(d in this&&g===e)return this;var i=q.call(this);return i[d]=e,l(i)}function l(b){for(var c in O)if(O.hasOwnProperty(c)){var d=O[c];i(b,d)}a(b,"flatMap",o),a(b,"asObject",r),a(b,"asMutable",q),a(b,"set",j),a(b,"setIn",k),a(b,"update",y),a(b,"updateIn",A);for(var e=0,f=b.length;f>e;e++)b[e]=F(b[e]);return h(b,N)}function m(b){return a(b,"asMutable",n),h(b,P)}function n(){return new Date(this.getTime())}function o(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);Array.isArray(e)?c.push.apply(c,e):c.push(e)}return l(c)}function p(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=Array.isArray(a)?a.slice():Array.prototype.slice.call(arguments);b.forEach(function(a,b,c){"number"==typeof a&&(c[b]=a.toString())}),a=function(a,c){return-1!==b.indexOf(c)}}var c=this.instantiateEmptyObject();for(var d in this)this.hasOwnProperty(d)&&a(this[d],d)===!1&&(c[d]=this[d]);return D(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function q(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(s(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function r(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return D(c)}function s(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,K)||a instanceof Date?a:a.asMutable({deep:!0})}function t(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function u(a,b){function c(a,c,d){var h=F(c[d]),i=l&&l(a[d],h,b),k=a[d];if(void 0!==g||void 0!==i||!a.hasOwnProperty(d)||!e(h,k)){var m;m=i?i:j&&f(k)&&f(h)?k.merge(h,b):h,e(k,m)&&a.hasOwnProperty(d)||(void 0===g&&(g=t(a,a.instantiateEmptyObject())),g[d]=m)}}function d(a,b){for(var c in a)b.hasOwnProperty(c)||(void 0===g&&(g=t(a,a.instantiateEmptyObject())),delete g[c])}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var g,h,i=Array.isArray(a),j=b&&b.deep,k=b&&b.mode||"merge",l=b&&b.merger;if(i)for(var m=0,n=a.length;n>m;m++){var o=a[m];for(h in o)o.hasOwnProperty(h)&&c(void 0!==g?g:this,o,h)}else{for(h in a)Object.getOwnPropertyDescriptor(a,h)&&c(this,a,h);"replace"===k&&d(this,a)}return void 0===g?this:D(g,{instantiateEmptyObject:this.instantiateEmptyObject})}function v(a,b){var c=b&&b.deep;if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#replace can only be invoked with objects or arrays, not "+JSON.stringify(a));return this.merge(a,{deep:c,mode:"replace"})}function w(a,b,c){var d=a[0];if(1===a.length)return x.call(this,d,b,c);var e,f=a.slice(1),g=this[d];if(e=this.hasOwnProperty(d)&&"object"==typeof g&&null!==g&&"function"==typeof g.setIn?g.setIn(f,b):w.call(R,f,b),this.hasOwnProperty(d)&&g===e)return this;var h=t(this,this.instantiateEmptyObject());return h[d]=e,D(h,this)}function x(a,b,c){var d=c&&c.deep;if(this.hasOwnProperty(a)&&(d&&this[a]!==b&&f(b)&&f(this[a])&&(b=this[a].merge(b,{deep:!0,mode:"replace"})),e(this[a],b)))return this;var g=t(this,this.instantiateEmptyObject());return g[a]=F(b),D(g,this)}function y(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return this.set(a,b.apply(d,[d].concat(c)))}function z(a,b){for(var c=0,d=b.length;null!=a&&d>c;c++)a=a[b[c]];return c&&c==d?a:void 0}function A(a,b){var c=Array.prototype.slice.call(arguments,2),d=z(this,a);return this.setIn(a,b.apply(d,[d].concat(c)))}function B(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=s(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function C(){return{}}function D(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:C;return a(b,"merge",u),a(b,"replace",v),a(b,"without",p),a(b,"asMutable",B),a(b,"instantiateEmptyObject",d),a(b,"set",x),a(b,"setIn",w),a(b,"update",y),a(b,"updateIn",A),h(b,L)}function E(a){return"object"==typeof a&&null!==a&&(a.$$typeof===J||a.$$typeof===I)}function F(a,b,c){if(d(a)||E(a))return a;if(Array.isArray(a))return l(a.slice());if(a instanceof Date)return m(new Date(a.getTime()));var e=b&&b.prototype,f=e&&e!==Object.prototype?function(){return Object.create(e)}:C,h=f();if(null==c&&(c=64),0>=c)throw new g("Attempt to construct Immutable from a deeply nested object was detected. Have you tried to wrap an object with circular references (e.g. React element)? See https://github.com/rtfeldman/seamless-immutable/wiki/Deeply-nested-object-was-detected for details.");c-=1;for(var i in a)Object.getOwnPropertyDescriptor(a,i)&&(h[i]=F(a[i],void 0,c));return D(h,{instantiateEmptyObject:f})}function G(a){function b(){var b=[].slice.call(arguments),c=b.shift();return a.apply(c,b)}return b}function H(a,b){function c(){var c=[].slice.call(arguments),d=c.shift();return Array.isArray(d)?b.apply(d,c):a.apply(d,c)}return c}var I="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),J=60103,K="__immutable_invariants_hold",L=["setPrototypeOf"],M=["keys"],N=L.concat(["push","pop","sort","splice","shift","unshift","reverse"]),O=M.concat(["map","filter","slice","concat","reduce","reduceRight"]),P=L.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);g.prototype=Error.prototype;var Q=F([]),R=F({});F.from=F,F.isImmutable=d,F.ImmutableError=g,F.merge=G(u),F.replace=G(v),F.without=G(p),F.asMutable=H(B,q),F.set=H(x,j),F.setIn=H(w,k),F.update=G(y),F.updateIn=G(A),F.flatMap=G(o),F.asObject=G(r),Object.freeze(F),"object"==typeof module?module.exports=F:"object"==typeof exports?exports.Immutable=F:"object"==typeof window?window.Immutable=F:"object"==typeof global&&(global.Immutable=F)}();
\No newline at end of file