seamless-immutable
Advanced tools
Comparing version 2.3.1 to 2.3.2
{ | ||
"name": "seamless-immutable", | ||
"main": "seamless-immutable.js", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"homepage": "https://github.com/rtfeldman/seamless-immutable", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "seamless-immutable", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.", | ||
@@ -5,0 +5,0 @@ "main": "seamless-immutable.development.js", |
@@ -86,3 +86,3 @@ seamless-immutable | ||
Beyond the usual Array fare, the following methods have been added. | ||
Beyond [the usual Array fare](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Accessor_methods), the following methods have been added. | ||
@@ -123,2 +123,5 @@ ### flatMap | ||
You can also call `.asObject` without passing an iterator, in which case it will proceed assuming the Array | ||
is already organized as desired. | ||
### asMutable | ||
@@ -146,3 +149,3 @@ | ||
Beyond the usual Object fare, the following methods have been added. | ||
Beyond [the usual Object fare](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#Methods_of_Object_instances), the following methods have been added. | ||
@@ -201,2 +204,6 @@ ### merge | ||
#### 2.3.2 | ||
Fixes a bug where indices passed into iterators for flatMap and asObject were strings instead of numbers. | ||
#### 2.3.1 | ||
@@ -203,0 +210,0 @@ |
@@ -121,6 +121,8 @@ (function(){ | ||
var result = []; | ||
var result = [], | ||
length = this.length, | ||
index; | ||
for (var key in this) { | ||
var iteratorResult = iterator(this[key], key, this); | ||
for (index = 0; index < length; index++) { | ||
var iteratorResult = iterator(this[index], index, this); | ||
@@ -196,5 +198,7 @@ if (iteratorResult instanceof Array) { | ||
var result = {}; | ||
var result = {}, | ||
length = this.length, | ||
index; | ||
for (var index in this) { | ||
for (index = 0; index < length; index++) { | ||
var pair = iterator(this[index], index, this), | ||
@@ -252,3 +256,3 @@ key = pair[0], | ||
var immutableValue = Immutable(otherObj[key]); | ||
var mergerResult = merger && merger(currentObj[key], immutableValue); | ||
var mergerResult = merger && merger(currentObj[key], immutableValue, config); | ||
@@ -255,0 +259,0 @@ anyChanges = anyChanges || |
@@ -1,1 +0,1 @@ | ||
!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,s,!0)}function c(a){return"object"==typeof a?null===a||a.hasOwnProperty(s):!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 r(d.apply(b,arguments))})}function h(b){for(var c in w){var d=w[c];g(b,d)}a(b,"flatMap",i),a(b,"asObject",l),a(b,"asMutable",k);for(var e=0,h=b.length;h>e;e++)b[e]=r(b[e]);return f(b,v)}function i(a){if(0===arguments.length)return this;var b=[];for(var c in this){var d=a(this[c],c,this);d instanceof Array?b.push.apply(b,d):b.push(d)}return h(b)}function j(a){if(0===arguments.length)return this;a instanceof Array||(a=Array.prototype.slice.call(arguments));var b={};for(var c in this)-1===a.indexOf(c)&&(b[c]=this[c]);return q(b)}function k(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(m(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function l(a){"function"!=typeof a&&(a=function(a){return a});var b={};for(var c in this){var d=a(this[c],c,this),e=d[0],f=d[1];b[e]=f}return q(b)}function m(a){return a&&a.hasOwnProperty(s)?a.asMutable({deep:!0}):a}function n(a,b){for(var c in a)b[c]=a[c];return b}function o(a,b){function c(a,c,e){var h=r(c[e]),k=j&&j(a[e],h);f=f||void 0!==k||!a.hasOwnProperty(e)||h!==a[e]&&h===h,g[e]=k?k:i&&d(a[e])&&d(h)?a[e].merge(h,b):h}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=!1,g=n(this,{}),h=a instanceof Array,i=b&&b.deep,j=b&&b.merger;if(h)for(var k in a){var l=a[k];for(e in l)c(this,l,e)}else for(e in a)c(this,a,e);return f?q(g):this}function p(a){var b,c={};if(a&&a.deep)for(b in this)c[b]=m(this[b]);else for(b in this)c[b]=this[b];return c}function q(b){return a(b,"merge",o),a(b,"without",j),a(b,"asMutable",p),f(b,t)}function r(a){if(arguments.length>1)return h(Array.prototype.slice.call(arguments));if(c(a))return a;if(a instanceof Array)return h(a.slice());if(a instanceof Date)return f(new Date(a.getTime()));var b={};for(var d in a)b[d]=r(a[d]);return q(b)}var s="__immutable_invariants_hold",t=["setPrototypeOf"],u=["keys"],v=t.concat(["push","pop","sort","splice","shift","unshift","reverse"]),w=u.concat(["map","filter","slice","concat","reduce","reduceRight"]);e.prototype=Error.prototype,r.isImmutable=c,r.ImmutableError=e,Object.freeze(r),"object"==typeof module?module.exports=r:"object"==typeof exports?exports.Immutable=r:"object"==typeof window?window.Immutable=r:"object"==typeof global&&(global.Immutable=r)}(); | ||
!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,s,!0)}function c(a){return"object"==typeof a?null===a||a.hasOwnProperty(s):!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 r(d.apply(b,arguments))})}function h(b){for(var c in w){var d=w[c];g(b,d)}a(b,"flatMap",i),a(b,"asObject",l),a(b,"asMutable",k);for(var e=0,h=b.length;h>e;e++)b[e]=r(b[e]);return f(b,v)}function i(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 h(c)}function j(a){if(0===arguments.length)return this;a instanceof Array||(a=Array.prototype.slice.call(arguments));var b={};for(var c in this)-1===a.indexOf(c)&&(b[c]=this[c]);return q(b)}function k(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(m(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function l(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 q(c)}function m(a){return a&&a.hasOwnProperty(s)?a.asMutable({deep:!0}):a}function n(a,b){for(var c in a)b[c]=a[c];return b}function o(a,b){function c(a,c,e){var h=r(c[e]),k=j&&j(a[e],h,b);f=f||void 0!==k||!a.hasOwnProperty(e)||h!==a[e]&&h===h,g[e]=k?k:i&&d(a[e])&&d(h)?a[e].merge(h,b):h}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=!1,g=n(this,{}),h=a instanceof Array,i=b&&b.deep,j=b&&b.merger;if(h)for(var k in a){var l=a[k];for(e in l)c(this,l,e)}else for(e in a)c(this,a,e);return f?q(g):this}function p(a){var b,c={};if(a&&a.deep)for(b in this)c[b]=m(this[b]);else for(b in this)c[b]=this[b];return c}function q(b){return a(b,"merge",o),a(b,"without",j),a(b,"asMutable",p),f(b,t)}function r(a){if(arguments.length>1)return h(Array.prototype.slice.call(arguments));if(c(a))return a;if(a instanceof Array)return h(a.slice());if(a instanceof Date)return f(new Date(a.getTime()));var b={};for(var d in a)b[d]=r(a[d]);return q(b)}var s="__immutable_invariants_hold",t=["setPrototypeOf"],u=["keys"],v=t.concat(["push","pop","sort","splice","shift","unshift","reverse"]),w=u.concat(["map","filter","slice","concat","reduce","reduceRight"]);e.prototype=Error.prototype,r.isImmutable=c,r.ImmutableError=e,Object.freeze(r),"object"==typeof module?module.exports=r:"object"==typeof exports?exports.Immutable=r:"object"==typeof window?window.Immutable=r:"object"==typeof global&&(global.Immutable=r)}(); |
@@ -121,6 +121,8 @@ (function(){ | ||
var result = []; | ||
var result = [], | ||
length = this.length, | ||
index; | ||
for (var key in this) { | ||
var iteratorResult = iterator(this[key], key, this); | ||
for (index = 0; index < length; index++) { | ||
var iteratorResult = iterator(this[index], index, this); | ||
@@ -196,5 +198,7 @@ if (iteratorResult instanceof Array) { | ||
var result = {}; | ||
var result = {}, | ||
length = this.length, | ||
index; | ||
for (var index in this) { | ||
for (index = 0; index < length; index++) { | ||
var pair = iterator(this[index], index, this), | ||
@@ -252,3 +256,3 @@ key = pair[0], | ||
var immutableValue = Immutable(otherObj[key]); | ||
var mergerResult = merger && merger(currentObj[key], immutableValue); | ||
var mergerResult = merger && merger(currentObj[key], immutableValue, config); | ||
@@ -255,0 +259,0 @@ anyChanges = anyChanges || |
@@ -21,2 +21,4 @@ var JSC = require("jscheck"); | ||
var result = array.asObject(function(value, index) { | ||
assert.strictEqual((typeof index), "number"); | ||
// Check that the index argument we receive works as expected. | ||
@@ -34,3 +36,2 @@ assert.deepEqual(value, array[index], "Expected array[" + index + "] to be " + value); | ||
check(100, [TestUtils.ComplexObjectSpecifier()], function(obj) { | ||
var keys = _.keys(obj); | ||
var array = Immutable(_.map(obj, function(value, key) { | ||
@@ -37,0 +38,0 @@ return [key, value]; |
@@ -33,2 +33,12 @@ var JSC = require("jscheck"); | ||
it("passes the expected index value", function() { | ||
check(100, [JSC.array()], function(array) { | ||
var iterator = function(value, index) { return index; }; | ||
var expected = _.map(array, iterator); | ||
var actual = Immutable(array).flatMap(iterator); | ||
assert.deepEqual(actual, expected); | ||
}); | ||
}); | ||
it("works the same way as map followed by flatten when the iterator function returns arrays", function() { | ||
@@ -35,0 +45,0 @@ check(100, [JSC.array()], function(array) { |
97073
1652
255