immutable 5.0.0-beta.4 → 5.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +2 -2
  2. package/dist/es/Collection.js +6 -1
  3. package/dist/es/CollectionImpl.js +11 -16
  4. package/dist/es/Hash.js +1 -0
  5. package/dist/es/Immutable.js +2 -2
  6. package/dist/es/Iterator.js +1 -0
  7. package/dist/es/List.js +7 -1
  8. package/dist/es/Map.js +4 -16
  9. package/dist/es/Math.js +1 -0
  10. package/dist/es/Operations.js +7 -6
  11. package/dist/es/OrderedMap.js +3 -1
  12. package/dist/es/OrderedSet.js +3 -1
  13. package/dist/es/PairSorting.js +1 -0
  14. package/dist/es/Range.js +16 -5
  15. package/dist/es/Record.js +3 -1
  16. package/dist/es/Repeat.js +5 -1
  17. package/dist/es/Seq.js +6 -1
  18. package/dist/es/Set.js +2 -0
  19. package/dist/es/Stack.js +2 -0
  20. package/dist/es/TrieUtils.js +2 -0
  21. package/dist/es/fromJS.js +1 -0
  22. package/dist/es/functional/get.js +1 -0
  23. package/dist/es/functional/getIn.js +1 -0
  24. package/dist/es/functional/has.js +1 -0
  25. package/dist/es/functional/hasIn.js +1 -0
  26. package/dist/es/functional/merge.js +1 -0
  27. package/dist/es/functional/remove.js +1 -0
  28. package/dist/es/functional/removeIn.js +1 -0
  29. package/dist/es/functional/set.js +1 -0
  30. package/dist/es/functional/setIn.js +1 -0
  31. package/dist/es/functional/update.js +1 -0
  32. package/dist/es/functional/updateIn.js +1 -0
  33. package/dist/es/is.js +1 -0
  34. package/dist/es/methods/asImmutable.js +1 -0
  35. package/dist/es/methods/asMutable.js +1 -0
  36. package/dist/es/methods/deleteIn.js +1 -0
  37. package/dist/es/methods/getIn.js +1 -0
  38. package/dist/es/methods/hasIn.js +1 -0
  39. package/dist/es/methods/merge.js +1 -0
  40. package/dist/es/methods/mergeDeep.js +1 -0
  41. package/dist/es/methods/mergeDeepIn.js +1 -0
  42. package/dist/es/methods/mergeIn.js +1 -0
  43. package/dist/es/methods/setIn.js +1 -0
  44. package/dist/es/methods/toObject.js +1 -0
  45. package/dist/es/methods/update.js +1 -0
  46. package/dist/es/methods/updateIn.js +1 -0
  47. package/dist/es/methods/wasAltered.js +1 -0
  48. package/dist/es/methods/withMutations.js +1 -0
  49. package/dist/es/package.json.js +2 -1
  50. package/dist/es/predicates/isAssociative.js +1 -0
  51. package/dist/es/predicates/isCollection.js +2 -0
  52. package/dist/es/predicates/isImmutable.js +1 -0
  53. package/dist/es/predicates/isIndexed.js +1 -0
  54. package/dist/es/predicates/isKeyed.js +1 -0
  55. package/dist/es/predicates/isList.js +1 -0
  56. package/dist/es/predicates/isMap.js +1 -0
  57. package/dist/es/predicates/isOrdered.js +1 -0
  58. package/dist/es/predicates/isOrderedMap.js +1 -0
  59. package/dist/es/predicates/isOrderedSet.js +1 -0
  60. package/dist/es/predicates/isRecord.js +1 -0
  61. package/dist/es/predicates/isSeq.js +1 -0
  62. package/dist/es/predicates/isSet.js +1 -0
  63. package/dist/es/predicates/isStack.js +1 -0
  64. package/dist/es/predicates/isValueObject.js +1 -0
  65. package/dist/es/toJS.js +1 -0
  66. package/dist/es/utils/arrCopy.js +3 -1
  67. package/dist/es/utils/assertNotInfinite.js +2 -1
  68. package/dist/es/utils/coerceKeyPath.js +2 -1
  69. package/dist/es/utils/deepEqual.js +2 -1
  70. package/dist/es/utils/hasOwnProperty.js +2 -1
  71. package/dist/es/utils/invariant.js +2 -1
  72. package/dist/es/utils/isArrayLike.js +2 -1
  73. package/dist/es/utils/isDataStructure.js +2 -1
  74. package/dist/es/utils/isPlainObj.js +2 -1
  75. package/dist/es/utils/mixin.js +5 -1
  76. package/dist/es/utils/quoteString.js +5 -1
  77. package/dist/es/utils/shallowCopy.js +2 -1
  78. package/dist/immutable.d.ts +14 -52
  79. package/dist/immutable.js +62 -40
  80. package/dist/immutable.js.flow +4 -2
  81. package/dist/immutable.min.js +2 -32
  82. package/package.json +1 -1
