UNPKG

6.75 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){a(b,J,!0)}function c(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,J)):!0}function d(a,b){return a===b||a!==a&&b!==b}function e(a){return!(null===a||"object"!=typeof a||Array.isArray(a)||a instanceof Date)}function f(a){var b=new Error(a);return b.__proto__=f,b}function g(a,c){b(a);return a}function h(b,c){var d=b[c];a(b,c,function(){return E(d.apply(b,arguments))})}function i(a,b,c){var f=c&&c.deep;if(a in this&&(f&&this[a]!==b&&e(b)&&e(this[a])&&(b=this[a].merge(b,{deep:!0,mode:"replace"})),d(this[a],b)))return this;var g=p.call(this);return g[a]=E(b),k(g)}function j(a,b,c){var d=a[0];if(1===a.length)return i.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)?j.call(P,f,b):v.call(Q,f,b)}if(d in this&&g===e)return this;var l=p.call(this);return l[d]=e,k(l)}function k(b){for(var c in N)if(N.hasOwnProperty(c)){var d=N[c];h(b,d)}a(b,"flatMap",n),a(b,"asObject",q),a(b,"asMutable",p),a(b,"set",i),a(b,"setIn",j),a(b,"update",x),a(b,"updateIn",z);for(var e=0,f=b.length;f>e;e++)b[e]=E(b[e]);return g(b,M)}function l(b){return a(b,"asMutable",m),g(b,O)}function m(){return new Date(this.getTime())}function n(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 k(c)}function o(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 C(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function p(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(r(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function q(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 C(c)}function r(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,J)||a instanceof Date?a:a.asMutable({deep:!0})}function s(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function t(a,b){function c(a,c,f){var h=E(c[f]),i=l&&l(a[f],h,b),k=a[f];if(void 0!==g||void 0!==i||!a.hasOwnProperty(f)||!d(h,k)){var m;m=i?i:j&&e(k)&&e(h)?k.merge(h,b):h,d(k,m)&&a.hasOwnProperty(f)||(void 0===g&&(g=s(a,a.instantiateEmptyObject())),g[f]=m)}}function f(a,b){for(var c in a)b.hasOwnProperty(c)||(void 0===g&&(g=s(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&&f(this,a)}return void 0===g?this:C(g,{instantiateEmptyObject:this.instantiateEmptyObject})}function u(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 v(a,b,c){var d=a[0];if(1===a.length)return w.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):v.call(Q,f,b),this.hasOwnProperty(d)&&g===e)return this;var h=s(this,this.instantiateEmptyObject());return h[d]=e,C(h,this)}function w(a,b,c){var f=c&&c.deep;if(this.hasOwnProperty(a)&&(f&&this[a]!==b&&e(b)&&e(this[a])&&(b=this[a].merge(b,{deep:!0,mode:"replace"})),d(this[a],b)))return this;var g=s(this,this.instantiateEmptyObject());return g[a]=E(b),C(g,this)}function x(a,b){var c=Array.prototype.slice.call(arguments,2),d=this[a];return this.set(a,b.apply(d,[d].concat(c)))}function y(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 z(a,b){var c=Array.prototype.slice.call(arguments,2),d=y(this,a);return this.setIn(a,b.apply(d,[d].concat(c)))}function A(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=r(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function B(){return{}}function C(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:B;return a(b,"merge",t),a(b,"replace",u),a(b,"without",o),a(b,"asMutable",A),a(b,"instantiateEmptyObject",d),a(b,"set",w),a(b,"setIn",v),a(b,"update",x),a(b,"updateIn",z),g(b,K)}function D(a){return"object"==typeof a&&null!==a&&(a.$$typeof===I||a.$$typeof===H)}function E(a,b,d){if(c(a)||D(a))return a;if(Array.isArray(a))return k(a.slice());if(a instanceof Date)return l(new Date(a.getTime()));var e=b&&b.prototype,f=e&&e!==Object.prototype?function(){return Object.create(e)}:B,g=f();for(var h in a)Object.getOwnPropertyDescriptor(a,h)&&(g[h]=E(a[h],void 0,d));return C(g,{instantiateEmptyObject:f})}function F(a){function b(){var b=[].slice.call(arguments),c=b.shift();return a.apply(c,b)}return b}function G(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 H="function"==typeof Symbol&&Symbol["for"]&&Symbol["for"]("react.element"),I=60103,J="__immutable_invariants_hold",K=["setPrototypeOf"],L=["keys"],M=K.concat(["push","pop","sort","splice","shift","unshift","reverse"]),N=L.concat(["map","filter","slice","concat","reduce","reduceRight"]),O=K.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);f.prototype=Error.prototype;var P=E([]),Q=E({});E.from=E,E.isImmutable=c,E.ImmutableError=f,E.merge=F(t),E.replace=F(u),E.without=F(o),E.asMutable=G(A,p),E.set=G(w,i),E.setIn=G(v,j),E.update=F(x),E.updateIn=F(z),E.flatMap=F(n),E.asObject=F(q),Object.freeze(E),"object"==typeof module?module.exports=E:"object"==typeof exports?exports.Immutable=E:"object"==typeof window?window.Immutable=E:"object"==typeof global&&(global.Immutable=E)}();
\No newline at end of file