seamless-immutable
Advanced tools
Comparing version 5.1.0 to 5.1.1
{ | ||
"name": "seamless-immutable", | ||
"main": "src/seamless-immutable.js", | ||
"version": "5.1.0", | ||
"version": "5.1.1", | ||
"homepage": "https://github.com/rtfeldman/seamless-immutable", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "seamless-immutable", | ||
"version": "5.1.0", | ||
"version": "5.1.1", | ||
"description": "Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.", | ||
@@ -5,0 +5,0 @@ "main": "src/seamless-immutable.js", |
@@ -147,3 +147,3 @@ seamless-immutable | ||
``` | ||
```javascript | ||
function Square(length) { this.length = length }; | ||
@@ -238,2 +238,6 @@ Square.prototype.area = function() { return Math.pow(this.length, 2) }; | ||
#### 5.1.1 | ||
`Immutable(Object.create(null))` now works as expected. | ||
#### 5.1.0 | ||
@@ -336,3 +340,3 @@ | ||
[1]: https://secure.travis-ci.org/rtfeldman/seamless-immutable.svg | ||
[1]: https://travis-ci.org/rtfeldman/seamless-immutable.svg?branch=master | ||
[2]: https://travis-ci.org/rtfeldman/seamless-immutable | ||
@@ -339,0 +343,0 @@ [3]: https://badge.fury.io/js/seamless-immutable.svg |
@@ -28,3 +28,5 @@ (function() { | ||
if (typeof target === "object") { | ||
return target === null || target.hasOwnProperty(immutabilityTag); | ||
return target === null || Boolean( | ||
Object.getOwnPropertyDescriptor(target, immutabilityTag) | ||
); | ||
} else { | ||
@@ -65,2 +67,3 @@ // In JavaScript, only objects are even potentially mutable. | ||
var err = new Error(message); | ||
// TODO: Consider `Object.setPrototypeOf(err, ImmutableError);` | ||
err.__proto__ = ImmutableError; | ||
@@ -282,3 +285,8 @@ | ||
function asDeepMutable(obj) { | ||
if(!obj || !obj.hasOwnProperty(immutabilityTag) || obj instanceof Date) { return obj; } | ||
if ( | ||
(!obj) || | ||
(typeof obj !== 'object') || | ||
(!Object.getOwnPropertyDescriptor(obj, immutabilityTag)) || | ||
(obj instanceof Date) | ||
) { return obj; } | ||
return obj.asMutable({deep: true}); | ||
@@ -289,3 +297,3 @@ } | ||
for (var key in src) { | ||
if (src.hasOwnProperty(key)) { | ||
if (Object.getOwnPropertyDescriptor(src, key)) { | ||
dest[key] = src[key]; | ||
@@ -366,3 +374,3 @@ } | ||
for (key in other) { | ||
if (other.hasOwnProperty(key)) { | ||
if (Object.getOwnPropertyDescriptor(other, key)) { | ||
addToResult(this, other, key); | ||
@@ -487,3 +495,3 @@ } | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
if (Object.getOwnPropertyDescriptor(obj, key)) { | ||
clone[key] = Immutable(obj[key]); | ||
@@ -490,0 +498,0 @@ } |
@@ -1,1 +0,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 f("The "+c+" method cannot be invoked on an Immutable data structure.")})}function c(b){a(b,A,!0)}function d(a){return"object"==typeof a?null===a||a.hasOwnProperty(A):!0}function e(a){return!(null===a||"object"!=typeof a||a instanceof Array||a instanceof Date)}function f(a){var b=new Error(a);return b.__proto__=f,b}function g(a,d){c(a);for(var e in d)d.hasOwnProperty(e)&&b(a,d[e]);return Object.freeze(a),a}function h(b,c){var d=b[c];a(b,c,function(){return z(d.apply(b,arguments))})}function i(a,b){if(a in this&&this[a]===b)return this;var c=p.call(this);return c[a]=z(b),k(c)}function j(a,b){var c=a[0];if(1===a.length)return i.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d="object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):j.call(G,e,b),c in this&&f===d)return this;var g=p.call(this);return g[c]=d,k(g)}function k(b){for(var c in E)if(E.hasOwnProperty(c)){var d=E[c];h(b,d)}a(b,"flatMap",n),a(b,"asObject",q),a(b,"asMutable",p),a(b,"set",i),a(b,"setIn",j);for(var e=0,f=b.length;f>e;e++)b[e]=z(b[e]);return g(b,D)}function l(b){return a(b,"asMutable",m),g(b,F)}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);e instanceof Array?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=a instanceof Array?a:Array.prototype.slice.call(arguments);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 y(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 y(c)}function r(a){return!a||!a.hasOwnProperty(A)||a instanceof Date?a:a.asMutable({deep:!0})}function s(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function t(a,b){function c(a,c,f){var g=z(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==d||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&e(k)&&e(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===d&&(d=s(a,a.instantiateEmptyObject())),d[f]=l)}}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 d,f,g=a instanceof Array,h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(this,k,f)}else for(f in a)a.hasOwnProperty(f)&&c(this,a,f);return void 0===d?this:y(d,{instantiateEmptyObject:this.instantiateEmptyObject})}function u(a,b){var c=a[0];if(1===a.length)return v.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):u.call(H,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=s(this,this.instantiateEmptyObject());return g[c]=d,y(g,this)}function v(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=s(this,this.instantiateEmptyObject());return c[a]=z(b),y(c,this)}function w(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 x(){return{}}function y(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:x;return a(b,"merge",t),a(b,"without",o),a(b,"asMutable",w),a(b,"instantiateEmptyObject",d),a(b,"set",v),a(b,"setIn",u),g(b,B)}function z(a,b){if(d(a))return a;if(a instanceof Array)return k(a.slice());if(a instanceof Date)return l(new Date(a.getTime()));var c=b&&b.prototype,e=c&&c!==Object.prototype?function(){return Object.create(c)}:x,f=e();for(var g in a)a.hasOwnProperty(g)&&(f[g]=z(a[g]));return y(f,{instantiateEmptyObject:e})}var A="__immutable_invariants_hold",B=["setPrototypeOf"],C=["keys"],D=B.concat(["push","pop","sort","splice","shift","unshift","reverse"]),E=C.concat(["map","filter","slice","concat","reduce","reduceRight"]),F=B.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);f.prototype=Error.prototype;var G=z([]),H=z({});z.isImmutable=d,z.ImmutableError=f,Object.freeze(z),"object"==typeof module?module.exports=z:"object"==typeof exports?exports.Immutable=z:"object"==typeof window?window.Immutable=z:"object"==typeof global&&(global.Immutable=z)}(); | ||
/* (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 f("The "+c+" method cannot be invoked on an Immutable data structure.")})}function c(b){a(b,A,!0)}function d(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,A)):!0}function e(a){return!(null===a||"object"!=typeof a||a instanceof Array||a instanceof Date)}function f(a){var b=new Error(a);return b.__proto__=f,b}function g(a,d){c(a);for(var e in d)d.hasOwnProperty(e)&&b(a,d[e]);return Object.freeze(a),a}function h(b,c){var d=b[c];a(b,c,function(){return z(d.apply(b,arguments))})}function i(a,b){if(a in this&&this[a]===b)return this;var c=p.call(this);return c[a]=z(b),k(c)}function j(a,b){var c=a[0];if(1===a.length)return i.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d="object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):j.call(G,e,b),c in this&&f===d)return this;var g=p.call(this);return g[c]=d,k(g)}function k(b){for(var c in E)if(E.hasOwnProperty(c)){var d=E[c];h(b,d)}a(b,"flatMap",n),a(b,"asObject",q),a(b,"asMutable",p),a(b,"set",i),a(b,"setIn",j);for(var e=0,f=b.length;f>e;e++)b[e]=z(b[e]);return g(b,D)}function l(b){return a(b,"asMutable",m),g(b,F)}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);e instanceof Array?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=a instanceof Array?a:Array.prototype.slice.call(arguments);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 y(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 y(c)}function r(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,A)||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 g=z(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==d||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&e(k)&&e(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===d&&(d=s(a,a.instantiateEmptyObject())),d[f]=l)}}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 d,f,g=a instanceof Array,h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(this,k,f)}else for(f in a)Object.getOwnPropertyDescriptor(a,f)&&c(this,a,f);return void 0===d?this:y(d,{instantiateEmptyObject:this.instantiateEmptyObject})}function u(a,b){var c=a[0];if(1===a.length)return v.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):u.call(H,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=s(this,this.instantiateEmptyObject());return g[c]=d,y(g,this)}function v(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=s(this,this.instantiateEmptyObject());return c[a]=z(b),y(c,this)}function w(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 x(){return{}}function y(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:x;return a(b,"merge",t),a(b,"without",o),a(b,"asMutable",w),a(b,"instantiateEmptyObject",d),a(b,"set",v),a(b,"setIn",u),g(b,B)}function z(a,b){if(d(a))return a;if(a instanceof Array)return k(a.slice());if(a instanceof Date)return l(new Date(a.getTime()));var c=b&&b.prototype,e=c&&c!==Object.prototype?function(){return Object.create(c)}:x,f=e();for(var g in a)Object.getOwnPropertyDescriptor(a,g)&&(f[g]=z(a[g]));return y(f,{instantiateEmptyObject:e})}var A="__immutable_invariants_hold",B=["setPrototypeOf"],C=["keys"],D=B.concat(["push","pop","sort","splice","shift","unshift","reverse"]),E=C.concat(["map","filter","slice","concat","reduce","reduceRight"]),F=B.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);f.prototype=Error.prototype;var G=z([]),H=z({});z.isImmutable=d,z.ImmutableError=f,Object.freeze(z),"object"==typeof module?module.exports=z:"object"==typeof exports?exports.Immutable=z:"object"==typeof window?window.Immutable=z:"object"==typeof global&&(global.Immutable=z)}(); |
@@ -1,1 +0,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,z,!0)}function c(a){return"object"==typeof a?null===a||a.hasOwnProperty(z):!0}function d(a){return!(null===a||"object"!=typeof a||a instanceof Array||a instanceof Date)}function e(a){var b=new Error(a);return b.__proto__=e,b}function f(a,c){b(a);return a}function g(b,c){var d=b[c];a(b,c,function(){return y(d.apply(b,arguments))})}function h(a,b){if(a in this&&this[a]===b)return this;var c=o.call(this);return c[a]=y(b),j(c)}function i(a,b){var c=a[0];if(1===a.length)return h.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d="object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):i.call(F,e,b),c in this&&f===d)return this;var g=o.call(this);return g[c]=d,j(g)}function j(b){for(var c in D)if(D.hasOwnProperty(c)){var d=D[c];g(b,d)}a(b,"flatMap",m),a(b,"asObject",p),a(b,"asMutable",o),a(b,"set",h),a(b,"setIn",i);for(var e=0,j=b.length;j>e;e++)b[e]=y(b[e]);return f(b,C)}function k(b){return a(b,"asMutable",l),f(b,E)}function l(){return new Date(this.getTime())}function m(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);e instanceof Array?c.push.apply(c,e):c.push(e)}return j(c)}function n(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=a instanceof Array?a:Array.prototype.slice.call(arguments);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 x(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function o(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(q(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function p(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 x(c)}function q(a){return!a||!a.hasOwnProperty(z)||a instanceof Date?a:a.asMutable({deep:!0})}function r(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function s(a,b){function c(a,c,f){var g=y(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==e||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&d(k)&&d(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===e&&(e=r(a,a.instantiateEmptyObject())),e[f]=l)}}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 e,f,g=a instanceof Array,h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(this,k,f)}else for(f in a)a.hasOwnProperty(f)&&c(this,a,f);return void 0===e?this:x(e,{instantiateEmptyObject:this.instantiateEmptyObject})}function t(a,b){var c=a[0];if(1===a.length)return u.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):t.call(G,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=r(this,this.instantiateEmptyObject());return g[c]=d,x(g,this)}function u(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=r(this,this.instantiateEmptyObject());return c[a]=y(b),x(c,this)}function v(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=q(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function w(){return{}}function x(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:w;return a(b,"merge",s),a(b,"without",n),a(b,"asMutable",v),a(b,"instantiateEmptyObject",d),a(b,"set",u),a(b,"setIn",t),f(b,A)}function y(a,b){if(c(a))return a;if(a instanceof Array)return j(a.slice());if(a instanceof Date)return k(new Date(a.getTime()));var d=b&&b.prototype,e=d&&d!==Object.prototype?function(){return Object.create(d)}:w,f=e();for(var g in a)a.hasOwnProperty(g)&&(f[g]=y(a[g]));return x(f,{instantiateEmptyObject:e})}var z="__immutable_invariants_hold",A=["setPrototypeOf"],B=["keys"],C=A.concat(["push","pop","sort","splice","shift","unshift","reverse"]),D=B.concat(["map","filter","slice","concat","reduce","reduceRight"]),E=A.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);e.prototype=Error.prototype;var F=y([]),G=y({});y.isImmutable=c,y.ImmutableError=e,Object.freeze(y),"object"==typeof module?module.exports=y:"object"==typeof exports?exports.Immutable=y:"object"==typeof window?window.Immutable=y:"object"==typeof global&&(global.Immutable=y)}(); | ||
/* (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,z,!0)}function c(a){return"object"==typeof a?null===a||Boolean(Object.getOwnPropertyDescriptor(a,z)):!0}function d(a){return!(null===a||"object"!=typeof a||a instanceof Array||a instanceof Date)}function e(a){var b=new Error(a);return b.__proto__=e,b}function f(a,c){b(a);return a}function g(b,c){var d=b[c];a(b,c,function(){return y(d.apply(b,arguments))})}function h(a,b){if(a in this&&this[a]===b)return this;var c=o.call(this);return c[a]=y(b),j(c)}function i(a,b){var c=a[0];if(1===a.length)return h.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d="object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):i.call(F,e,b),c in this&&f===d)return this;var g=o.call(this);return g[c]=d,j(g)}function j(b){for(var c in D)if(D.hasOwnProperty(c)){var d=D[c];g(b,d)}a(b,"flatMap",m),a(b,"asObject",p),a(b,"asMutable",o),a(b,"set",h),a(b,"setIn",i);for(var e=0,j=b.length;j>e;e++)b[e]=y(b[e]);return f(b,C)}function k(b){return a(b,"asMutable",l),f(b,E)}function l(){return new Date(this.getTime())}function m(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);e instanceof Array?c.push.apply(c,e):c.push(e)}return j(c)}function n(a){if("undefined"==typeof a&&0===arguments.length)return this;if("function"!=typeof a){var b=a instanceof Array?a:Array.prototype.slice.call(arguments);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 x(c,{instantiateEmptyObject:this.instantiateEmptyObject})}function o(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(q(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function p(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 x(c)}function q(a){return!a||"object"!=typeof a||!Object.getOwnPropertyDescriptor(a,z)||a instanceof Date?a:a.asMutable({deep:!0})}function r(a,b){for(var c in a)Object.getOwnPropertyDescriptor(a,c)&&(b[c]=a[c]);return b}function s(a,b){function c(a,c,f){var g=y(c[f]),j=i&&i(a[f],g,b),k=a[f];if(void 0!==e||void 0!==j||!a.hasOwnProperty(f)||g!==k&&g===g){var l;l=j?j:h&&d(k)&&d(g)?k.merge(g,b):g,(k!==l&&l===l||!a.hasOwnProperty(f))&&(void 0===e&&(e=r(a,a.instantiateEmptyObject())),e[f]=l)}}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 e,f,g=a instanceof Array,h=b&&b.deep,i=b&&b.merger;if(g)for(var j=0;j<a.length;j++){var k=a[j];for(f in k)k.hasOwnProperty(f)&&c(this,k,f)}else for(f in a)Object.getOwnPropertyDescriptor(a,f)&&c(this,a,f);return void 0===e?this:x(e,{instantiateEmptyObject:this.instantiateEmptyObject})}function t(a,b){var c=a[0];if(1===a.length)return u.call(this,c,b);var d,e=a.slice(1),f=this[c];if(d=this.hasOwnProperty(c)&&"object"==typeof f&&null!==f&&"function"==typeof f.setIn?f.setIn(e,b):t.call(G,e,b),this.hasOwnProperty(c)&&f===d)return this;var g=r(this,this.instantiateEmptyObject());return g[c]=d,x(g,this)}function u(a,b){if(this.hasOwnProperty(a)&&this[a]===b)return this;var c=r(this,this.instantiateEmptyObject());return c[a]=y(b),x(c,this)}function v(a){var b,c=this.instantiateEmptyObject();if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=q(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function w(){return{}}function x(b,c){var d=c&&c.instantiateEmptyObject?c.instantiateEmptyObject:w;return a(b,"merge",s),a(b,"without",n),a(b,"asMutable",v),a(b,"instantiateEmptyObject",d),a(b,"set",u),a(b,"setIn",t),f(b,A)}function y(a,b){if(c(a))return a;if(a instanceof Array)return j(a.slice());if(a instanceof Date)return k(new Date(a.getTime()));var d=b&&b.prototype,e=d&&d!==Object.prototype?function(){return Object.create(d)}:w,f=e();for(var g in a)Object.getOwnPropertyDescriptor(a,g)&&(f[g]=y(a[g]));return x(f,{instantiateEmptyObject:e})}var z="__immutable_invariants_hold",A=["setPrototypeOf"],B=["keys"],C=A.concat(["push","pop","sort","splice","shift","unshift","reverse"]),D=B.concat(["map","filter","slice","concat","reduce","reduceRight"]),E=A.concat(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);e.prototype=Error.prototype;var F=y([]),G=y({});y.isImmutable=c,y.ImmutableError=e,Object.freeze(y),"object"==typeof module?module.exports=y:"object"==typeof exports?exports.Immutable=y:"object"==typeof window?window.Immutable=y:"object"==typeof global&&(global.Immutable=y)}(); |
@@ -28,3 +28,5 @@ (function() { | ||
if (typeof target === "object") { | ||
return target === null || target.hasOwnProperty(immutabilityTag); | ||
return target === null || Boolean( | ||
Object.getOwnPropertyDescriptor(target, immutabilityTag) | ||
); | ||
} else { | ||
@@ -65,2 +67,3 @@ // In JavaScript, only objects are even potentially mutable. | ||
var err = new Error(message); | ||
// TODO: Consider `Object.setPrototypeOf(err, ImmutableError);` | ||
err.__proto__ = ImmutableError; | ||
@@ -282,3 +285,8 @@ | ||
function asDeepMutable(obj) { | ||
if(!obj || !obj.hasOwnProperty(immutabilityTag) || obj instanceof Date) { return obj; } | ||
if ( | ||
(!obj) || | ||
(typeof obj !== 'object') || | ||
(!Object.getOwnPropertyDescriptor(obj, immutabilityTag)) || | ||
(obj instanceof Date) | ||
) { return obj; } | ||
return obj.asMutable({deep: true}); | ||
@@ -289,3 +297,3 @@ } | ||
for (var key in src) { | ||
if (src.hasOwnProperty(key)) { | ||
if (Object.getOwnPropertyDescriptor(src, key)) { | ||
dest[key] = src[key]; | ||
@@ -366,3 +374,3 @@ } | ||
for (key in other) { | ||
if (other.hasOwnProperty(key)) { | ||
if (Object.getOwnPropertyDescriptor(other, key)) { | ||
addToResult(this, other, key); | ||
@@ -487,3 +495,3 @@ } | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
if (Object.getOwnPropertyDescriptor(obj, key)) { | ||
clone[key] = Immutable(obj[key]); | ||
@@ -490,0 +498,0 @@ } |
@@ -17,3 +17,12 @@ var JSC = require("jscheck"); | ||
describe("Immutable", function () { | ||
it("makes an Immutable for Object.create(null)", function () { | ||
var mutable = Object.create(null); | ||
var immutable = Immutable(mutable); | ||
assert.typeOf(immutable, "object"); | ||
assert.isTrue(Immutable.isImmutable(immutable)); | ||
assert.isFalse(Immutable.isImmutable(mutable)); | ||
}); | ||
it("makes an Immutable Array when passed a mutable array", function () { | ||
@@ -20,0 +29,0 @@ TestUtils.check(100, [JSC.array()], function (mutable) { |
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
127760
2382
344