diff --git a/package.json b/package.json index 1faa3c6..85b174c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "detox", "utils" ], - "version" : "1.5.0", + "version" : "1.6.0", "homepage" : "https://github.com/Detox/utils", "author" : "Nazar Mokrynskyi ", "repository" : { diff --git a/src/index.js b/src/index.js index 3da5487..a4705a4 100644 --- a/src/index.js +++ b/src/index.js @@ -244,9 +244,9 @@ * * Implementation keeps weak references to make the whole thing fast and efficient */ - function ArrayMap(){ - var x$; - x$ = new Map; + function ArrayMap(array){ + var x$, map, i$, len$, ref$, key, value; + x$ = map = new Map; x$.get = function(key){ key = get_unique_key(key); return Map.prototype.get.call(this, key); @@ -275,7 +275,13 @@ this$['delete'](key); }); }; - return x$; + if (array) { + for (i$ = 0, len$ = array.length; i$ < len$; ++i$) { + ref$ = array[i$], key = ref$[0], value = ref$[1]; + map.set(key, value); + } + } + return map; } /** * This is a Set with very interesting property: different arrays with the same contents will be treated as the same array diff --git a/src/index.ls b/src/index.ls index e73c5f7..0fb667e 100644 --- a/src/index.ls +++ b/src/index.ls @@ -203,8 +203,8 @@ function get_unique_key (key) * * Implementation keeps weak references to make the whole thing fast and efficient */ -function ArrayMap - new Map +function ArrayMap (array) + map = new Map ..get = (key) -> key = get_unique_key(key) Map::get.call(@, key) @@ -224,6 +224,10 @@ function ArrayMap ..clear = !-> @forEach (, key) !~> @delete(key) + if array + for [key, value] in array + map.set(key, value) + map # LiveScript doesn't support classes, so we do it in ugly way /** * This is a Set with very interesting property: different arrays with the same contents will be treated as the same array diff --git a/src/index.min.js b/src/index.min.js index e05adfe..fd2b335 100644 --- a/src/index.min.js +++ b/src/index.min.js @@ -1,10 +1,10 @@ /* 0BSD */ -(function(){function p(a,b){var c=h(4);c=(new Uint32Array(c.buffer))[0];return Math.floor(c/Math.pow(2,32)*(b-a+1))+a}function v(a){var b=a.length;if(1===b)return a.pop();b=p(0,b-1);return a.splice(b,1)[0]}function w(a){var b;var c="";var d=0;for(b=a.length;d