seamless-immutable
Advanced tools
Comparing version 4.1.1 to 5.0.0
{ | ||
"name": "seamless-immutable", | ||
"main": "src/seamless-immutable.js", | ||
"version": "4.0.2", | ||
"version": "5.0.0", | ||
"homepage": "https://github.com/rtfeldman/seamless-immutable", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "seamless-immutable", | ||
"version": "4.1.1", | ||
"version": "5.0.0", | ||
"description": "Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.", | ||
@@ -23,3 +23,3 @@ "main": "src/seamless-immutable.js", | ||
"scripts": { | ||
"test": "mocha test/*.spec.js", | ||
"test": "grunt", | ||
"test-watch": "mocha --watch test/*.spec.js", | ||
@@ -26,0 +26,0 @@ "jshint": "jshint seamless-immutable.development.js", |
@@ -39,2 +39,4 @@ seamless-immutable | ||
We generally recommend to use the "development" build that enforces immutability (and this is the default in Node.js). Only switch to the production build when you encounter performance problems. (See #50 for how to do that in Node or using a build tool - essentially do explicitely refer to the production build.) | ||
## API Overview | ||
@@ -194,3 +196,3 @@ | ||
Like [set](#set), but accepts a nested path to the property. | ||
Like [set](#set), but accepts a nested path to the property. | ||
@@ -233,2 +235,6 @@ ```javascript | ||
#### 5.0.0 | ||
In development build, freeze Dates and ban mutating methods. | ||
#### 4.1.1 | ||
@@ -235,0 +241,0 @@ |
@@ -1,2 +0,2 @@ | ||
(function(){ | ||
(function() { | ||
"use strict"; | ||
@@ -56,2 +56,8 @@ | ||
var mutatingDateMethods = mutatingObjectMethods.concat([ | ||
"setDate", "setFullYear", "setHours", "setMilliseconds", "setMinutes", "setMonth", "setSeconds", | ||
"setTime", "setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", | ||
"setUTCMonth", "setUTCSeconds", "setYear" | ||
]); | ||
function ImmutableError(message) { | ||
@@ -154,2 +160,12 @@ var err = new Error(message); | ||
function makeImmutableDate(date) { | ||
addPropertyTo(date, "asMutable", asMutableDate); | ||
return makeImmutable(date, mutatingDateMethods); | ||
} | ||
function asMutableDate() { | ||
return new Date(this.getTime()); | ||
} | ||
/** | ||
@@ -220,3 +236,3 @@ * Effectively performs a map() over the elements in the array, using the | ||
for(i = 0, length = this.length; i < length; i++) { | ||
result.push( asDeepMutable(this[i]) ); | ||
result.push(asDeepMutable(this[i])); | ||
} | ||
@@ -454,3 +470,3 @@ } else { | ||
} else if (obj instanceof Date) { | ||
return makeImmutable(new Date(obj.getTime())); | ||
return makeImmutableDate(new Date(obj.getTime())); | ||
} else { | ||
@@ -457,0 +473,0 @@ // Don't freeze the object we were given; make a clone and use that. |
@@ -25,3 +25,4 @@ var JSC = require("jscheck"); | ||
"objects": [false, JSC.object()], | ||
"arrays": [false, JSC.array()] | ||
"arrays": [false, JSC.array()], | ||
"dates": [false, JSC.literal(new Date())] | ||
}, function (tuple, type) { | ||
@@ -28,0 +29,0 @@ var expectImmutable = tuple[0]; |
@@ -28,2 +28,12 @@ var JSC = require("jscheck"); | ||
it("makes an Immutable Date when passed a mutable Date", function () { | ||
TestUtils.check(100, [JSC.literal(new Date())], function (mutable) { | ||
var immutable = Immutable(mutable); | ||
assert.deepEqual(immutable, mutable); | ||
assert.isTrue(Immutable.isImmutable(immutable)); | ||
assert.isFalse(Immutable.isImmutable(mutable)); | ||
}); | ||
}); | ||
it("makes an Immutable Object when passed a mutable object", function () { | ||
@@ -48,3 +58,3 @@ TestUtils.check(100, [JSC.object()], function (mutable) { | ||
}) | ||
}) | ||
}); | ||
@@ -51,0 +61,0 @@ it("doesn't fail when a function is defined on Array.prototype", function() { |
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
117860
31
2300
323