package/dist/immutable.js CHANGED
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @license
2
3
  * MIT License
3
4
  *
4
5
  * Copyright (c) 2014-present, Lee Byron and other contributors.
@@ -25,8 +26,9 @@
25
26
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
26
27
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
27
28
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Immutable = {}));
28
- }(this, (function (exports) { 'use strict';
29
+ })(this, (function (exports) { 'use strict';
29
30
 
31
+ // Used for setting prototype methods that IE8 chokes on.
30
32
  var DELETE = 'delete';
31
33
 
32
34
  // Constants describing the size of trie nodes.
@@ -118,6 +120,7 @@
118
120
  return value < 0 || (value === 0 && 1 / value === -Infinity);
119
121
  }
120
122
 
123
+ // Note: value is unchanged to not break immutable-devtools.
121
124
  var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
122
125
 
123
126
  function isCollection(maybeCollection) {
@@ -141,11 +144,13 @@
141
144
  }
142
145
 
143
146
  var Collection = function Collection(value) {
147
+ // eslint-disable-next-line no-constructor-return
144
148
  return isCollection(value) ? value : Seq(value);
145
149
  };
146
150
 
147
151
  var KeyedCollection = /*@__PURE__*/(function (Collection) {
148
152
  function KeyedCollection(value) {
153
+ // eslint-disable-next-line no-constructor-return
149
154
  return isKeyed(value) ? value : KeyedSeq(value);
150
155
  }
151
156
 
@@ -158,6 +163,7 @@
158
163
 
159
164
  var IndexedCollection = /*@__PURE__*/(function (Collection) {
160
165
  function IndexedCollection(value) {
166
+ // eslint-disable-next-line no-constructor-return
161
167
  return isIndexed(value) ? value : IndexedSeq(value);
162
168
  }
163
169
 
@@ -170,6 +176,7 @@
170
176
 
171
177
  var SetCollection = /*@__PURE__*/(function (Collection) {
172
178
  function SetCollection(value) {
179
+ // eslint-disable-next-line no-constructor-return
173
180
  return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
174
181
  }
175
182
 
@@ -310,6 +317,7 @@
310
317
 
311
318
  var Seq = /*@__PURE__*/(function (Collection) {
312
319
  function Seq(value) {
320
+ // eslint-disable-next-line no-constructor-return
313
321
  return value === undefined || value === null
314
322
  ? emptySequence()
315
323
  : isImmutable(value)
@@ -378,6 +386,7 @@
378
386
 
379
387
  var KeyedSeq = /*@__PURE__*/(function (Seq) {
380
388
  function KeyedSeq(value) {
389
+ // eslint-disable-next-line no-constructor-return
381
390
  return value === undefined || value === null
382
391
  ? emptySequence().toKeyedSeq()
383
392
  : isCollection(value)
@@ -402,6 +411,7 @@
402
411
 
403
412
  var IndexedSeq = /*@__PURE__*/(function (Seq) {
404
413
  function IndexedSeq(value) {
414
+ // eslint-disable-next-line no-constructor-return
405
415
  return value === undefined || value === null
406
416
  ? emptySequence()
407
417
  : isCollection(value)
@@ -434,6 +444,7 @@
434
444
 
435
445
  var SetSeq = /*@__PURE__*/(function (Seq) {
436
446
  function SetSeq(value) {
447
+ // eslint-disable-next-line no-constructor-return
437
448
  return (
438
449
  isCollection(value) && !isAssociative(value) ? value : IndexedSeq(value)
439
450
  ).toSetSeq();
@@ -1435,16 +1446,16 @@
1435
1446
  return collection;
1436
1447
  }
1437
1448
 
1438
- var resolvedBegin = resolveBegin(begin, originalSize);
1439
- var resolvedEnd = resolveEnd(end, originalSize);
1440
-
1441
- // begin or end will be NaN if they were provided as negative numbers and
1449
+ // begin or end can not be resolved if they were provided as negative numbers and
1442
1450
  // this collection's size is unknown. In that case, cache first so there is
1443
1451
  // a known size and these do not resolve to NaN.
1444
- if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
1452
+ if (typeof originalSize === 'undefined' && (begin < 0 || end < 0)) {
1445
1453
  return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
1446
1454
  }
1447
1455
 
1456
+ var resolvedBegin = resolveBegin(begin, originalSize);
1457
+ var resolvedEnd = resolveEnd(end, originalSize);
1458
+
1448
1459
  // Note: resolvedEnd is undefined when the original sequence's length is
1449
1460
  // unknown and this slice did not supply an end and should contain all
1450
1461
  // elements after resolvedBegin.
@@ -1935,6 +1946,7 @@
1935
1946
  return a > b ? 1 : a < b ? -1 : 0;
1936
1947
  }
1937
1948
 
1949
+ // http://jsperf.com/copy-array-inline
1938
1950
  function arrCopy(arr, offset) {
1939
1951
  offset = offset || 0;
1940
1952
  var len = Math.max(0, arr.length - offset);
@@ -2006,6 +2018,9 @@
2006
2018
  );
2007
2019
  }
2008
2020
 
2021
+ /**
2022
+ * Converts a value to a string, adding quotes if a string was provided.
2023
+ */
2009
2024
  function quoteString(value) {
2010
2025
  try {
2011
2026
  return typeof value === 'string' ? JSON.stringify(value) : String(value);
@@ -2382,6 +2397,7 @@
2382
2397
 
2383
2398
  var Map = /*@__PURE__*/(function (KeyedCollection) {
2384
2399
  function Map(value) {
2400
+ // eslint-disable-next-line no-constructor-return
2385
2401
  return value === undefined || value === null
2386
2402
  ? emptyMap()
2387
2403
  : isMap(value) && !isOrdered(value)
@@ -2397,20 +2413,6 @@
2397
2413
  Map.prototype = Object.create( KeyedCollection && KeyedCollection.prototype );
2398
2414
  Map.prototype.constructor = Map;
2399
2415
 
2400
- Map.of = function of () {
2401
- var keyValues = [], len = arguments.length;
2402
- while ( len-- ) keyValues[ len ] = arguments[ len ];
2403
-
2404
- return emptyMap().withMutations(function (map) {
2405
- for (var i = 0; i < keyValues.length; i += 2) {
2406
- if (i + 1 >= keyValues.length) {
2407
- throw new Error('Missing value for key: ' + keyValues[i]);
2408
- }
2409
- map.set(keyValues[i], keyValues[i + 1]);
2410
- }
2411
- });
2412
- };
2413
-
2414
2416
  Map.prototype.toString = function toString () {
2415
2417
  return this.__toString('Map {', '}');
2416
2418
  };
@@ -2900,7 +2902,7 @@
2900
2902
  }
2901
2903
  };
2902
2904
 
2903
- // eslint-disable-next-line no-unused-vars
2905
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2904
2906
  ValueNode.prototype.iterate = function (fn, reverse) {
2905
2907
  return fn(this.entry);
2906
2908
  };
@@ -3174,20 +3176,25 @@
3174
3176
  function List(value) {
3175
3177
  var empty = emptyList();
3176
3178
  if (value === undefined || value === null) {
3179
+ // eslint-disable-next-line no-constructor-return
3177
3180
  return empty;
3178
3181
  }
3179
3182
  if (isList(value)) {
3183
+ // eslint-disable-next-line no-constructor-return
3180
3184
  return value;
3181
3185
  }
3182
3186
  var iter = IndexedCollection(value);
3183
3187
  var size = iter.size;
3184
3188
  if (size === 0) {
3189
+ // eslint-disable-next-line no-constructor-return
3185
3190
  return empty;
3186
3191
  }
3187
3192
  assertNotInfinite(size);
3188
3193
  if (size > 0 && size < SIZE) {
3194
+ // eslint-disable-next-line no-constructor-return
3189
3195
  return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
3190
3196
  }
3197
+ // eslint-disable-next-line no-constructor-return
3191
3198
  return empty.withMutations(function (list) {
3192
3199
  list.setSize(size);
3193
3200
  iter.forEach(function (v, i) { return list.set(i, v); });
@@ -3823,6 +3830,7 @@
3823
3830
 
3824
3831
  var OrderedMap = /*@__PURE__*/(function (Map) {
3825
3832
  function OrderedMap(value) {
3833
+ // eslint-disable-next-line no-constructor-return
3826
3834
  return value === undefined || value === null
3827
3835
  ? emptyOrderedMap()
3828
3836
  : isOrderedMap(value)
@@ -3991,6 +3999,7 @@
3991
3999
 
3992
4000
  var Stack = /*@__PURE__*/(function (IndexedCollection) {
3993
4001
  function Stack(value) {
4002
+ // eslint-disable-next-line no-constructor-return
3994
4003
  return value === undefined || value === null
3995
4004
  ? emptyStack()
3996
4005
  : isStack(value)
@@ -4289,6 +4298,9 @@
4289
4298
  return allEqual && a.size === bSize;
4290
4299
  }
4291
4300
 
4301
+ /**
4302
+ * Contributes additional methods to a constructor
4303
+ */
4292
4304
  function mixin(ctor, methods) {
4293
4305
  var keyCopier = function (key) {
4294
4306
  ctor.prototype[key] = methods[key];
@@ -4325,6 +4337,7 @@
4325
4337
 
4326
4338
  var Set = /*@__PURE__*/(function (SetCollection) {
4327
4339
  function Set(value) {
4340
+ // eslint-disable-next-line no-constructor-return
4328
4341
  return value === undefined || value === null
4329
4342
  ? emptySet()
4330
4343
  : isSet(value) && !isOrdered(value)
@@ -4571,15 +4584,23 @@
4571
4584
  */
4572
4585
  var Range = /*@__PURE__*/(function (IndexedSeq) {
4573
4586
  function Range(start, end, step) {
4587
+ if ( step === void 0 ) step = 1;
4588
+
4574
4589
  if (!(this instanceof Range)) {
4590
+ // eslint-disable-next-line no-constructor-return
4575
4591
  return new Range(start, end, step);
4576
4592
  }
4577
4593
  invariant(step !== 0, 'Cannot step a Range by 0');
4578
- start = start || 0;
4579
- if (end === undefined) {
4580
- end = Infinity;
4581
- }
4582
- step = step === undefined ? 1 : Math.abs(step);
4594
+ invariant(
4595
+ start !== undefined,
4596
+ 'You must define a start value when using Range'
4597
+ );
4598
+ invariant(
4599
+ end !== undefined,
4600
+ 'You must define an end value when using Range'
4601
+ );
4602
+
4603
+ step = Math.abs(step);
4583
4604
  if (end < start) {
4584
4605
  step = -step;
4585
4606
  }
@@ -4589,8 +4610,10 @@
4589
4610
  this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
4590
4611
  if (this.size === 0) {
4591
4612
  if (EMPTY_RANGE) {
4613
+ // eslint-disable-next-line no-constructor-return
4592
4614
  return EMPTY_RANGE;
4593
4615
  }
4616
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
4594
4617
  EMPTY_RANGE = this;
4595
4618
  }
4596
4619
  }
@@ -4734,13 +4757,6 @@
4734
4757
  return object;
4735
4758
  }
4736
4759
 
4737
- // Note: all of these methods are deprecated.
4738
- Collection.isIterable = isCollection;
4739
- Collection.isKeyed = isKeyed;
4740
- Collection.isIndexed = isIndexed;
4741
- Collection.isAssociative = isAssociative;
4742
- Collection.isOrdered = isOrdered;
4743
-
4744
4760
  Collection.Iterator = Iterator;
4745
4761
 
4746
4762
  mixin(Collection, {
@@ -4975,6 +4991,7 @@
4975
4991
  },
4976
4992
 
4977
4993
  entrySeq: function entrySeq() {
4994
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
4978
4995
  var collection = this;
4979
4996
  if (collection._cache) {
4980
4997
  // We cache as an entries array, so we can just return the cache!
@@ -5425,7 +5442,8 @@
5425
5442
  var ordered = isOrdered(collection);
5426
5443
  var keyed = isKeyed(collection);
5427
5444
  var h = ordered ? 1 : 0;
5428
- var size = collection.__iterate(
5445
+
5446
+ collection.__iterate(
5429
5447
  keyed
5430
5448
  ? ordered
5431
5449
  ? function (v, k) {
@@ -5442,7 +5460,8 @@
5442
5460
  h = (h + hash(v)) | 0;
5443
5461
  }
5444
5462
  );
5445
- return murmurHashOfSize(size, h);
5463
+
5464
+ return murmurHashOfSize(collection.size, h);
5446
5465
  }
5447
5466
 
5448
5467
  function murmurHashOfSize(size, h) {
@@ -5462,6 +5481,7 @@
5462
5481
 
5463
5482
  var OrderedSet = /*@__PURE__*/(function (Set) {
5464
5483
  function OrderedSet(value) {
5484
+ // eslint-disable-next-line no-constructor-return
5465
5485
  return value === undefined || value === null
5466
5486
  ? emptyOrderedSet()
5467
5487
  : isOrderedSet(value)
@@ -5605,6 +5625,7 @@
5605
5625
  RecordType.displayName = name;
5606
5626
  }
5607
5627
 
5628
+ // eslint-disable-next-line no-constructor-return
5608
5629
  return RecordType;
5609
5630
  };
5610
5631
 
@@ -5772,14 +5793,17 @@
5772
5793
  var Repeat = /*@__PURE__*/(function (IndexedSeq) {
5773
5794
  function Repeat(value, times) {
5774
5795
  if (!(this instanceof Repeat)) {
5796
+ // eslint-disable-next-line no-constructor-return
5775
5797
  return new Repeat(value, times);
5776
5798
  }
5777
5799
  this._value = value;
5778
5800
  this.size = times === undefined ? Infinity : Math.max(0, times);
5779
5801
  if (this.size === 0) {
5780
5802
  if (EMPTY_REPEAT) {
5803
+ // eslint-disable-next-line no-constructor-return
5781
5804
  return EMPTY_REPEAT;
5782
5805
  }
5806
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
5783
5807
  EMPTY_REPEAT = this;
5784
5808
  }
5785
5809
  }
@@ -5856,7 +5880,7 @@
5856
5880
  Repeat.prototype.equals = function equals (other) {
5857
5881
  return other instanceof Repeat
5858
5882
  ? is(this._value, other._value)
5859
- : deepEqual(other);
5883
+ : deepEqual(this, other);
5860
5884
  };
5861
5885
 
5862
5886
  return Repeat;
@@ -5905,7 +5929,7 @@
5905
5929
  return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
5906
5930
  }
5907
5931
 
5908
- var version = "5.0.0-beta.4";
5932
+ var version = "5.0.0-rc.1";
5909
5933
 
5910
5934
  // Note: Iterable is deprecated
5911
5935
  var Iterable = Collection;
@@ -5958,6 +5982,4 @@
5958
5982
  exports.updateIn = updateIn$1;
5959
5983
  exports.version = version;
5960
5984
 
5961
- Object.defineProperty(exports, '__esModule', { value: true });
5962
-
5963
- })));
5985
+ }));
@@ -76,8 +76,10 @@ declare class _Collection<K, +V> implements ValueObject {
76
76
  has(key: K): boolean;
77
77
  includes(value: V): boolean;
78
78
  contains(value: V): boolean;
79
- first<NSV>(notSetValue?: NSV): V | NSV;
80
- last<NSV>(notSetValue?: NSV): V | NSV;
79
+ first(): V | void;
80
+ first<NSV>(notSetValue: NSV): V | NSV;
81
+ last(): V | void;
82
+ last<NSV>(notSetValue: NSV): V | NSV;
81
83
 
82
84
  hasIn(keyPath: Iterable<mixed>): boolean;
83
85