immutable 5.0.2 → 5.1.0
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.
- package/README.md +2 -2
- package/dist/immutable.es.js +771 -476
- package/dist/immutable.js +5533 -5238
- package/dist/immutable.min.js +1 -1
- package/dist/{immutable.d.ts → type-definitions/immutable.d.ts} +253 -109
- package/dist/{immutable.js.flow → type-definitions/immutable.js.flow} +60 -60
- package/package.json +1 -1
package/dist/immutable.es.js
CHANGED
|
@@ -24,117 +24,162 @@
|
|
|
24
24
|
*/
|
|
25
25
|
// Used for setting prototype methods that IE8 chokes on.
|
|
26
26
|
var DELETE = 'delete';
|
|
27
|
-
|
|
28
27
|
// Constants describing the size of trie nodes.
|
|
29
28
|
var SHIFT = 5; // Resulted in best performance after ______?
|
|
30
29
|
var SIZE = 1 << SHIFT;
|
|
31
30
|
var MASK = SIZE - 1;
|
|
32
|
-
|
|
33
31
|
// A consistent shared value representing "not set" which equals nothing other
|
|
34
32
|
// than itself, and nothing that could be provided externally.
|
|
35
33
|
var NOT_SET = {};
|
|
36
|
-
|
|
37
34
|
// Boolean references, Rough equivalent of `bool &`.
|
|
38
35
|
function MakeRef() {
|
|
39
|
-
|
|
36
|
+
return { value: false };
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
function SetRef(ref) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
if (ref) {
|
|
40
|
+
ref.value = true;
|
|
41
|
+
}
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
// A function which returns a value representing an "owner" for transient writes
|
|
49
44
|
// to tries. The return value will only ever equal itself, and will not equal
|
|
50
45
|
// the return of any subsequent call of this function.
|
|
51
|
-
function OwnerID() {}
|
|
52
|
-
|
|
46
|
+
function OwnerID() { }
|
|
53
47
|
function ensureSize(iter) {
|
|
54
|
-
|
|
55
|
-
iter.size
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
// @ts-expect-error size should exists on Collection
|
|
49
|
+
if (iter.size === undefined) {
|
|
50
|
+
// @ts-expect-error size should exists on Collection, __iterate does exist on Collection
|
|
51
|
+
iter.size = iter.__iterate(returnTrue);
|
|
52
|
+
}
|
|
53
|
+
// @ts-expect-error size should exists on Collection
|
|
54
|
+
return iter.size;
|
|
58
55
|
}
|
|
59
|
-
|
|
60
56
|
function wrapIndex(iter, index) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
// This implements "is array index" which the ECMAString spec defines as:
|
|
58
|
+
//
|
|
59
|
+
// A String property name P is an array index if and only if
|
|
60
|
+
// ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
|
|
61
|
+
// to 2^32−1.
|
|
62
|
+
//
|
|
63
|
+
// http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
|
|
64
|
+
if (typeof index !== 'number') {
|
|
65
|
+
var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
|
|
66
|
+
if ('' + uint32Index !== index || uint32Index === 4294967295) {
|
|
67
|
+
return NaN;
|
|
68
|
+
}
|
|
69
|
+
index = uint32Index;
|
|
72
70
|
}
|
|
73
|
-
index
|
|
74
|
-
}
|
|
75
|
-
return index < 0 ? ensureSize(iter) + index : index;
|
|
71
|
+
return index < 0 ? ensureSize(iter) + index : index;
|
|
76
72
|
}
|
|
77
|
-
|
|
78
73
|
function returnTrue() {
|
|
79
|
-
|
|
74
|
+
return true;
|
|
80
75
|
}
|
|
81
|
-
|
|
82
76
|
function wholeSlice(begin, end, size) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
(end === undefined || (size !== undefined && end >= size))
|
|
87
|
-
);
|
|
77
|
+
return (((begin === 0 && !isNeg(begin)) ||
|
|
78
|
+
(size !== undefined && begin <= -size)) &&
|
|
79
|
+
(end === undefined || (size !== undefined && end >= size)));
|
|
88
80
|
}
|
|
89
|
-
|
|
90
81
|
function resolveBegin(begin, size) {
|
|
91
|
-
|
|
82
|
+
return resolveIndex(begin, size, 0);
|
|
92
83
|
}
|
|
93
|
-
|
|
94
84
|
function resolveEnd(end, size) {
|
|
95
|
-
|
|
85
|
+
return resolveIndex(end, size, size);
|
|
96
86
|
}
|
|
97
|
-
|
|
98
87
|
function resolveIndex(index, size, defaultIndex) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
88
|
+
// Sanitize indices using this shorthand for ToInt32(argument)
|
|
89
|
+
// http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
|
|
90
|
+
return index === undefined
|
|
91
|
+
? defaultIndex
|
|
92
|
+
: isNeg(index)
|
|
93
|
+
? size === Infinity
|
|
94
|
+
? size
|
|
95
|
+
: Math.max(0, size + index) | 0
|
|
96
|
+
: size === undefined || size === index
|
|
97
|
+
? index
|
|
98
|
+
: Math.min(size, index) | 0;
|
|
110
99
|
}
|
|
111
|
-
|
|
112
100
|
function isNeg(value) {
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
// Account for -0 which is negative, but not less than 0.
|
|
102
|
+
return value < 0 || (value === 0 && 1 / value === -Infinity);
|
|
115
103
|
}
|
|
116
104
|
|
|
117
105
|
// Note: value is unchanged to not break immutable-devtools.
|
|
118
106
|
var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
|
|
119
|
-
|
|
107
|
+
/**
|
|
108
|
+
* True if `maybeCollection` is a Collection, or any of its subclasses.
|
|
109
|
+
*
|
|
110
|
+
* ```js
|
|
111
|
+
* import { isCollection, Map, List, Stack } from 'immutable';
|
|
112
|
+
*
|
|
113
|
+
* isCollection([]); // false
|
|
114
|
+
* isCollection({}); // false
|
|
115
|
+
* isCollection(Map()); // true
|
|
116
|
+
* isCollection(List()); // true
|
|
117
|
+
* isCollection(Stack()); // true
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
120
|
function isCollection(maybeCollection) {
|
|
121
|
-
|
|
121
|
+
return Boolean(maybeCollection &&
|
|
122
|
+
// @ts-expect-error: maybeCollection is typed as `{}`, need to change in 6.0 to `maybeCollection && typeof maybeCollection === 'object' && IS_COLLECTION_SYMBOL in maybeCollection`
|
|
123
|
+
maybeCollection[IS_COLLECTION_SYMBOL]);
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
|
|
125
|
-
|
|
127
|
+
/**
|
|
128
|
+
* True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
|
|
129
|
+
*
|
|
130
|
+
* ```js
|
|
131
|
+
* import { isKeyed, Map, List, Stack } from 'immutable';
|
|
132
|
+
*
|
|
133
|
+
* isKeyed([]); // false
|
|
134
|
+
* isKeyed({}); // false
|
|
135
|
+
* isKeyed(Map()); // true
|
|
136
|
+
* isKeyed(List()); // false
|
|
137
|
+
* isKeyed(Stack()); // false
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
126
140
|
function isKeyed(maybeKeyed) {
|
|
127
|
-
|
|
141
|
+
return Boolean(maybeKeyed &&
|
|
142
|
+
// @ts-expect-error: maybeKeyed is typed as `{}`, need to change in 6.0 to `maybeKeyed && typeof maybeKeyed === 'object' && IS_KEYED_SYMBOL in maybeKeyed`
|
|
143
|
+
maybeKeyed[IS_KEYED_SYMBOL]);
|
|
128
144
|
}
|
|
129
145
|
|
|
130
146
|
var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
|
|
131
|
-
|
|
147
|
+
/**
|
|
148
|
+
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
|
|
149
|
+
*
|
|
150
|
+
* ```js
|
|
151
|
+
* import { isIndexed, Map, List, Stack, Set } from 'immutable';
|
|
152
|
+
*
|
|
153
|
+
* isIndexed([]); // false
|
|
154
|
+
* isIndexed({}); // false
|
|
155
|
+
* isIndexed(Map()); // false
|
|
156
|
+
* isIndexed(List()); // true
|
|
157
|
+
* isIndexed(Stack()); // true
|
|
158
|
+
* isIndexed(Set()); // false
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
132
161
|
function isIndexed(maybeIndexed) {
|
|
133
|
-
|
|
162
|
+
return Boolean(maybeIndexed &&
|
|
163
|
+
// @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
|
|
164
|
+
maybeIndexed[IS_INDEXED_SYMBOL]);
|
|
134
165
|
}
|
|
135
166
|
|
|
167
|
+
/**
|
|
168
|
+
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
|
|
169
|
+
*
|
|
170
|
+
* ```js
|
|
171
|
+
* import { isAssociative, Map, List, Stack, Set } from 'immutable';
|
|
172
|
+
*
|
|
173
|
+
* isAssociative([]); // false
|
|
174
|
+
* isAssociative({}); // false
|
|
175
|
+
* isAssociative(Map()); // true
|
|
176
|
+
* isAssociative(List()); // true
|
|
177
|
+
* isAssociative(Stack()); // true
|
|
178
|
+
* isAssociative(Set()); // false
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
136
181
|
function isAssociative(maybeAssociative) {
|
|
137
|
-
|
|
182
|
+
return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
|
|
138
183
|
}
|
|
139
184
|
|
|
140
185
|
var Collection = function Collection(value) {
|
|
@@ -186,25 +231,49 @@ Collection.Indexed = IndexedCollection;
|
|
|
186
231
|
Collection.Set = SetCollection;
|
|
187
232
|
|
|
188
233
|
var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
|
|
189
|
-
|
|
234
|
+
/**
|
|
235
|
+
* True if `maybeSeq` is a Seq.
|
|
236
|
+
*/
|
|
190
237
|
function isSeq(maybeSeq) {
|
|
191
|
-
|
|
238
|
+
return Boolean(maybeSeq &&
|
|
239
|
+
// @ts-expect-error: maybeSeq is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSeq === 'object' && MAYBE_SEQ_SYMBOL in maybeSeq`
|
|
240
|
+
maybeSeq[IS_SEQ_SYMBOL]);
|
|
192
241
|
}
|
|
193
242
|
|
|
194
243
|
var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
|
|
195
|
-
|
|
244
|
+
/**
|
|
245
|
+
* True if `maybeRecord` is a Record.
|
|
246
|
+
*/
|
|
196
247
|
function isRecord(maybeRecord) {
|
|
197
|
-
|
|
248
|
+
return Boolean(maybeRecord &&
|
|
249
|
+
// @ts-expect-error: maybeRecord is typed as `{}`, need to change in 6.0 to `maybeRecord && typeof maybeRecord === 'object' && IS_RECORD_SYMBOL in maybeRecord`
|
|
250
|
+
maybeRecord[IS_RECORD_SYMBOL]);
|
|
198
251
|
}
|
|
199
252
|
|
|
253
|
+
/**
|
|
254
|
+
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
255
|
+
*
|
|
256
|
+
* Note: Still returns true even if the collections is within a `withMutations()`.
|
|
257
|
+
*
|
|
258
|
+
* ```js
|
|
259
|
+
* import { isImmutable, Map, List, Stack } from 'immutable';
|
|
260
|
+
* isImmutable([]); // false
|
|
261
|
+
* isImmutable({}); // false
|
|
262
|
+
* isImmutable(Map()); // true
|
|
263
|
+
* isImmutable(List()); // true
|
|
264
|
+
* isImmutable(Stack()); // true
|
|
265
|
+
* isImmutable(Map().asMutable()); // true
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
200
268
|
function isImmutable(maybeImmutable) {
|
|
201
|
-
|
|
269
|
+
return isCollection(maybeImmutable) || isRecord(maybeImmutable);
|
|
202
270
|
}
|
|
203
271
|
|
|
204
272
|
var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
|
|
205
|
-
|
|
206
273
|
function isOrdered(maybeOrdered) {
|
|
207
|
-
|
|
274
|
+
return Boolean(maybeOrdered &&
|
|
275
|
+
// @ts-expect-error: maybeOrdered is typed as `{}`, need to change in 6.0 to `maybeOrdered && typeof maybeOrdered === 'object' && IS_ORDERED_SYMBOL in maybeOrdered`
|
|
276
|
+
maybeOrdered[IS_ORDERED_SYMBOL]);
|
|
208
277
|
}
|
|
209
278
|
|
|
210
279
|
var ITERATE_KEYS = 0;
|
|
@@ -236,7 +305,9 @@ Iterator.prototype[ITERATOR_SYMBOL] = function () {
|
|
|
236
305
|
};
|
|
237
306
|
|
|
238
307
|
function iteratorValue(type, k, v, iteratorResult) {
|
|
239
|
-
var value =
|
|
308
|
+
var value =
|
|
309
|
+
type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v];
|
|
310
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
240
311
|
iteratorResult
|
|
241
312
|
? (iteratorResult.value = value)
|
|
242
313
|
: (iteratorResult = {
|
|
@@ -291,22 +362,24 @@ function isKeysIterable(maybeIterable) {
|
|
|
291
362
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
292
363
|
|
|
293
364
|
function isArrayLike(value) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
365
|
+
if (Array.isArray(value) || typeof value === 'string') {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
// @ts-expect-error "Type 'unknown' is not assignable to type 'boolean'" : convert to Boolean
|
|
369
|
+
return (value &&
|
|
370
|
+
typeof value === 'object' &&
|
|
371
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
372
|
+
Number.isInteger(value.length) &&
|
|
373
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
374
|
+
value.length >= 0 &&
|
|
375
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
376
|
+
(value.length === 0
|
|
377
|
+
? // Only {length: 0} is considered Array-like.
|
|
378
|
+
Object.keys(value).length === 1
|
|
379
|
+
: // An object is only Array-like if it has a property where the last value
|
|
380
|
+
// in the array-like may be found (which could be undefined).
|
|
381
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
382
|
+
value.hasOwnProperty(value.length - 1)));
|
|
310
383
|
}
|
|
311
384
|
|
|
312
385
|
var Seq = /*@__PURE__*/(function (Collection) {
|
|
@@ -315,8 +388,8 @@ var Seq = /*@__PURE__*/(function (Collection) {
|
|
|
315
388
|
return value === undefined || value === null
|
|
316
389
|
? emptySequence()
|
|
317
390
|
: isImmutable(value)
|
|
318
|
-
|
|
319
|
-
|
|
391
|
+
? value.toSeq()
|
|
392
|
+
: seqFromValue(value);
|
|
320
393
|
}
|
|
321
394
|
|
|
322
395
|
if ( Collection ) Seq.__proto__ = Collection;
|
|
@@ -384,12 +457,12 @@ var KeyedSeq = /*@__PURE__*/(function (Seq) {
|
|
|
384
457
|
return value === undefined || value === null
|
|
385
458
|
? emptySequence().toKeyedSeq()
|
|
386
459
|
: isCollection(value)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
460
|
+
? isKeyed(value)
|
|
461
|
+
? value.toSeq()
|
|
462
|
+
: value.fromEntrySeq()
|
|
463
|
+
: isRecord(value)
|
|
464
|
+
? value.toSeq()
|
|
465
|
+
: keyedSeqFromValue(value);
|
|
393
466
|
}
|
|
394
467
|
|
|
395
468
|
if ( Seq ) KeyedSeq.__proto__ = Seq;
|
|
@@ -409,12 +482,12 @@ var IndexedSeq = /*@__PURE__*/(function (Seq) {
|
|
|
409
482
|
return value === undefined || value === null
|
|
410
483
|
? emptySequence()
|
|
411
484
|
: isCollection(value)
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
485
|
+
? isKeyed(value)
|
|
486
|
+
? value.entrySeq()
|
|
487
|
+
: value.toIndexedSeq()
|
|
488
|
+
: isRecord(value)
|
|
489
|
+
? value.toSeq().entrySeq()
|
|
490
|
+
: indexedSeqFromValue(value);
|
|
418
491
|
}
|
|
419
492
|
|
|
420
493
|
if ( Seq ) IndexedSeq.__proto__ = Seq;
|
|
@@ -653,8 +726,8 @@ function seqFromValue(value) {
|
|
|
653
726
|
return isEntriesIterable(value)
|
|
654
727
|
? seq.fromEntrySeq()
|
|
655
728
|
: isKeysIterable(value)
|
|
656
|
-
|
|
657
|
-
|
|
729
|
+
? seq.toSetSeq()
|
|
730
|
+
: seq;
|
|
658
731
|
}
|
|
659
732
|
if (typeof value === 'object') {
|
|
660
733
|
return new ObjectSeq(value);
|
|
@@ -668,26 +741,42 @@ function maybeIndexedSeqFromValue(value) {
|
|
|
668
741
|
return isArrayLike(value)
|
|
669
742
|
? new ArraySeq(value)
|
|
670
743
|
: hasIterator(value)
|
|
671
|
-
|
|
672
|
-
|
|
744
|
+
? new CollectionSeq(value)
|
|
745
|
+
: undefined;
|
|
673
746
|
}
|
|
674
747
|
|
|
675
748
|
var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
|
|
676
|
-
|
|
749
|
+
/**
|
|
750
|
+
* True if `maybeMap` is a Map.
|
|
751
|
+
*
|
|
752
|
+
* Also true for OrderedMaps.
|
|
753
|
+
*/
|
|
677
754
|
function isMap(maybeMap) {
|
|
678
|
-
|
|
755
|
+
return Boolean(maybeMap &&
|
|
756
|
+
// @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
|
|
757
|
+
maybeMap[IS_MAP_SYMBOL]);
|
|
679
758
|
}
|
|
680
759
|
|
|
760
|
+
/**
|
|
761
|
+
* True if `maybeOrderedMap` is an OrderedMap.
|
|
762
|
+
*/
|
|
681
763
|
function isOrderedMap(maybeOrderedMap) {
|
|
682
|
-
|
|
764
|
+
return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
|
|
683
765
|
}
|
|
684
766
|
|
|
767
|
+
/**
|
|
768
|
+
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
|
|
769
|
+
* and `hashCode()` methods.
|
|
770
|
+
*
|
|
771
|
+
* Any two instances of *value objects* can be compared for value equality with
|
|
772
|
+
* `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
|
|
773
|
+
*/
|
|
685
774
|
function isValueObject(maybeValue) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
775
|
+
return Boolean(maybeValue &&
|
|
776
|
+
// @ts-expect-error: maybeValue is typed as `{}`
|
|
777
|
+
typeof maybeValue.equals === 'function' &&
|
|
778
|
+
// @ts-expect-error: maybeValue is typed as `{}`
|
|
779
|
+
typeof maybeValue.hashCode === 'function');
|
|
691
780
|
}
|
|
692
781
|
|
|
693
782
|
/**
|
|
@@ -745,30 +834,26 @@ function isValueObject(maybeValue) {
|
|
|
745
834
|
* and `hashCode()`.
|
|
746
835
|
*/
|
|
747
836
|
function is(valueA, valueB) {
|
|
748
|
-
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
749
|
-
return true;
|
|
750
|
-
}
|
|
751
|
-
if (!valueA || !valueB) {
|
|
752
|
-
return false;
|
|
753
|
-
}
|
|
754
|
-
if (
|
|
755
|
-
typeof valueA.valueOf === 'function' &&
|
|
756
|
-
typeof valueB.valueOf === 'function'
|
|
757
|
-
) {
|
|
758
|
-
valueA = valueA.valueOf();
|
|
759
|
-
valueB = valueB.valueOf();
|
|
760
837
|
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
761
|
-
|
|
838
|
+
return true;
|
|
762
839
|
}
|
|
763
840
|
if (!valueA || !valueB) {
|
|
764
|
-
|
|
841
|
+
return false;
|
|
765
842
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
843
|
+
if (typeof valueA.valueOf === 'function' &&
|
|
844
|
+
typeof valueB.valueOf === 'function') {
|
|
845
|
+
valueA = valueA.valueOf();
|
|
846
|
+
valueB = valueB.valueOf();
|
|
847
|
+
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
if (!valueA || !valueB) {
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return !!(isValueObject(valueA) &&
|
|
855
|
+
isValueObject(valueB) &&
|
|
856
|
+
valueA.equals(valueB));
|
|
772
857
|
}
|
|
773
858
|
|
|
774
859
|
var imul =
|
|
@@ -794,6 +879,7 @@ function smi(i32) {
|
|
|
794
879
|
var defaultValueOf = Object.prototype.valueOf;
|
|
795
880
|
|
|
796
881
|
function hash(o) {
|
|
882
|
+
// eslint-disable-next-line eqeqeq
|
|
797
883
|
if (o == null) {
|
|
798
884
|
return hashNullish(o);
|
|
799
885
|
}
|
|
@@ -805,6 +891,7 @@ function hash(o) {
|
|
|
805
891
|
|
|
806
892
|
var v = valueOf(o);
|
|
807
893
|
|
|
894
|
+
// eslint-disable-next-line eqeqeq
|
|
808
895
|
if (v == null) {
|
|
809
896
|
return hashNullish(v);
|
|
810
897
|
}
|
|
@@ -971,6 +1058,7 @@ var canDefineProperty = (function () {
|
|
|
971
1058
|
try {
|
|
972
1059
|
Object.defineProperty({}, '@', {});
|
|
973
1060
|
return true;
|
|
1061
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
974
1062
|
} catch (e) {
|
|
975
1063
|
return false;
|
|
976
1064
|
}
|
|
@@ -1099,6 +1187,7 @@ var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq) {
|
|
|
1099
1187
|
var this$1$1 = this;
|
|
1100
1188
|
|
|
1101
1189
|
var i = 0;
|
|
1190
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
1102
1191
|
reverse && ensureSize(this);
|
|
1103
1192
|
return this._iter.__iterate(
|
|
1104
1193
|
function (v) { return fn(v, reverse ? this$1$1.size - ++i : i++, this$1$1); },
|
|
@@ -1111,6 +1200,7 @@ var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq) {
|
|
|
1111
1200
|
|
|
1112
1201
|
var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
|
1113
1202
|
var i = 0;
|
|
1203
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
1114
1204
|
reverse && ensureSize(this);
|
|
1115
1205
|
return new Iterator(function () {
|
|
1116
1206
|
var step = iterator.next();
|
|
@@ -1326,6 +1416,7 @@ function reverseFactory(collection, useKeys) {
|
|
|
1326
1416
|
var this$1$1 = this;
|
|
1327
1417
|
|
|
1328
1418
|
var i = 0;
|
|
1419
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
1329
1420
|
reverse && ensureSize(collection);
|
|
1330
1421
|
return collection.__iterate(
|
|
1331
1422
|
function (v, k) { return fn(v, useKeys ? k : reverse ? this$1$1.size - ++i : i++, this$1$1); },
|
|
@@ -1334,6 +1425,7 @@ function reverseFactory(collection, useKeys) {
|
|
|
1334
1425
|
};
|
|
1335
1426
|
reversedSequence.__iterator = function (type, reverse) {
|
|
1336
1427
|
var i = 0;
|
|
1428
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
1337
1429
|
reverse && ensureSize(collection);
|
|
1338
1430
|
var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
|
|
1339
1431
|
return new Iterator(function () {
|
|
@@ -1620,6 +1712,7 @@ function skipWhileFactory(collection, predicate, context, useKeys) {
|
|
|
1620
1712
|
var entry = step.value;
|
|
1621
1713
|
k = entry[0];
|
|
1622
1714
|
v = entry[1];
|
|
1715
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
1623
1716
|
skipping && (skipping = predicate.call(context, v, k, this$1$1));
|
|
1624
1717
|
} while (skipping);
|
|
1625
1718
|
return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
|
|
@@ -1628,6 +1721,108 @@ function skipWhileFactory(collection, predicate, context, useKeys) {
|
|
|
1628
1721
|
return skipSequence;
|
|
1629
1722
|
}
|
|
1630
1723
|
|
|
1724
|
+
var ConcatSeq = /*@__PURE__*/(function (Seq) {
|
|
1725
|
+
function ConcatSeq(iterables) {
|
|
1726
|
+
this._wrappedIterables = iterables.flatMap(function (iterable) {
|
|
1727
|
+
if (iterable._wrappedIterables) {
|
|
1728
|
+
return iterable._wrappedIterables;
|
|
1729
|
+
}
|
|
1730
|
+
return [iterable];
|
|
1731
|
+
});
|
|
1732
|
+
this.size = this._wrappedIterables.reduce(function (sum, iterable) {
|
|
1733
|
+
if (sum !== undefined) {
|
|
1734
|
+
var size = iterable.size;
|
|
1735
|
+
if (size !== undefined) {
|
|
1736
|
+
return sum + size;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}, 0);
|
|
1740
|
+
this[IS_KEYED_SYMBOL] = this._wrappedIterables[0][IS_KEYED_SYMBOL];
|
|
1741
|
+
this[IS_INDEXED_SYMBOL] = this._wrappedIterables[0][IS_INDEXED_SYMBOL];
|
|
1742
|
+
this[IS_ORDERED_SYMBOL] = this._wrappedIterables[0][IS_ORDERED_SYMBOL];
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
if ( Seq ) ConcatSeq.__proto__ = Seq;
|
|
1746
|
+
ConcatSeq.prototype = Object.create( Seq && Seq.prototype );
|
|
1747
|
+
ConcatSeq.prototype.constructor = ConcatSeq;
|
|
1748
|
+
|
|
1749
|
+
ConcatSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
|
|
1750
|
+
if (this._wrappedIterables.length === 0) {
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
if (reverse) {
|
|
1755
|
+
return this.cacheResult().__iterate(fn, reverse);
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
var iterableIndex = 0;
|
|
1759
|
+
var useKeys = isKeyed(this);
|
|
1760
|
+
var iteratorType = useKeys ? ITERATE_ENTRIES : ITERATE_VALUES;
|
|
1761
|
+
var currentIterator = this._wrappedIterables[iterableIndex].__iterator(
|
|
1762
|
+
iteratorType,
|
|
1763
|
+
reverse
|
|
1764
|
+
);
|
|
1765
|
+
|
|
1766
|
+
var keepGoing = true;
|
|
1767
|
+
var index = 0;
|
|
1768
|
+
while (keepGoing) {
|
|
1769
|
+
var next = currentIterator.next();
|
|
1770
|
+
while (next.done) {
|
|
1771
|
+
iterableIndex++;
|
|
1772
|
+
if (iterableIndex === this._wrappedIterables.length) {
|
|
1773
|
+
return index;
|
|
1774
|
+
}
|
|
1775
|
+
currentIterator = this._wrappedIterables[iterableIndex].__iterator(
|
|
1776
|
+
iteratorType,
|
|
1777
|
+
reverse
|
|
1778
|
+
);
|
|
1779
|
+
next = currentIterator.next();
|
|
1780
|
+
}
|
|
1781
|
+
var fnResult = useKeys
|
|
1782
|
+
? fn(next.value[1], next.value[0], this)
|
|
1783
|
+
: fn(next.value, index, this);
|
|
1784
|
+
keepGoing = fnResult !== false;
|
|
1785
|
+
index++;
|
|
1786
|
+
}
|
|
1787
|
+
return index;
|
|
1788
|
+
};
|
|
1789
|
+
|
|
1790
|
+
ConcatSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
|
|
1791
|
+
var this$1$1 = this;
|
|
1792
|
+
|
|
1793
|
+
if (this._wrappedIterables.length === 0) {
|
|
1794
|
+
return new Iterator(iteratorDone);
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
if (reverse) {
|
|
1798
|
+
return this.cacheResult().__iterator(type, reverse);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
var iterableIndex = 0;
|
|
1802
|
+
var currentIterator = this._wrappedIterables[iterableIndex].__iterator(
|
|
1803
|
+
type,
|
|
1804
|
+
reverse
|
|
1805
|
+
);
|
|
1806
|
+
return new Iterator(function () {
|
|
1807
|
+
var next = currentIterator.next();
|
|
1808
|
+
while (next.done) {
|
|
1809
|
+
iterableIndex++;
|
|
1810
|
+
if (iterableIndex === this$1$1._wrappedIterables.length) {
|
|
1811
|
+
return next;
|
|
1812
|
+
}
|
|
1813
|
+
currentIterator = this$1$1._wrappedIterables[iterableIndex].__iterator(
|
|
1814
|
+
type,
|
|
1815
|
+
reverse
|
|
1816
|
+
);
|
|
1817
|
+
next = currentIterator.next();
|
|
1818
|
+
}
|
|
1819
|
+
return next;
|
|
1820
|
+
});
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
return ConcatSeq;
|
|
1824
|
+
}(Seq));
|
|
1825
|
+
|
|
1631
1826
|
function concatFactory(collection, values) {
|
|
1632
1827
|
var isKeyedCollection = isKeyed(collection);
|
|
1633
1828
|
var iters = [collection]
|
|
@@ -1659,22 +1854,7 @@ function concatFactory(collection, values) {
|
|
|
1659
1854
|
}
|
|
1660
1855
|
}
|
|
1661
1856
|
|
|
1662
|
-
|
|
1663
|
-
if (isKeyedCollection) {
|
|
1664
|
-
concatSeq = concatSeq.toKeyedSeq();
|
|
1665
|
-
} else if (!isIndexed(collection)) {
|
|
1666
|
-
concatSeq = concatSeq.toSetSeq();
|
|
1667
|
-
}
|
|
1668
|
-
concatSeq = concatSeq.flatten(true);
|
|
1669
|
-
concatSeq.size = iters.reduce(function (sum, seq) {
|
|
1670
|
-
if (sum !== undefined) {
|
|
1671
|
-
var size = seq.size;
|
|
1672
|
-
if (size !== undefined) {
|
|
1673
|
-
return sum + size;
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
}, 0);
|
|
1677
|
-
return concatSeq;
|
|
1857
|
+
return new ConcatSeq(iters);
|
|
1678
1858
|
}
|
|
1679
1859
|
|
|
1680
1860
|
function flattenFactory(collection, depth, useKeys) {
|
|
@@ -1798,8 +1978,8 @@ function sortFactory(collection, comparator, mapper) {
|
|
|
1798
1978
|
return isKeyedCollection
|
|
1799
1979
|
? KeyedSeq(entries)
|
|
1800
1980
|
: isIndexed(collection)
|
|
1801
|
-
|
|
1802
|
-
|
|
1981
|
+
? IndexedSeq(entries)
|
|
1982
|
+
: SetSeq(entries);
|
|
1803
1983
|
}
|
|
1804
1984
|
|
|
1805
1985
|
function maxFactory(collection, comparator, mapper) {
|
|
@@ -1866,7 +2046,9 @@ function zipWithFactory(keyIter, zipper, iters, zipAll) {
|
|
|
1866
2046
|
var steps;
|
|
1867
2047
|
if (!isDone) {
|
|
1868
2048
|
steps = iterators.map(function (i) { return i.next(); });
|
|
1869
|
-
isDone = zipAll
|
|
2049
|
+
isDone = zipAll
|
|
2050
|
+
? steps.every(function (s) { return s.done; })
|
|
2051
|
+
: steps.some(function (s) { return s.done; });
|
|
1870
2052
|
}
|
|
1871
2053
|
if (isDone) {
|
|
1872
2054
|
return iteratorDone();
|
|
@@ -1900,8 +2082,8 @@ function collectionClass(collection) {
|
|
|
1900
2082
|
return isKeyed(collection)
|
|
1901
2083
|
? KeyedCollection
|
|
1902
2084
|
: isIndexed(collection)
|
|
1903
|
-
|
|
1904
|
-
|
|
2085
|
+
? IndexedCollection
|
|
2086
|
+
: SetCollection;
|
|
1905
2087
|
}
|
|
1906
2088
|
|
|
1907
2089
|
function makeSequence(collection) {
|
|
@@ -1909,8 +2091,8 @@ function makeSequence(collection) {
|
|
|
1909
2091
|
(isKeyed(collection)
|
|
1910
2092
|
? KeyedSeq
|
|
1911
2093
|
: isIndexed(collection)
|
|
1912
|
-
|
|
1913
|
-
|
|
2094
|
+
? IndexedSeq
|
|
2095
|
+
: SetSeq
|
|
1914
2096
|
).prototype
|
|
1915
2097
|
);
|
|
1916
2098
|
}
|
|
@@ -1942,63 +2124,55 @@ function defaultComparator(a, b) {
|
|
|
1942
2124
|
|
|
1943
2125
|
// http://jsperf.com/copy-array-inline
|
|
1944
2126
|
function arrCopy(arr, offset) {
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
2127
|
+
offset = offset || 0;
|
|
2128
|
+
var len = Math.max(0, arr.length - offset);
|
|
2129
|
+
var newArr = new Array(len);
|
|
2130
|
+
for (var ii = 0; ii < len; ii++) {
|
|
2131
|
+
// @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
|
|
2132
|
+
newArr[ii] = arr[ii + offset];
|
|
2133
|
+
}
|
|
2134
|
+
return newArr;
|
|
1952
2135
|
}
|
|
1953
2136
|
|
|
1954
2137
|
function invariant(condition, error) {
|
|
1955
|
-
|
|
2138
|
+
if (!condition)
|
|
2139
|
+
{ throw new Error(error); }
|
|
1956
2140
|
}
|
|
1957
2141
|
|
|
1958
2142
|
function assertNotInfinite(size) {
|
|
1959
|
-
|
|
1960
|
-
size !== Infinity,
|
|
1961
|
-
'Cannot perform this action with an infinite size.'
|
|
1962
|
-
);
|
|
2143
|
+
invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
|
|
1963
2144
|
}
|
|
1964
2145
|
|
|
1965
2146
|
function coerceKeyPath(keyPath) {
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
|
|
1974
|
-
);
|
|
2147
|
+
if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
|
|
2148
|
+
return keyPath;
|
|
2149
|
+
}
|
|
2150
|
+
if (isOrdered(keyPath)) {
|
|
2151
|
+
return keyPath.toArray();
|
|
2152
|
+
}
|
|
2153
|
+
throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
|
|
1975
2154
|
}
|
|
1976
2155
|
|
|
1977
2156
|
var toString = Object.prototype.toString;
|
|
1978
|
-
|
|
1979
2157
|
function isPlainObject(value) {
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
parentProto = nextProto;
|
|
1999
|
-
nextProto = Object.getPrototypeOf(parentProto);
|
|
2000
|
-
}
|
|
2001
|
-
return parentProto === proto;
|
|
2158
|
+
// The base prototype's toString deals with Argument objects and native namespaces like Math
|
|
2159
|
+
if (!value ||
|
|
2160
|
+
typeof value !== 'object' ||
|
|
2161
|
+
toString.call(value) !== '[object Object]') {
|
|
2162
|
+
return false;
|
|
2163
|
+
}
|
|
2164
|
+
var proto = Object.getPrototypeOf(value);
|
|
2165
|
+
if (proto === null) {
|
|
2166
|
+
return true;
|
|
2167
|
+
}
|
|
2168
|
+
// Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
|
|
2169
|
+
var parentProto = proto;
|
|
2170
|
+
var nextProto = Object.getPrototypeOf(proto);
|
|
2171
|
+
while (nextProto !== null) {
|
|
2172
|
+
parentProto = nextProto;
|
|
2173
|
+
nextProto = Object.getPrototypeOf(parentProto);
|
|
2174
|
+
}
|
|
2175
|
+
return parentProto === proto;
|
|
2002
2176
|
}
|
|
2003
2177
|
|
|
2004
2178
|
/**
|
|
@@ -2006,169 +2180,206 @@ function isPlainObject(value) {
|
|
|
2006
2180
|
* provided by Immutable.js or a plain Array or Object.
|
|
2007
2181
|
*/
|
|
2008
2182
|
function isDataStructure(value) {
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
(isImmutable(value) || Array.isArray(value) || isPlainObject(value))
|
|
2012
|
-
);
|
|
2183
|
+
return (typeof value === 'object' &&
|
|
2184
|
+
(isImmutable(value) || Array.isArray(value) || isPlainObject(value)));
|
|
2013
2185
|
}
|
|
2014
2186
|
|
|
2015
2187
|
/**
|
|
2016
2188
|
* Converts a value to a string, adding quotes if a string was provided.
|
|
2017
2189
|
*/
|
|
2018
2190
|
function quoteString(value) {
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2191
|
+
try {
|
|
2192
|
+
return typeof value === 'string' ? JSON.stringify(value) : String(value);
|
|
2193
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2194
|
+
}
|
|
2195
|
+
catch (_ignoreError) {
|
|
2196
|
+
return JSON.stringify(value);
|
|
2197
|
+
}
|
|
2024
2198
|
}
|
|
2025
2199
|
|
|
2200
|
+
/**
|
|
2201
|
+
* Returns true if the key is defined in the provided collection.
|
|
2202
|
+
*
|
|
2203
|
+
* A functional alternative to `collection.has(key)` which will also work with
|
|
2204
|
+
* plain Objects and Arrays as an alternative for
|
|
2205
|
+
* `collection.hasOwnProperty(key)`.
|
|
2206
|
+
*
|
|
2207
|
+
* <!-- runkit:activate -->
|
|
2208
|
+
* ```js
|
|
2209
|
+
* import { has } from 'immutable';
|
|
2210
|
+
*
|
|
2211
|
+
* has([ 'dog', 'frog', 'cat' ], 2) // true
|
|
2212
|
+
* has([ 'dog', 'frog', 'cat' ], 5) // false
|
|
2213
|
+
* has({ x: 123, y: 456 }, 'x') // true
|
|
2214
|
+
* has({ x: 123, y: 456 }, 'z') // false
|
|
2215
|
+
* ```
|
|
2216
|
+
*/
|
|
2026
2217
|
function has(collection, key) {
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2218
|
+
return isImmutable(collection)
|
|
2219
|
+
? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
|
|
2220
|
+
collection.has(key)
|
|
2221
|
+
: // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
|
|
2222
|
+
isDataStructure(collection) && hasOwnProperty.call(collection, key);
|
|
2030
2223
|
}
|
|
2031
2224
|
|
|
2032
2225
|
function get(collection, key, notSetValue) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2226
|
+
return isImmutable(collection)
|
|
2227
|
+
? collection.get(key, notSetValue)
|
|
2228
|
+
: !has(collection, key)
|
|
2229
|
+
? notSetValue
|
|
2230
|
+
: // @ts-expect-error weird "get" here,
|
|
2231
|
+
typeof collection.get === 'function'
|
|
2232
|
+
? // @ts-expect-error weird "get" here,
|
|
2233
|
+
collection.get(key)
|
|
2234
|
+
: // @ts-expect-error key is unknown here,
|
|
2235
|
+
collection[key];
|
|
2040
2236
|
}
|
|
2041
2237
|
|
|
2042
2238
|
function shallowCopy(from) {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
}
|
|
2046
|
-
var to = {};
|
|
2047
|
-
for (var key in from) {
|
|
2048
|
-
if (hasOwnProperty.call(from, key)) {
|
|
2049
|
-
to[key] = from[key];
|
|
2239
|
+
if (Array.isArray(from)) {
|
|
2240
|
+
return arrCopy(from);
|
|
2050
2241
|
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2242
|
+
var to = {};
|
|
2243
|
+
for (var key in from) {
|
|
2244
|
+
if (hasOwnProperty.call(from, key)) {
|
|
2245
|
+
to[key] = from[key];
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
return to;
|
|
2053
2249
|
}
|
|
2054
2250
|
|
|
2055
2251
|
function remove(collection, key) {
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
'Cannot update non-data-structure value: ' + collection
|
|
2059
|
-
);
|
|
2060
|
-
}
|
|
2061
|
-
if (isImmutable(collection)) {
|
|
2062
|
-
if (!collection.remove) {
|
|
2063
|
-
throw new TypeError(
|
|
2064
|
-
'Cannot update immutable value without .remove() method: ' + collection
|
|
2065
|
-
);
|
|
2252
|
+
if (!isDataStructure(collection)) {
|
|
2253
|
+
throw new TypeError('Cannot update non-data-structure value: ' + collection);
|
|
2066
2254
|
}
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2255
|
+
if (isImmutable(collection)) {
|
|
2256
|
+
// @ts-expect-error weird "remove" here,
|
|
2257
|
+
if (!collection.remove) {
|
|
2258
|
+
throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
|
|
2259
|
+
}
|
|
2260
|
+
// @ts-expect-error weird "remove" here,
|
|
2261
|
+
return collection.remove(key);
|
|
2262
|
+
}
|
|
2263
|
+
if (!hasOwnProperty.call(collection, key)) {
|
|
2264
|
+
return collection;
|
|
2265
|
+
}
|
|
2266
|
+
var collectionCopy = shallowCopy(collection);
|
|
2267
|
+
if (Array.isArray(collectionCopy)) {
|
|
2268
|
+
// @ts-expect-error assert that key is a number here
|
|
2269
|
+
collectionCopy.splice(key, 1);
|
|
2270
|
+
}
|
|
2271
|
+
else {
|
|
2272
|
+
delete collectionCopy[key];
|
|
2273
|
+
}
|
|
2274
|
+
return collectionCopy;
|
|
2079
2275
|
}
|
|
2080
2276
|
|
|
2081
2277
|
function set(collection, key, value) {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
'Cannot update non-data-structure value: ' + collection
|
|
2085
|
-
);
|
|
2086
|
-
}
|
|
2087
|
-
if (isImmutable(collection)) {
|
|
2088
|
-
if (!collection.set) {
|
|
2089
|
-
throw new TypeError(
|
|
2090
|
-
'Cannot update immutable value without .set() method: ' + collection
|
|
2091
|
-
);
|
|
2278
|
+
if (!isDataStructure(collection)) {
|
|
2279
|
+
throw new TypeError('Cannot update non-data-structure value: ' + collection);
|
|
2092
2280
|
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2281
|
+
if (isImmutable(collection)) {
|
|
2282
|
+
// @ts-expect-error weird "set" here,
|
|
2283
|
+
if (!collection.set) {
|
|
2284
|
+
throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
|
|
2285
|
+
}
|
|
2286
|
+
// @ts-expect-error weird "set" here,
|
|
2287
|
+
return collection.set(key, value);
|
|
2288
|
+
}
|
|
2289
|
+
// @ts-expect-error mix of key and string here. Probably need a more fine type here
|
|
2290
|
+
if (hasOwnProperty.call(collection, key) && value === collection[key]) {
|
|
2291
|
+
return collection;
|
|
2292
|
+
}
|
|
2293
|
+
var collectionCopy = shallowCopy(collection);
|
|
2294
|
+
// @ts-expect-error mix of key and string here. Probably need a more fine type here
|
|
2295
|
+
collectionCopy[key] = value;
|
|
2296
|
+
return collectionCopy;
|
|
2101
2297
|
}
|
|
2102
2298
|
|
|
2103
2299
|
function updateIn$1(collection, keyPath, notSetValue, updater) {
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
collection,
|
|
2111
|
-
|
|
2112
|
-
0,
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
|
|
2145
|
-
nextExisting,
|
|
2146
|
-
keyPath,
|
|
2147
|
-
i + 1,
|
|
2148
|
-
notSetValue,
|
|
2149
|
-
updater
|
|
2150
|
-
);
|
|
2151
|
-
return nextUpdated === nextExisting
|
|
2152
|
-
? existing
|
|
2153
|
-
: nextUpdated === NOT_SET
|
|
2154
|
-
? remove(existing, key)
|
|
2155
|
-
: set(
|
|
2156
|
-
wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
|
|
2157
|
-
key,
|
|
2158
|
-
nextUpdated
|
|
2159
|
-
);
|
|
2300
|
+
if (!updater) {
|
|
2301
|
+
// handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
|
|
2302
|
+
// @ts-expect-error updater is a function here
|
|
2303
|
+
updater = notSetValue;
|
|
2304
|
+
notSetValue = undefined;
|
|
2305
|
+
}
|
|
2306
|
+
var updatedValue = updateInDeeply(isImmutable(collection),
|
|
2307
|
+
// @ts-expect-error type issues with Record and mixed types
|
|
2308
|
+
collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
|
|
2309
|
+
// @ts-expect-error mixed return type
|
|
2310
|
+
return updatedValue === NOT_SET ? notSetValue : updatedValue;
|
|
2311
|
+
}
|
|
2312
|
+
function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
|
|
2313
|
+
var wasNotSet = existing === NOT_SET;
|
|
2314
|
+
if (i === keyPath.length) {
|
|
2315
|
+
var existingValue = wasNotSet ? notSetValue : existing;
|
|
2316
|
+
// @ts-expect-error mixed type with optional value
|
|
2317
|
+
var newValue = updater(existingValue);
|
|
2318
|
+
// @ts-expect-error mixed type
|
|
2319
|
+
return newValue === existingValue ? existing : newValue;
|
|
2320
|
+
}
|
|
2321
|
+
if (!wasNotSet && !isDataStructure(existing)) {
|
|
2322
|
+
throw new TypeError('Cannot update within non-data-structure value in path [' +
|
|
2323
|
+
Array.from(keyPath).slice(0, i).map(quoteString) +
|
|
2324
|
+
']: ' +
|
|
2325
|
+
existing);
|
|
2326
|
+
}
|
|
2327
|
+
var key = keyPath[i];
|
|
2328
|
+
if (typeof key === 'undefined') {
|
|
2329
|
+
throw new TypeError('Index can not be undefined in updateIn(). This should not happen');
|
|
2330
|
+
}
|
|
2331
|
+
var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
|
|
2332
|
+
var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
|
|
2333
|
+
// @ts-expect-error mixed type
|
|
2334
|
+
nextExisting, keyPath, i + 1, notSetValue, updater);
|
|
2335
|
+
return nextUpdated === nextExisting
|
|
2336
|
+
? existing
|
|
2337
|
+
: nextUpdated === NOT_SET
|
|
2338
|
+
? remove(existing, key)
|
|
2339
|
+
: set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
|
|
2160
2340
|
}
|
|
2161
2341
|
|
|
2342
|
+
/**
|
|
2343
|
+
* Returns a copy of the collection with the value at the key path set to the
|
|
2344
|
+
* provided value.
|
|
2345
|
+
*
|
|
2346
|
+
* A functional alternative to `collection.setIn(keypath)` which will also
|
|
2347
|
+
* work with plain Objects and Arrays.
|
|
2348
|
+
*
|
|
2349
|
+
* <!-- runkit:activate -->
|
|
2350
|
+
* ```js
|
|
2351
|
+
* import { setIn } from 'immutable';
|
|
2352
|
+
*
|
|
2353
|
+
* const original = { x: { y: { z: 123 }}}
|
|
2354
|
+
* setIn(original, ['x', 'y', 'z'], 456) // { x: { y: { z: 456 }}}
|
|
2355
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
2356
|
+
* ```
|
|
2357
|
+
*/
|
|
2162
2358
|
function setIn$1(collection, keyPath, value) {
|
|
2163
|
-
|
|
2359
|
+
return updateIn$1(collection, keyPath, NOT_SET, function () { return value; });
|
|
2164
2360
|
}
|
|
2165
2361
|
|
|
2166
2362
|
function setIn(keyPath, v) {
|
|
2167
2363
|
return setIn$1(this, keyPath, v);
|
|
2168
2364
|
}
|
|
2169
2365
|
|
|
2366
|
+
/**
|
|
2367
|
+
* Returns a copy of the collection with the value at the key path removed.
|
|
2368
|
+
*
|
|
2369
|
+
* A functional alternative to `collection.removeIn(keypath)` which will also
|
|
2370
|
+
* work with plain Objects and Arrays.
|
|
2371
|
+
*
|
|
2372
|
+
* <!-- runkit:activate -->
|
|
2373
|
+
* ```js
|
|
2374
|
+
* import { removeIn } from 'immutable';
|
|
2375
|
+
*
|
|
2376
|
+
* const original = { x: { y: { z: 123 }}}
|
|
2377
|
+
* removeIn(original, ['x', 'y', 'z']) // { x: { y: {}}}
|
|
2378
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
2379
|
+
* ```
|
|
2380
|
+
*/
|
|
2170
2381
|
function removeIn(collection, keyPath) {
|
|
2171
|
-
|
|
2382
|
+
return updateIn$1(collection, keyPath, function () { return NOT_SET; });
|
|
2172
2383
|
}
|
|
2173
2384
|
|
|
2174
2385
|
function deleteIn(keyPath) {
|
|
@@ -2176,7 +2387,9 @@ function deleteIn(keyPath) {
|
|
|
2176
2387
|
}
|
|
2177
2388
|
|
|
2178
2389
|
function update$1(collection, key, notSetValue, updater) {
|
|
2179
|
-
|
|
2390
|
+
return updateIn$1(
|
|
2391
|
+
// @ts-expect-error Index signature for type string is missing in type V[]
|
|
2392
|
+
collection, [key], notSetValue, updater);
|
|
2180
2393
|
}
|
|
2181
2394
|
|
|
2182
2395
|
function update(key, notSetValue, updater) {
|
|
@@ -2281,8 +2494,8 @@ function mergeWithSources(collection, sources, merger) {
|
|
|
2281
2494
|
return typeof merger === 'function' && collection.mergeWith
|
|
2282
2495
|
? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
|
|
2283
2496
|
: collection.merge
|
|
2284
|
-
|
|
2285
|
-
|
|
2497
|
+
? collection.merge.apply(collection, sources)
|
|
2498
|
+
: collection.concat.apply(collection, sources);
|
|
2286
2499
|
}
|
|
2287
2500
|
var isArray = Array.isArray(collection);
|
|
2288
2501
|
var merged = collection;
|
|
@@ -2320,8 +2533,8 @@ function deepMergerWith(merger) {
|
|
|
2320
2533
|
areMergeable(oldValue, newValue)
|
|
2321
2534
|
? mergeWithSources(oldValue, [newValue], deepMerger)
|
|
2322
2535
|
: merger
|
|
2323
|
-
|
|
2324
|
-
|
|
2536
|
+
? merger(oldValue, newValue, key)
|
|
2537
|
+
: newValue;
|
|
2325
2538
|
}
|
|
2326
2539
|
return deepMerger;
|
|
2327
2540
|
}
|
|
@@ -2395,12 +2608,12 @@ var Map = /*@__PURE__*/(function (KeyedCollection) {
|
|
|
2395
2608
|
return value === undefined || value === null
|
|
2396
2609
|
? emptyMap()
|
|
2397
2610
|
: isMap(value) && !isOrdered(value)
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2611
|
+
? value
|
|
2612
|
+
: emptyMap().withMutations(function (map) {
|
|
2613
|
+
var iter = KeyedCollection(value);
|
|
2614
|
+
assertNotInfinite(iter.size);
|
|
2615
|
+
iter.forEach(function (v, k) { return map.set(k, v); });
|
|
2616
|
+
});
|
|
2404
2617
|
}
|
|
2405
2618
|
|
|
2406
2619
|
if ( KeyedCollection ) Map.__proto__ = KeyedCollection;
|
|
@@ -2487,6 +2700,7 @@ var Map = /*@__PURE__*/(function (KeyedCollection) {
|
|
|
2487
2700
|
var this$1$1 = this;
|
|
2488
2701
|
|
|
2489
2702
|
var iterations = 0;
|
|
2703
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
2490
2704
|
this._root &&
|
|
2491
2705
|
this._root.iterate(function (entry) {
|
|
2492
2706
|
iterations++;
|
|
@@ -2575,6 +2789,7 @@ ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, v
|
|
|
2575
2789
|
}
|
|
2576
2790
|
|
|
2577
2791
|
SetRef(didAlter);
|
|
2792
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
2578
2793
|
(removed || !exists) && SetRef(didChangeSize);
|
|
2579
2794
|
|
|
2580
2795
|
if (removed && entries.length === 1) {
|
|
@@ -2590,6 +2805,7 @@ ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, v
|
|
|
2590
2805
|
|
|
2591
2806
|
if (exists) {
|
|
2592
2807
|
if (removed) {
|
|
2808
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
2593
2809
|
idx === len - 1
|
|
2594
2810
|
? newEntries.pop()
|
|
2595
2811
|
: (newEntries[idx] = newEntries.pop());
|
|
@@ -2808,6 +3024,7 @@ HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, k
|
|
|
2808
3024
|
}
|
|
2809
3025
|
|
|
2810
3026
|
SetRef(didAlter);
|
|
3027
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
2811
3028
|
(removed || !exists) && SetRef(didChangeSize);
|
|
2812
3029
|
|
|
2813
3030
|
if (removed && len === 2) {
|
|
@@ -2819,6 +3036,7 @@ HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, k
|
|
|
2819
3036
|
|
|
2820
3037
|
if (exists) {
|
|
2821
3038
|
if (removed) {
|
|
3039
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
2822
3040
|
idx === len - 1
|
|
2823
3041
|
? newEntries.pop()
|
|
2824
3042
|
: (newEntries[idx] = newEntries.pop());
|
|
@@ -3161,9 +3379,13 @@ var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
|
|
|
3161
3379
|
var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
|
|
3162
3380
|
|
|
3163
3381
|
var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
|
|
3164
|
-
|
|
3382
|
+
/**
|
|
3383
|
+
* True if `maybeList` is a List.
|
|
3384
|
+
*/
|
|
3165
3385
|
function isList(maybeList) {
|
|
3166
|
-
|
|
3386
|
+
return Boolean(maybeList &&
|
|
3387
|
+
// @ts-expect-error: maybeList is typed as `{}`, need to change in 6.0 to `maybeList && typeof maybeList === 'object' && IS_LIST_SYMBOL in maybeList`
|
|
3388
|
+
maybeList[IS_LIST_SYMBOL]);
|
|
3167
3389
|
}
|
|
3168
3390
|
|
|
3169
3391
|
var List = /*@__PURE__*/(function (IndexedCollection) {
|
|
@@ -3229,10 +3451,10 @@ var List = /*@__PURE__*/(function (IndexedCollection) {
|
|
|
3229
3451
|
return !this.has(index)
|
|
3230
3452
|
? this
|
|
3231
3453
|
: index === 0
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3454
|
+
? this.shift()
|
|
3455
|
+
: index === this.size - 1
|
|
3456
|
+
? this.pop()
|
|
3457
|
+
: this.splice(index, 1);
|
|
3236
3458
|
};
|
|
3237
3459
|
|
|
3238
3460
|
List.prototype.insert = function insert (index, value) {
|
|
@@ -3282,6 +3504,25 @@ var List = /*@__PURE__*/(function (IndexedCollection) {
|
|
|
3282
3504
|
return setListBounds(this, 1);
|
|
3283
3505
|
};
|
|
3284
3506
|
|
|
3507
|
+
List.prototype.shuffle = function shuffle (random) {
|
|
3508
|
+
if ( random === void 0 ) random = Math.random;
|
|
3509
|
+
|
|
3510
|
+
return this.withMutations(function (mutable) {
|
|
3511
|
+
// implementation of the Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
3512
|
+
var current = mutable.size;
|
|
3513
|
+
var destination;
|
|
3514
|
+
var tmp;
|
|
3515
|
+
|
|
3516
|
+
while (current) {
|
|
3517
|
+
destination = Math.floor(random() * current--);
|
|
3518
|
+
|
|
3519
|
+
tmp = mutable.get(destination);
|
|
3520
|
+
mutable.set(destination, mutable.get(current));
|
|
3521
|
+
mutable.set(current, tmp);
|
|
3522
|
+
}
|
|
3523
|
+
});
|
|
3524
|
+
};
|
|
3525
|
+
|
|
3285
3526
|
// @pragma Composition
|
|
3286
3527
|
|
|
3287
3528
|
List.prototype.concat = function concat (/*...collections*/) {
|
|
@@ -3418,7 +3659,10 @@ var VNode = function VNode(array, ownerID) {
|
|
|
3418
3659
|
// TODO: seems like these methods are very similar
|
|
3419
3660
|
|
|
3420
3661
|
VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
|
|
3421
|
-
if (
|
|
3662
|
+
if (
|
|
3663
|
+
(index & ((1 << (level + SHIFT)) - 1)) === 0 ||
|
|
3664
|
+
this.array.length === 0
|
|
3665
|
+
) {
|
|
3422
3666
|
return this;
|
|
3423
3667
|
}
|
|
3424
3668
|
var originIndex = (index >>> level) & MASK;
|
|
@@ -3451,7 +3695,10 @@ VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
|
|
|
3451
3695
|
};
|
|
3452
3696
|
|
|
3453
3697
|
VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
|
|
3454
|
-
if (
|
|
3698
|
+
if (
|
|
3699
|
+
index === (level ? 1 << (level + SHIFT) : SIZE) ||
|
|
3700
|
+
this.array.length === 0
|
|
3701
|
+
) {
|
|
3455
3702
|
return this;
|
|
3456
3703
|
}
|
|
3457
3704
|
var sizeIndex = ((index - 1) >>> level) & MASK;
|
|
@@ -3567,6 +3814,7 @@ function updateList(list, index, value) {
|
|
|
3567
3814
|
|
|
3568
3815
|
if (index >= list.size || index < 0) {
|
|
3569
3816
|
return list.withMutations(function (list) {
|
|
3817
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
3570
3818
|
index < 0
|
|
3571
3819
|
? setListBounds(list, index).set(0, value)
|
|
3572
3820
|
: setListBounds(list, 0, index + 1).set(index, value);
|
|
@@ -3688,8 +3936,8 @@ function setListBounds(list, begin, end) {
|
|
|
3688
3936
|
end === undefined
|
|
3689
3937
|
? oldCapacity
|
|
3690
3938
|
: end < 0
|
|
3691
|
-
|
|
3692
|
-
|
|
3939
|
+
? oldCapacity + end
|
|
3940
|
+
: oldOrigin + end;
|
|
3693
3941
|
if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
|
|
3694
3942
|
return list;
|
|
3695
3943
|
}
|
|
@@ -3737,8 +3985,8 @@ function setListBounds(list, begin, end) {
|
|
|
3737
3985
|
newTailOffset < oldTailOffset
|
|
3738
3986
|
? listNodeFor(list, newCapacity - 1)
|
|
3739
3987
|
: newTailOffset > oldTailOffset
|
|
3740
|
-
|
|
3741
|
-
|
|
3988
|
+
? new VNode([], owner)
|
|
3989
|
+
: oldTail;
|
|
3742
3990
|
|
|
3743
3991
|
// Merge Tail into tree.
|
|
3744
3992
|
if (
|
|
@@ -3827,12 +4075,12 @@ var OrderedMap = /*@__PURE__*/(function (Map) {
|
|
|
3827
4075
|
return value === undefined || value === null
|
|
3828
4076
|
? emptyOrderedMap()
|
|
3829
4077
|
: isOrderedMap(value)
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
4078
|
+
? value
|
|
4079
|
+
: emptyOrderedMap().withMutations(function (map) {
|
|
4080
|
+
var iter = KeyedCollection(value);
|
|
4081
|
+
assertNotInfinite(iter.size);
|
|
4082
|
+
iter.forEach(function (v, k) { return map.set(k, v); });
|
|
4083
|
+
});
|
|
3836
4084
|
}
|
|
3837
4085
|
|
|
3838
4086
|
if ( Map ) OrderedMap.__proto__ = Map;
|
|
@@ -3985,9 +4233,13 @@ function updateOrderedMap(omap, k, v) {
|
|
|
3985
4233
|
}
|
|
3986
4234
|
|
|
3987
4235
|
var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
|
|
3988
|
-
|
|
4236
|
+
/**
|
|
4237
|
+
* True if `maybeStack` is a Stack.
|
|
4238
|
+
*/
|
|
3989
4239
|
function isStack(maybeStack) {
|
|
3990
|
-
|
|
4240
|
+
return Boolean(maybeStack &&
|
|
4241
|
+
// @ts-expect-error: maybeStack is typed as `{}`, need to change in 6.0 to `maybeStack && typeof maybeStack === 'object' && MAYBE_STACK_SYMBOL in maybeStack`
|
|
4242
|
+
maybeStack[IS_STACK_SYMBOL]);
|
|
3991
4243
|
}
|
|
3992
4244
|
|
|
3993
4245
|
var Stack = /*@__PURE__*/(function (IndexedCollection) {
|
|
@@ -3996,8 +4248,8 @@ var Stack = /*@__PURE__*/(function (IndexedCollection) {
|
|
|
3996
4248
|
return value === undefined || value === null
|
|
3997
4249
|
? emptyStack()
|
|
3998
4250
|
: isStack(value)
|
|
3999
|
-
|
|
4000
|
-
|
|
4251
|
+
? value
|
|
4252
|
+
: emptyStack().pushAll(value);
|
|
4001
4253
|
}
|
|
4002
4254
|
|
|
4003
4255
|
if ( IndexedCollection ) Stack.__proto__ = IndexedCollection;
|
|
@@ -4216,92 +4468,108 @@ function emptyStack() {
|
|
|
4216
4468
|
}
|
|
4217
4469
|
|
|
4218
4470
|
var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
|
|
4219
|
-
|
|
4471
|
+
/**
|
|
4472
|
+
* True if `maybeSet` is a Set.
|
|
4473
|
+
*
|
|
4474
|
+
* Also true for OrderedSets.
|
|
4475
|
+
*/
|
|
4220
4476
|
function isSet(maybeSet) {
|
|
4221
|
-
|
|
4477
|
+
return Boolean(maybeSet &&
|
|
4478
|
+
// @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
|
|
4479
|
+
maybeSet[IS_SET_SYMBOL]);
|
|
4222
4480
|
}
|
|
4223
4481
|
|
|
4482
|
+
/**
|
|
4483
|
+
* True if `maybeOrderedSet` is an OrderedSet.
|
|
4484
|
+
*/
|
|
4224
4485
|
function isOrderedSet(maybeOrderedSet) {
|
|
4225
|
-
|
|
4486
|
+
return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
|
|
4226
4487
|
}
|
|
4227
4488
|
|
|
4228
4489
|
function deepEqual(a, b) {
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
if (a.size === 0 && b.size === 0) {
|
|
4247
|
-
return true;
|
|
4248
|
-
}
|
|
4249
|
-
|
|
4250
|
-
var notAssociative = !isAssociative(a);
|
|
4251
|
-
|
|
4252
|
-
if (isOrdered(a)) {
|
|
4253
|
-
var entries = a.entries();
|
|
4254
|
-
return (
|
|
4255
|
-
b.every(function (v, k) {
|
|
4256
|
-
var entry = entries.next().value;
|
|
4257
|
-
return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
|
|
4258
|
-
}) && entries.next().done
|
|
4259
|
-
);
|
|
4260
|
-
}
|
|
4261
|
-
|
|
4262
|
-
var flipped = false;
|
|
4263
|
-
|
|
4264
|
-
if (a.size === undefined) {
|
|
4265
|
-
if (b.size === undefined) {
|
|
4266
|
-
if (typeof a.cacheResult === 'function') {
|
|
4267
|
-
a.cacheResult();
|
|
4268
|
-
}
|
|
4269
|
-
} else {
|
|
4270
|
-
flipped = true;
|
|
4271
|
-
var _ = a;
|
|
4272
|
-
a = b;
|
|
4273
|
-
b = _;
|
|
4490
|
+
if (a === b) {
|
|
4491
|
+
return true;
|
|
4492
|
+
}
|
|
4493
|
+
if (!isCollection(b) ||
|
|
4494
|
+
// @ts-expect-error size should exists on Collection
|
|
4495
|
+
(a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
|
|
4496
|
+
// @ts-expect-error __hash exists on Collection
|
|
4497
|
+
(a.__hash !== undefined &&
|
|
4498
|
+
// @ts-expect-error __hash exists on Collection
|
|
4499
|
+
b.__hash !== undefined &&
|
|
4500
|
+
// @ts-expect-error __hash exists on Collection
|
|
4501
|
+
a.__hash !== b.__hash) ||
|
|
4502
|
+
isKeyed(a) !== isKeyed(b) ||
|
|
4503
|
+
isIndexed(a) !== isIndexed(b) ||
|
|
4504
|
+
// @ts-expect-error Range extends Collection, which implements [Symbol.iterator], so it is valid
|
|
4505
|
+
isOrdered(a) !== isOrdered(b)) {
|
|
4506
|
+
return false;
|
|
4274
4507
|
}
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4508
|
+
// @ts-expect-error size should exists on Collection
|
|
4509
|
+
if (a.size === 0 && b.size === 0) {
|
|
4510
|
+
return true;
|
|
4511
|
+
}
|
|
4512
|
+
var notAssociative = !isAssociative(a);
|
|
4513
|
+
// @ts-expect-error Range extends Collection, which implements [Symbol.iterator], so it is valid
|
|
4514
|
+
if (isOrdered(a)) {
|
|
4515
|
+
var entries = a.entries();
|
|
4516
|
+
// @ts-expect-error need to cast as boolean
|
|
4517
|
+
return (b.every(function (v, k) {
|
|
4518
|
+
var entry = entries.next().value;
|
|
4519
|
+
return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
|
|
4520
|
+
}) && entries.next().done);
|
|
4521
|
+
}
|
|
4522
|
+
var flipped = false;
|
|
4523
|
+
if (a.size === undefined) {
|
|
4524
|
+
// @ts-expect-error size should exists on Collection
|
|
4525
|
+
if (b.size === undefined) {
|
|
4526
|
+
if (typeof a.cacheResult === 'function') {
|
|
4527
|
+
a.cacheResult();
|
|
4528
|
+
}
|
|
4529
|
+
}
|
|
4530
|
+
else {
|
|
4531
|
+
flipped = true;
|
|
4532
|
+
var _ = a;
|
|
4533
|
+
a = b;
|
|
4534
|
+
b = _;
|
|
4535
|
+
}
|
|
4288
4536
|
}
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4537
|
+
var allEqual = true;
|
|
4538
|
+
var bSize =
|
|
4539
|
+
// @ts-expect-error b is Range | Repeat | Collection<unknown, unknown> as it may have been flipped, and __iterate is valid
|
|
4540
|
+
b.__iterate(function (v, k) {
|
|
4541
|
+
if (notAssociative
|
|
4542
|
+
? // @ts-expect-error has exists on Collection
|
|
4543
|
+
!a.has(v)
|
|
4544
|
+
: flipped
|
|
4545
|
+
? // @ts-expect-error type of `get` does not "catch" the version with `notSetValue`
|
|
4546
|
+
!is(v, a.get(k, NOT_SET))
|
|
4547
|
+
: // @ts-expect-error type of `get` does not "catch" the version with `notSetValue`
|
|
4548
|
+
!is(a.get(k, NOT_SET), v)) {
|
|
4549
|
+
allEqual = false;
|
|
4550
|
+
return false;
|
|
4551
|
+
}
|
|
4552
|
+
});
|
|
4553
|
+
return (allEqual &&
|
|
4554
|
+
// @ts-expect-error size should exists on Collection
|
|
4555
|
+
a.size === bSize);
|
|
4292
4556
|
}
|
|
4293
4557
|
|
|
4294
4558
|
/**
|
|
4295
4559
|
* Contributes additional methods to a constructor
|
|
4296
4560
|
*/
|
|
4297
|
-
function mixin(ctor,
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4561
|
+
function mixin(ctor,
|
|
4562
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
4563
|
+
methods) {
|
|
4564
|
+
var keyCopier = function (key) {
|
|
4565
|
+
// @ts-expect-error how to handle symbol ?
|
|
4566
|
+
ctor.prototype[key] = methods[key];
|
|
4567
|
+
};
|
|
4568
|
+
Object.keys(methods).forEach(keyCopier);
|
|
4569
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
4570
|
+
Object.getOwnPropertySymbols &&
|
|
4571
|
+
Object.getOwnPropertySymbols(methods).forEach(keyCopier);
|
|
4572
|
+
return ctor;
|
|
4305
4573
|
}
|
|
4306
4574
|
|
|
4307
4575
|
function toJS(value) {
|
|
@@ -4334,12 +4602,12 @@ var Set = /*@__PURE__*/(function (SetCollection) {
|
|
|
4334
4602
|
return value === undefined || value === null
|
|
4335
4603
|
? emptySet()
|
|
4336
4604
|
: isSet(value) && !isOrdered(value)
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4605
|
+
? value
|
|
4606
|
+
: emptySet().withMutations(function (set) {
|
|
4607
|
+
var iter = SetCollection(value);
|
|
4608
|
+
assertNotInfinite(iter.size);
|
|
4609
|
+
iter.forEach(function (v) { return set.add(v); });
|
|
4610
|
+
});
|
|
4343
4611
|
}
|
|
4344
4612
|
|
|
4345
4613
|
if ( SetCollection ) Set.__proto__ = SetCollection;
|
|
@@ -4553,8 +4821,8 @@ function updateSet(set, newMap) {
|
|
|
4553
4821
|
return newMap === set._map
|
|
4554
4822
|
? set
|
|
4555
4823
|
: newMap.size === 0
|
|
4556
|
-
|
|
4557
|
-
|
|
4824
|
+
? set.__empty()
|
|
4825
|
+
: set.__make(newMap);
|
|
4558
4826
|
}
|
|
4559
4827
|
|
|
4560
4828
|
function makeSet(map, ownerID) {
|
|
@@ -4616,17 +4884,9 @@ var Range = /*@__PURE__*/(function (IndexedSeq) {
|
|
|
4616
4884
|
Range.prototype.constructor = Range;
|
|
4617
4885
|
|
|
4618
4886
|
Range.prototype.toString = function toString () {
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
return (
|
|
4623
|
-
'Range [ ' +
|
|
4624
|
-
this._start +
|
|
4625
|
-
'...' +
|
|
4626
|
-
this._end +
|
|
4627
|
-
(this._step !== 1 ? ' by ' + this._step : '') +
|
|
4628
|
-
' ]'
|
|
4629
|
-
);
|
|
4887
|
+
return this.size === 0
|
|
4888
|
+
? 'Range []'
|
|
4889
|
+
: ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
|
|
4630
4890
|
};
|
|
4631
4891
|
|
|
4632
4892
|
Range.prototype.get = function get (index, notSetValue) {
|
|
@@ -4717,24 +4977,54 @@ var Range = /*@__PURE__*/(function (IndexedSeq) {
|
|
|
4717
4977
|
|
|
4718
4978
|
var EMPTY_RANGE;
|
|
4719
4979
|
|
|
4980
|
+
/**
|
|
4981
|
+
* Returns the value at the provided key path starting at the provided
|
|
4982
|
+
* collection, or notSetValue if the key path is not defined.
|
|
4983
|
+
*
|
|
4984
|
+
* A functional alternative to `collection.getIn(keypath)` which will also
|
|
4985
|
+
* work with plain Objects and Arrays.
|
|
4986
|
+
*
|
|
4987
|
+
* <!-- runkit:activate -->
|
|
4988
|
+
* ```js
|
|
4989
|
+
* import { getIn } from 'immutable';
|
|
4990
|
+
*
|
|
4991
|
+
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
|
|
4992
|
+
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
|
|
4993
|
+
* ```
|
|
4994
|
+
*/
|
|
4720
4995
|
function getIn$1(collection, searchKeyPath, notSetValue) {
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4996
|
+
var keyPath = coerceKeyPath(searchKeyPath);
|
|
4997
|
+
var i = 0;
|
|
4998
|
+
while (i !== keyPath.length) {
|
|
4999
|
+
// @ts-expect-error keyPath[i++] can not be undefined by design
|
|
5000
|
+
collection = get(collection, keyPath[i++], NOT_SET);
|
|
5001
|
+
if (collection === NOT_SET) {
|
|
5002
|
+
return notSetValue;
|
|
5003
|
+
}
|
|
4727
5004
|
}
|
|
4728
|
-
|
|
4729
|
-
return collection;
|
|
5005
|
+
return collection;
|
|
4730
5006
|
}
|
|
4731
5007
|
|
|
4732
5008
|
function getIn(searchKeyPath, notSetValue) {
|
|
4733
5009
|
return getIn$1(this, searchKeyPath, notSetValue);
|
|
4734
5010
|
}
|
|
4735
5011
|
|
|
5012
|
+
/**
|
|
5013
|
+
* Returns true if the key path is defined in the provided collection.
|
|
5014
|
+
*
|
|
5015
|
+
* A functional alternative to `collection.hasIn(keypath)` which will also
|
|
5016
|
+
* work with plain Objects and Arrays.
|
|
5017
|
+
*
|
|
5018
|
+
* <!-- runkit:activate -->
|
|
5019
|
+
* ```js
|
|
5020
|
+
* import { hasIn } from 'immutable';
|
|
5021
|
+
*
|
|
5022
|
+
* hasIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // true
|
|
5023
|
+
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
|
|
5024
|
+
* ```
|
|
5025
|
+
*/
|
|
4736
5026
|
function hasIn$1(collection, keyPath) {
|
|
4737
|
-
|
|
5027
|
+
return getIn$1(collection, keyPath, NOT_SET) !== NOT_SET;
|
|
4738
5028
|
}
|
|
4739
5029
|
|
|
4740
5030
|
function hasIn(searchKeyPath) {
|
|
@@ -4809,8 +5099,8 @@ mixin(Collection, {
|
|
|
4809
5099
|
return isIndexed(this)
|
|
4810
5100
|
? this.toIndexedSeq()
|
|
4811
5101
|
: isKeyed(this)
|
|
4812
|
-
|
|
4813
|
-
|
|
5102
|
+
? this.toKeyedSeq()
|
|
5103
|
+
: this.toSetSeq();
|
|
4814
5104
|
},
|
|
4815
5105
|
|
|
4816
5106
|
toStack: function toStack() {
|
|
@@ -4895,6 +5185,7 @@ mixin(Collection, {
|
|
|
4895
5185
|
var joined = '';
|
|
4896
5186
|
var isFirst = true;
|
|
4897
5187
|
this.__iterate(function (v) {
|
|
5188
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
4898
5189
|
isFirst ? (isFirst = false) : (joined += separator);
|
|
4899
5190
|
joined += v !== null && v !== undefined ? v.toString() : '';
|
|
4900
5191
|
});
|
|
@@ -5446,12 +5737,12 @@ function hashCollection(collection) {
|
|
|
5446
5737
|
h = (h + hashMerge(hash(v), hash(k))) | 0;
|
|
5447
5738
|
}
|
|
5448
5739
|
: ordered
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5740
|
+
? function (v) {
|
|
5741
|
+
h = (31 * h + hash(v)) | 0;
|
|
5742
|
+
}
|
|
5743
|
+
: function (v) {
|
|
5744
|
+
h = (h + hash(v)) | 0;
|
|
5745
|
+
}
|
|
5455
5746
|
);
|
|
5456
5747
|
|
|
5457
5748
|
return murmurHashOfSize(collection.size, h);
|
|
@@ -5478,12 +5769,12 @@ var OrderedSet = /*@__PURE__*/(function (Set) {
|
|
|
5478
5769
|
return value === undefined || value === null
|
|
5479
5770
|
? emptyOrderedSet()
|
|
5480
5771
|
: isOrderedSet(value)
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5772
|
+
? value
|
|
5773
|
+
: emptyOrderedSet().withMutations(function (set) {
|
|
5774
|
+
var iter = SetCollection(value);
|
|
5775
|
+
assertNotInfinite(iter.size);
|
|
5776
|
+
iter.forEach(function (v) { return set.add(v); });
|
|
5777
|
+
});
|
|
5487
5778
|
}
|
|
5488
5779
|
|
|
5489
5780
|
if ( Set ) OrderedSet.__proto__ = Set;
|
|
@@ -5533,7 +5824,7 @@ function emptyOrderedSet() {
|
|
|
5533
5824
|
|
|
5534
5825
|
var PairSorting = {
|
|
5535
5826
|
LeftThenRight: -1,
|
|
5536
|
-
RightThenLeft:
|
|
5827
|
+
RightThenLeft: 1,
|
|
5537
5828
|
};
|
|
5538
5829
|
|
|
5539
5830
|
function throwOnInvalidDefaultValues(defaultValues) {
|
|
@@ -5585,6 +5876,7 @@ var Record = function Record(defaultValues, name) {
|
|
|
5585
5876
|
indices[propName] = i;
|
|
5586
5877
|
if (RecordTypePrototype[propName]) {
|
|
5587
5878
|
/* eslint-disable no-console */
|
|
5879
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
5588
5880
|
typeof console === 'object' &&
|
|
5589
5881
|
console.warn &&
|
|
5590
5882
|
console.warn(
|
|
@@ -5774,6 +6066,7 @@ function setProp(prototype, name) {
|
|
|
5774
6066
|
this.set(name, value);
|
|
5775
6067
|
},
|
|
5776
6068
|
});
|
|
6069
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO enable eslint here
|
|
5777
6070
|
} catch (error) {
|
|
5778
6071
|
// Object.defineProperty failed. Probably IE8.
|
|
5779
6072
|
}
|
|
@@ -5902,6 +6195,7 @@ function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
|
|
|
5902
6195
|
throw new TypeError('Cannot convert circular structure to Immutable');
|
|
5903
6196
|
}
|
|
5904
6197
|
stack.push(value);
|
|
6198
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
5905
6199
|
keyPath && key !== '' && keyPath.push(key);
|
|
5906
6200
|
var converted = converter.call(
|
|
5907
6201
|
parentValue,
|
|
@@ -5911,6 +6205,7 @@ function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
|
|
|
5911
6205
|
keyPath && keyPath.slice()
|
|
5912
6206
|
);
|
|
5913
6207
|
stack.pop();
|
|
6208
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
5914
6209
|
keyPath && keyPath.pop();
|
|
5915
6210
|
return converted;
|
|
5916
6211
|
}
|
|
@@ -5922,7 +6217,7 @@ function defaultConverter(k, v) {
|
|
|
5922
6217
|
return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
|
|
5923
6218
|
}
|
|
5924
6219
|
|
|
5925
|
-
var version = "5.0
|
|
6220
|
+
var version = "5.1.0";
|
|
5926
6221
|
|
|
5927
6222
|
// Note: Iterable is deprecated
|
|
5928
6223
|
var Iterable = Collection;
|