immutable 5.1.2 → 5.1.4
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 +54 -84
- package/dist/immutable.d.ts +16 -1139
- package/dist/immutable.es.js +1075 -1121
- package/dist/immutable.js +1075 -1121
- package/dist/immutable.min.js +1 -1
- package/package.json +1 -1
package/dist/immutable.js
CHANGED
|
@@ -28,105 +28,25 @@
|
|
|
28
28
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Immutable = {}));
|
|
29
29
|
})(this, (function (exports) { 'use strict';
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
var DELETE = 'delete';
|
|
33
|
-
// Constants describing the size of trie nodes.
|
|
34
|
-
var SHIFT = 5; // Resulted in best performance after ______?
|
|
35
|
-
var SIZE = 1 << SHIFT;
|
|
36
|
-
var MASK = SIZE - 1;
|
|
37
|
-
// A consistent shared value representing "not set" which equals nothing other
|
|
38
|
-
// than itself, and nothing that could be provided externally.
|
|
39
|
-
var NOT_SET = {};
|
|
40
|
-
// Boolean references, Rough equivalent of `bool &`.
|
|
41
|
-
function MakeRef() {
|
|
42
|
-
return { value: false };
|
|
43
|
-
}
|
|
44
|
-
function SetRef(ref) {
|
|
45
|
-
if (ref) {
|
|
46
|
-
ref.value = true;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// A function which returns a value representing an "owner" for transient writes
|
|
50
|
-
// to tries. The return value will only ever equal itself, and will not equal
|
|
51
|
-
// the return of any subsequent call of this function.
|
|
52
|
-
function OwnerID() { }
|
|
53
|
-
function ensureSize(iter) {
|
|
54
|
-
// @ts-expect-error size should exists on Collection
|
|
55
|
-
if (iter.size === undefined) {
|
|
56
|
-
// @ts-expect-error size should exists on Collection, __iterate does exist on Collection
|
|
57
|
-
iter.size = iter.__iterate(returnTrue);
|
|
58
|
-
}
|
|
59
|
-
// @ts-expect-error size should exists on Collection
|
|
60
|
-
return iter.size;
|
|
61
|
-
}
|
|
62
|
-
function wrapIndex(iter, index) {
|
|
63
|
-
// This implements "is array index" which the ECMAString spec defines as:
|
|
64
|
-
//
|
|
65
|
-
// A String property name P is an array index if and only if
|
|
66
|
-
// ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
|
|
67
|
-
// to 2^32−1.
|
|
68
|
-
//
|
|
69
|
-
// http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
|
|
70
|
-
if (typeof index !== 'number') {
|
|
71
|
-
var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
|
|
72
|
-
if ('' + uint32Index !== index || uint32Index === 4294967295) {
|
|
73
|
-
return NaN;
|
|
74
|
-
}
|
|
75
|
-
index = uint32Index;
|
|
76
|
-
}
|
|
77
|
-
return index < 0 ? ensureSize(iter) + index : index;
|
|
78
|
-
}
|
|
79
|
-
function returnTrue() {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
function wholeSlice(begin, end, size) {
|
|
83
|
-
return (((begin === 0 && !isNeg(begin)) ||
|
|
84
|
-
(size !== undefined && begin <= -size)) &&
|
|
85
|
-
(end === undefined || (size !== undefined && end >= size)));
|
|
86
|
-
}
|
|
87
|
-
function resolveBegin(begin, size) {
|
|
88
|
-
return resolveIndex(begin, size, 0);
|
|
89
|
-
}
|
|
90
|
-
function resolveEnd(end, size) {
|
|
91
|
-
return resolveIndex(end, size, size);
|
|
92
|
-
}
|
|
93
|
-
function resolveIndex(index, size, defaultIndex) {
|
|
94
|
-
// Sanitize indices using this shorthand for ToInt32(argument)
|
|
95
|
-
// http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
|
|
96
|
-
return index === undefined
|
|
97
|
-
? defaultIndex
|
|
98
|
-
: isNeg(index)
|
|
99
|
-
? size === Infinity
|
|
100
|
-
? size
|
|
101
|
-
: Math.max(0, size + index) | 0
|
|
102
|
-
: size === undefined || size === index
|
|
103
|
-
? index
|
|
104
|
-
: Math.min(size, index) | 0;
|
|
105
|
-
}
|
|
106
|
-
function isNeg(value) {
|
|
107
|
-
// Account for -0 which is negative, but not less than 0.
|
|
108
|
-
return value < 0 || (value === 0 && 1 / value === -Infinity);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Note: value is unchanged to not break immutable-devtools.
|
|
112
|
-
var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
|
|
31
|
+
var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
|
|
113
32
|
/**
|
|
114
|
-
* True if `
|
|
33
|
+
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
|
|
115
34
|
*
|
|
116
35
|
* ```js
|
|
117
|
-
* import {
|
|
36
|
+
* import { isIndexed, Map, List, Stack, Set } from 'immutable';
|
|
118
37
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
38
|
+
* isIndexed([]); // false
|
|
39
|
+
* isIndexed({}); // false
|
|
40
|
+
* isIndexed(Map()); // false
|
|
41
|
+
* isIndexed(List()); // true
|
|
42
|
+
* isIndexed(Stack()); // true
|
|
43
|
+
* isIndexed(Set()); // false
|
|
124
44
|
* ```
|
|
125
45
|
*/
|
|
126
|
-
function
|
|
127
|
-
return Boolean(
|
|
128
|
-
// @ts-expect-error:
|
|
129
|
-
|
|
46
|
+
function isIndexed(maybeIndexed) {
|
|
47
|
+
return Boolean(maybeIndexed &&
|
|
48
|
+
// @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
|
|
49
|
+
maybeIndexed[IS_INDEXED_SYMBOL]);
|
|
130
50
|
}
|
|
131
51
|
|
|
132
52
|
var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
|
|
@@ -149,27 +69,6 @@
|
|
|
149
69
|
maybeKeyed[IS_KEYED_SYMBOL]);
|
|
150
70
|
}
|
|
151
71
|
|
|
152
|
-
var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
|
|
153
|
-
/**
|
|
154
|
-
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
|
|
155
|
-
*
|
|
156
|
-
* ```js
|
|
157
|
-
* import { isIndexed, Map, List, Stack, Set } from 'immutable';
|
|
158
|
-
*
|
|
159
|
-
* isIndexed([]); // false
|
|
160
|
-
* isIndexed({}); // false
|
|
161
|
-
* isIndexed(Map()); // false
|
|
162
|
-
* isIndexed(List()); // true
|
|
163
|
-
* isIndexed(Stack()); // true
|
|
164
|
-
* isIndexed(Set()); // false
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
function isIndexed(maybeIndexed) {
|
|
168
|
-
return Boolean(maybeIndexed &&
|
|
169
|
-
// @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
|
|
170
|
-
maybeIndexed[IS_INDEXED_SYMBOL]);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
72
|
/**
|
|
174
73
|
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
|
|
175
74
|
*
|
|
@@ -188,6 +87,27 @@
|
|
|
188
87
|
return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
|
|
189
88
|
}
|
|
190
89
|
|
|
90
|
+
// Note: value is unchanged to not break immutable-devtools.
|
|
91
|
+
var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
|
|
92
|
+
/**
|
|
93
|
+
* True if `maybeCollection` is a Collection, or any of its subclasses.
|
|
94
|
+
*
|
|
95
|
+
* ```js
|
|
96
|
+
* import { isCollection, Map, List, Stack } from 'immutable';
|
|
97
|
+
*
|
|
98
|
+
* isCollection([]); // false
|
|
99
|
+
* isCollection({}); // false
|
|
100
|
+
* isCollection(Map()); // true
|
|
101
|
+
* isCollection(List()); // true
|
|
102
|
+
* isCollection(Stack()); // true
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
function isCollection(maybeCollection) {
|
|
106
|
+
return Boolean(maybeCollection &&
|
|
107
|
+
// @ts-expect-error: maybeCollection is typed as `{}`, need to change in 6.0 to `maybeCollection && typeof maybeCollection === 'object' && IS_COLLECTION_SYMBOL in maybeCollection`
|
|
108
|
+
maybeCollection[IS_COLLECTION_SYMBOL]);
|
|
109
|
+
}
|
|
110
|
+
|
|
191
111
|
var Collection = function Collection(value) {
|
|
192
112
|
// eslint-disable-next-line no-constructor-return
|
|
193
113
|
return isCollection(value) ? value : Seq(value);
|
|
@@ -236,158 +156,236 @@
|
|
|
236
156
|
Collection.Indexed = IndexedCollection;
|
|
237
157
|
Collection.Set = SetCollection;
|
|
238
158
|
|
|
239
|
-
var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
|
|
240
|
-
/**
|
|
241
|
-
* True if `maybeSeq` is a Seq.
|
|
242
|
-
*/
|
|
243
|
-
function isSeq(maybeSeq) {
|
|
244
|
-
return Boolean(maybeSeq &&
|
|
245
|
-
// @ts-expect-error: maybeSeq is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSeq === 'object' && MAYBE_SEQ_SYMBOL in maybeSeq`
|
|
246
|
-
maybeSeq[IS_SEQ_SYMBOL]);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
|
|
250
|
-
/**
|
|
251
|
-
* True if `maybeRecord` is a Record.
|
|
252
|
-
*/
|
|
253
|
-
function isRecord(maybeRecord) {
|
|
254
|
-
return Boolean(maybeRecord &&
|
|
255
|
-
// @ts-expect-error: maybeRecord is typed as `{}`, need to change in 6.0 to `maybeRecord && typeof maybeRecord === 'object' && IS_RECORD_SYMBOL in maybeRecord`
|
|
256
|
-
maybeRecord[IS_RECORD_SYMBOL]);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
261
|
-
*
|
|
262
|
-
* Note: Still returns true even if the collections is within a `withMutations()`.
|
|
263
|
-
*
|
|
264
|
-
* ```js
|
|
265
|
-
* import { isImmutable, Map, List, Stack } from 'immutable';
|
|
266
|
-
* isImmutable([]); // false
|
|
267
|
-
* isImmutable({}); // false
|
|
268
|
-
* isImmutable(Map()); // true
|
|
269
|
-
* isImmutable(List()); // true
|
|
270
|
-
* isImmutable(Stack()); // true
|
|
271
|
-
* isImmutable(Map().asMutable()); // true
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
function isImmutable(maybeImmutable) {
|
|
275
|
-
return isCollection(maybeImmutable) || isRecord(maybeImmutable);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
|
|
279
|
-
function isOrdered(maybeOrdered) {
|
|
280
|
-
return Boolean(maybeOrdered &&
|
|
281
|
-
// @ts-expect-error: maybeOrdered is typed as `{}`, need to change in 6.0 to `maybeOrdered && typeof maybeOrdered === 'object' && IS_ORDERED_SYMBOL in maybeOrdered`
|
|
282
|
-
maybeOrdered[IS_ORDERED_SYMBOL]);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
159
|
var ITERATE_KEYS = 0;
|
|
286
160
|
var ITERATE_VALUES = 1;
|
|
287
161
|
var ITERATE_ENTRIES = 2;
|
|
288
|
-
|
|
162
|
+
// TODO Symbol is widely available in modern JavaScript environments, clean this
|
|
289
163
|
var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
290
164
|
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
|
291
|
-
|
|
292
165
|
var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
|
|
293
|
-
|
|
166
|
+
// @ts-expect-error: properties are not supported in buble
|
|
294
167
|
var Iterator = function Iterator(next) {
|
|
295
|
-
|
|
168
|
+
// @ts-expect-error: properties are not supported in buble
|
|
169
|
+
this.next = next;
|
|
296
170
|
};
|
|
297
|
-
|
|
298
171
|
Iterator.prototype.toString = function toString () {
|
|
299
|
-
|
|
172
|
+
return '[Iterator]';
|
|
300
173
|
};
|
|
301
|
-
|
|
174
|
+
// @ts-expect-error: static properties are not supported in buble
|
|
302
175
|
Iterator.KEYS = ITERATE_KEYS;
|
|
176
|
+
// @ts-expect-error: static properties are not supported in buble
|
|
303
177
|
Iterator.VALUES = ITERATE_VALUES;
|
|
178
|
+
// @ts-expect-error: static properties are not supported in buble
|
|
304
179
|
Iterator.ENTRIES = ITERATE_ENTRIES;
|
|
305
|
-
|
|
180
|
+
// @ts-expect-error: properties are not supported in buble
|
|
306
181
|
Iterator.prototype.inspect = Iterator.prototype.toSource = function () {
|
|
307
|
-
|
|
182
|
+
return this.toString();
|
|
308
183
|
};
|
|
184
|
+
// @ts-expect-error don't know how to type this
|
|
309
185
|
Iterator.prototype[ITERATOR_SYMBOL] = function () {
|
|
310
|
-
|
|
186
|
+
return this;
|
|
311
187
|
};
|
|
312
|
-
|
|
313
188
|
function iteratorValue(type, k, v, iteratorResult) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
189
|
+
var value = type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v];
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
191
|
+
iteratorResult
|
|
192
|
+
? (iteratorResult.value = value)
|
|
193
|
+
: (iteratorResult = {
|
|
194
|
+
// @ts-expect-error ensure value is not undefined
|
|
195
|
+
value: value,
|
|
196
|
+
done: false,
|
|
197
|
+
});
|
|
198
|
+
return iteratorResult;
|
|
324
199
|
}
|
|
325
|
-
|
|
326
200
|
function iteratorDone() {
|
|
327
|
-
|
|
201
|
+
return { value: undefined, done: true };
|
|
328
202
|
}
|
|
329
|
-
|
|
330
203
|
function hasIterator(maybeIterable) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return !!getIteratorFn(maybeIterable);
|
|
204
|
+
if (Array.isArray(maybeIterable)) {
|
|
205
|
+
// IE11 trick as it does not support `Symbol.iterator`
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return !!getIteratorFn(maybeIterable);
|
|
337
209
|
}
|
|
338
|
-
|
|
339
210
|
function isIterator(maybeIterator) {
|
|
340
|
-
|
|
211
|
+
return !!(maybeIterator &&
|
|
212
|
+
// @ts-expect-error: maybeIterator is typed as `{}`
|
|
213
|
+
typeof maybeIterator.next === 'function');
|
|
341
214
|
}
|
|
342
|
-
|
|
343
215
|
function getIterator(iterable) {
|
|
344
|
-
|
|
345
|
-
|
|
216
|
+
var iteratorFn = getIteratorFn(iterable);
|
|
217
|
+
return iteratorFn && iteratorFn.call(iterable);
|
|
346
218
|
}
|
|
347
|
-
|
|
348
219
|
function getIteratorFn(iterable) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
220
|
+
var iteratorFn = iterable &&
|
|
221
|
+
// @ts-expect-error: maybeIterator is typed as `{}`
|
|
222
|
+
((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
|
|
223
|
+
// @ts-expect-error: maybeIterator is typed as `{}`
|
|
224
|
+
iterable[FAUX_ITERATOR_SYMBOL]);
|
|
225
|
+
if (typeof iteratorFn === 'function') {
|
|
226
|
+
return iteratorFn;
|
|
227
|
+
}
|
|
356
228
|
}
|
|
357
|
-
|
|
358
229
|
function isEntriesIterable(maybeIterable) {
|
|
359
|
-
|
|
360
|
-
|
|
230
|
+
var iteratorFn = getIteratorFn(maybeIterable);
|
|
231
|
+
// @ts-expect-error: maybeIterator is typed as `{}`
|
|
232
|
+
return iteratorFn && iteratorFn === maybeIterable.entries;
|
|
361
233
|
}
|
|
362
|
-
|
|
363
234
|
function isKeysIterable(maybeIterable) {
|
|
364
|
-
|
|
365
|
-
|
|
235
|
+
var iteratorFn = getIteratorFn(maybeIterable);
|
|
236
|
+
// @ts-expect-error: maybeIterator is typed as `{}`
|
|
237
|
+
return iteratorFn && iteratorFn === maybeIterable.keys;
|
|
366
238
|
}
|
|
367
239
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
value.length >= 0 &&
|
|
381
|
-
// @ts-expect-error check that `'length' in value &&`
|
|
382
|
-
(value.length === 0
|
|
383
|
-
? // Only {length: 0} is considered Array-like.
|
|
384
|
-
Object.keys(value).length === 1
|
|
385
|
-
: // An object is only Array-like if it has a property where the last value
|
|
386
|
-
// in the array-like may be found (which could be undefined).
|
|
387
|
-
// @ts-expect-error check that `'length' in value &&`
|
|
388
|
-
value.hasOwnProperty(value.length - 1)));
|
|
240
|
+
// Used for setting prototype methods that IE8 chokes on.
|
|
241
|
+
var DELETE = 'delete';
|
|
242
|
+
// Constants describing the size of trie nodes.
|
|
243
|
+
var SHIFT = 5; // Resulted in best performance after ______?
|
|
244
|
+
var SIZE = 1 << SHIFT;
|
|
245
|
+
var MASK = SIZE - 1;
|
|
246
|
+
// A consistent shared value representing "not set" which equals nothing other
|
|
247
|
+
// than itself, and nothing that could be provided externally.
|
|
248
|
+
var NOT_SET = {};
|
|
249
|
+
// Boolean references, Rough equivalent of `bool &`.
|
|
250
|
+
function MakeRef() {
|
|
251
|
+
return { value: false };
|
|
389
252
|
}
|
|
390
|
-
|
|
253
|
+
function SetRef(ref) {
|
|
254
|
+
if (ref) {
|
|
255
|
+
ref.value = true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// A function which returns a value representing an "owner" for transient writes
|
|
259
|
+
// to tries. The return value will only ever equal itself, and will not equal
|
|
260
|
+
// the return of any subsequent call of this function.
|
|
261
|
+
function OwnerID() { }
|
|
262
|
+
function ensureSize(iter) {
|
|
263
|
+
// @ts-expect-error size should exists on Collection
|
|
264
|
+
if (iter.size === undefined) {
|
|
265
|
+
// @ts-expect-error size should exists on Collection, __iterate does exist on Collection
|
|
266
|
+
iter.size = iter.__iterate(returnTrue);
|
|
267
|
+
}
|
|
268
|
+
// @ts-expect-error size should exists on Collection
|
|
269
|
+
return iter.size;
|
|
270
|
+
}
|
|
271
|
+
function wrapIndex(iter, index) {
|
|
272
|
+
// This implements "is array index" which the ECMAString spec defines as:
|
|
273
|
+
//
|
|
274
|
+
// A String property name P is an array index if and only if
|
|
275
|
+
// ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
|
|
276
|
+
// to 2^32−1.
|
|
277
|
+
//
|
|
278
|
+
// http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
|
|
279
|
+
if (typeof index !== 'number') {
|
|
280
|
+
var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
|
|
281
|
+
if ('' + uint32Index !== index || uint32Index === 4294967295) {
|
|
282
|
+
return NaN;
|
|
283
|
+
}
|
|
284
|
+
index = uint32Index;
|
|
285
|
+
}
|
|
286
|
+
return index < 0 ? ensureSize(iter) + index : index;
|
|
287
|
+
}
|
|
288
|
+
function returnTrue() {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
function wholeSlice(begin, end, size) {
|
|
292
|
+
return (((begin === 0 && !isNeg(begin)) ||
|
|
293
|
+
(size !== undefined && begin <= -size)) &&
|
|
294
|
+
(end === undefined || (size !== undefined && end >= size)));
|
|
295
|
+
}
|
|
296
|
+
function resolveBegin(begin, size) {
|
|
297
|
+
return resolveIndex(begin, size, 0);
|
|
298
|
+
}
|
|
299
|
+
function resolveEnd(end, size) {
|
|
300
|
+
return resolveIndex(end, size, size);
|
|
301
|
+
}
|
|
302
|
+
function resolveIndex(index, size, defaultIndex) {
|
|
303
|
+
// Sanitize indices using this shorthand for ToInt32(argument)
|
|
304
|
+
// http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
|
|
305
|
+
return index === undefined
|
|
306
|
+
? defaultIndex
|
|
307
|
+
: isNeg(index)
|
|
308
|
+
? size === Infinity
|
|
309
|
+
? size
|
|
310
|
+
: Math.max(0, size + index) | 0
|
|
311
|
+
: size === undefined || size === index
|
|
312
|
+
? index
|
|
313
|
+
: Math.min(size, index) | 0;
|
|
314
|
+
}
|
|
315
|
+
function isNeg(value) {
|
|
316
|
+
// Account for -0 which is negative, but not less than 0.
|
|
317
|
+
return value < 0 || (value === 0 && 1 / value === -Infinity);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
|
|
321
|
+
/**
|
|
322
|
+
* True if `maybeRecord` is a Record.
|
|
323
|
+
*/
|
|
324
|
+
function isRecord(maybeRecord) {
|
|
325
|
+
return Boolean(maybeRecord &&
|
|
326
|
+
// @ts-expect-error: maybeRecord is typed as `{}`, need to change in 6.0 to `maybeRecord && typeof maybeRecord === 'object' && IS_RECORD_SYMBOL in maybeRecord`
|
|
327
|
+
maybeRecord[IS_RECORD_SYMBOL]);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
332
|
+
*
|
|
333
|
+
* Note: Still returns true even if the collections is within a `withMutations()`.
|
|
334
|
+
*
|
|
335
|
+
* ```js
|
|
336
|
+
* import { isImmutable, Map, List, Stack } from 'immutable';
|
|
337
|
+
* isImmutable([]); // false
|
|
338
|
+
* isImmutable({}); // false
|
|
339
|
+
* isImmutable(Map()); // true
|
|
340
|
+
* isImmutable(List()); // true
|
|
341
|
+
* isImmutable(Stack()); // true
|
|
342
|
+
* isImmutable(Map().asMutable()); // true
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
function isImmutable(maybeImmutable) {
|
|
346
|
+
return isCollection(maybeImmutable) || isRecord(maybeImmutable);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
|
|
350
|
+
function isOrdered(maybeOrdered) {
|
|
351
|
+
return Boolean(maybeOrdered &&
|
|
352
|
+
// @ts-expect-error: maybeOrdered is typed as `{}`, need to change in 6.0 to `maybeOrdered && typeof maybeOrdered === 'object' && IS_ORDERED_SYMBOL in maybeOrdered`
|
|
353
|
+
maybeOrdered[IS_ORDERED_SYMBOL]);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
|
|
357
|
+
/**
|
|
358
|
+
* True if `maybeSeq` is a Seq.
|
|
359
|
+
*/
|
|
360
|
+
function isSeq(maybeSeq) {
|
|
361
|
+
return Boolean(maybeSeq &&
|
|
362
|
+
// @ts-expect-error: maybeSeq is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSeq === 'object' && MAYBE_SEQ_SYMBOL in maybeSeq`
|
|
363
|
+
maybeSeq[IS_SEQ_SYMBOL]);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
367
|
+
|
|
368
|
+
function isArrayLike(value) {
|
|
369
|
+
if (Array.isArray(value) || typeof value === 'string') {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
// @ts-expect-error "Type 'unknown' is not assignable to type 'boolean'" : convert to Boolean
|
|
373
|
+
return (value &&
|
|
374
|
+
typeof value === 'object' &&
|
|
375
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
376
|
+
Number.isInteger(value.length) &&
|
|
377
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
378
|
+
value.length >= 0 &&
|
|
379
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
380
|
+
(value.length === 0
|
|
381
|
+
? // Only {length: 0} is considered Array-like.
|
|
382
|
+
Object.keys(value).length === 1
|
|
383
|
+
: // An object is only Array-like if it has a property where the last value
|
|
384
|
+
// in the array-like may be found (which could be undefined).
|
|
385
|
+
// @ts-expect-error check that `'length' in value &&`
|
|
386
|
+
value.hasOwnProperty(value.length - 1)));
|
|
387
|
+
}
|
|
388
|
+
|
|
391
389
|
var Seq = /*@__PURE__*/(function (Collection) {
|
|
392
390
|
function Seq(value) {
|
|
393
391
|
// eslint-disable-next-line no-constructor-return
|
|
@@ -751,119 +749,16 @@
|
|
|
751
749
|
: undefined;
|
|
752
750
|
}
|
|
753
751
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
* True if `maybeMap` is a Map.
|
|
757
|
-
*
|
|
758
|
-
* Also true for OrderedMaps.
|
|
759
|
-
*/
|
|
760
|
-
function isMap(maybeMap) {
|
|
761
|
-
return Boolean(maybeMap &&
|
|
762
|
-
// @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
|
|
763
|
-
maybeMap[IS_MAP_SYMBOL]);
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* True if `maybeOrderedMap` is an OrderedMap.
|
|
768
|
-
*/
|
|
769
|
-
function isOrderedMap(maybeOrderedMap) {
|
|
770
|
-
return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
|
|
775
|
-
* and `hashCode()` methods.
|
|
776
|
-
*
|
|
777
|
-
* Any two instances of *value objects* can be compared for value equality with
|
|
778
|
-
* `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
|
|
779
|
-
*/
|
|
780
|
-
function isValueObject(maybeValue) {
|
|
781
|
-
return Boolean(maybeValue &&
|
|
782
|
-
// @ts-expect-error: maybeValue is typed as `{}`
|
|
783
|
-
typeof maybeValue.equals === 'function' &&
|
|
784
|
-
// @ts-expect-error: maybeValue is typed as `{}`
|
|
785
|
-
typeof maybeValue.hashCode === 'function');
|
|
752
|
+
function asImmutable() {
|
|
753
|
+
return this.__ensureOwner();
|
|
786
754
|
}
|
|
787
755
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
* and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
|
|
791
|
-
*
|
|
792
|
-
* NaN is considered the same as NaN, however -0 and 0 are considered the same
|
|
793
|
-
* value, which is different from the algorithm described by
|
|
794
|
-
* [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
|
795
|
-
*
|
|
796
|
-
* This is extended further to allow Objects to describe the values they
|
|
797
|
-
* represent, by way of `valueOf` or `equals` (and `hashCode`).
|
|
798
|
-
*
|
|
799
|
-
* Note: because of this extension, the key equality of Immutable.Map and the
|
|
800
|
-
* value equality of Immutable.Set will differ from ES6 Map and Set.
|
|
801
|
-
*
|
|
802
|
-
* ### Defining custom values
|
|
803
|
-
*
|
|
804
|
-
* The easiest way to describe the value an object represents is by implementing
|
|
805
|
-
* `valueOf`. For example, `Date` represents a value by returning a unix
|
|
806
|
-
* timestamp for `valueOf`:
|
|
807
|
-
*
|
|
808
|
-
* var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
|
|
809
|
-
* var date2 = new Date(1234567890000);
|
|
810
|
-
* date1.valueOf(); // 1234567890000
|
|
811
|
-
* assert( date1 !== date2 );
|
|
812
|
-
* assert( Immutable.is( date1, date2 ) );
|
|
813
|
-
*
|
|
814
|
-
* Note: overriding `valueOf` may have other implications if you use this object
|
|
815
|
-
* where JavaScript expects a primitive, such as implicit string coercion.
|
|
816
|
-
*
|
|
817
|
-
* For more complex types, especially collections, implementing `valueOf` may
|
|
818
|
-
* not be performant. An alternative is to implement `equals` and `hashCode`.
|
|
819
|
-
*
|
|
820
|
-
* `equals` takes another object, presumably of similar type, and returns true
|
|
821
|
-
* if it is equal. Equality is symmetrical, so the same result should be
|
|
822
|
-
* returned if this and the argument are flipped.
|
|
823
|
-
*
|
|
824
|
-
* assert( a.equals(b) === b.equals(a) );
|
|
825
|
-
*
|
|
826
|
-
* `hashCode` returns a 32bit integer number representing the object which will
|
|
827
|
-
* be used to determine how to store the value object in a Map or Set. You must
|
|
828
|
-
* provide both or neither methods, one must not exist without the other.
|
|
829
|
-
*
|
|
830
|
-
* Also, an important relationship between these methods must be upheld: if two
|
|
831
|
-
* values are equal, they *must* return the same hashCode. If the values are not
|
|
832
|
-
* equal, they might have the same hashCode; this is called a hash collision,
|
|
833
|
-
* and while undesirable for performance reasons, it is acceptable.
|
|
834
|
-
*
|
|
835
|
-
* if (a.equals(b)) {
|
|
836
|
-
* assert( a.hashCode() === b.hashCode() );
|
|
837
|
-
* }
|
|
838
|
-
*
|
|
839
|
-
* All Immutable collections are Value Objects: they implement `equals()`
|
|
840
|
-
* and `hashCode()`.
|
|
841
|
-
*/
|
|
842
|
-
function is(valueA, valueB) {
|
|
843
|
-
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
if (!valueA || !valueB) {
|
|
847
|
-
return false;
|
|
848
|
-
}
|
|
849
|
-
if (typeof valueA.valueOf === 'function' &&
|
|
850
|
-
typeof valueB.valueOf === 'function') {
|
|
851
|
-
valueA = valueA.valueOf();
|
|
852
|
-
valueB = valueB.valueOf();
|
|
853
|
-
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
854
|
-
return true;
|
|
855
|
-
}
|
|
856
|
-
if (!valueA || !valueB) {
|
|
857
|
-
return false;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
return !!(isValueObject(valueA) &&
|
|
861
|
-
isValueObject(valueB) &&
|
|
862
|
-
valueA.equals(valueB));
|
|
756
|
+
function asMutable() {
|
|
757
|
+
return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
|
|
863
758
|
}
|
|
864
759
|
|
|
865
|
-
|
|
866
|
-
|
|
760
|
+
// TODO remove in v6 as Math.imul is widely available now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
|
|
761
|
+
var imul = typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
|
|
867
762
|
? Math.imul
|
|
868
763
|
: function imul(a, b) {
|
|
869
764
|
a |= 0; // int
|
|
@@ -872,247 +767,238 @@
|
|
|
872
767
|
var d = b & 0xffff;
|
|
873
768
|
// Shift by 0 fixes the sign on the high part.
|
|
874
769
|
return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
|
|
875
|
-
|
|
876
|
-
|
|
770
|
+
};
|
|
877
771
|
// v8 has an optimization for storing 31-bit signed numbers.
|
|
878
772
|
// Values which have either 00 or 11 as the high order bits qualify.
|
|
879
773
|
// This function drops the highest order bit in a signed number, maintaining
|
|
880
774
|
// the sign bit.
|
|
881
775
|
function smi(i32) {
|
|
882
|
-
|
|
776
|
+
return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
|
|
883
777
|
}
|
|
884
778
|
|
|
885
779
|
var defaultValueOf = Object.prototype.valueOf;
|
|
886
|
-
|
|
887
780
|
function hash(o) {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
:
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
throw new Error('Value type ' + typeof v + ' cannot be hashed.');
|
|
927
|
-
}
|
|
781
|
+
// eslint-disable-next-line eqeqeq
|
|
782
|
+
if (o == null) {
|
|
783
|
+
return hashNullish(o);
|
|
784
|
+
}
|
|
785
|
+
// @ts-expect-error don't care about object beeing typed as `{}` here
|
|
786
|
+
if (typeof o.hashCode === 'function') {
|
|
787
|
+
// Drop any high bits from accidentally long hash codes.
|
|
788
|
+
// @ts-expect-error don't care about object beeing typed as `{}` here
|
|
789
|
+
return smi(o.hashCode(o));
|
|
790
|
+
}
|
|
791
|
+
var v = valueOf(o);
|
|
792
|
+
// eslint-disable-next-line eqeqeq
|
|
793
|
+
if (v == null) {
|
|
794
|
+
return hashNullish(v);
|
|
795
|
+
}
|
|
796
|
+
switch (typeof v) {
|
|
797
|
+
case 'boolean':
|
|
798
|
+
// The hash values for built-in constants are a 1 value for each 5-byte
|
|
799
|
+
// shift region expect for the first, which encodes the value. This
|
|
800
|
+
// reduces the odds of a hash collision for these common values.
|
|
801
|
+
return v ? 0x42108421 : 0x42108420;
|
|
802
|
+
case 'number':
|
|
803
|
+
return hashNumber(v);
|
|
804
|
+
case 'string':
|
|
805
|
+
return v.length > STRING_HASH_CACHE_MIN_STRLEN
|
|
806
|
+
? cachedHashString(v)
|
|
807
|
+
: hashString(v);
|
|
808
|
+
case 'object':
|
|
809
|
+
case 'function':
|
|
810
|
+
return hashJSObj(v);
|
|
811
|
+
case 'symbol':
|
|
812
|
+
return hashSymbol(v);
|
|
813
|
+
default:
|
|
814
|
+
if (typeof v.toString === 'function') {
|
|
815
|
+
return hashString(v.toString());
|
|
816
|
+
}
|
|
817
|
+
throw new Error('Value type ' + typeof v + ' cannot be hashed.');
|
|
818
|
+
}
|
|
928
819
|
}
|
|
929
|
-
|
|
930
820
|
function hashNullish(nullish) {
|
|
931
|
-
|
|
821
|
+
return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
|
|
932
822
|
}
|
|
933
|
-
|
|
934
823
|
// Compress arbitrarily large numbers into smi hashes.
|
|
935
824
|
function hashNumber(n) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
825
|
+
if (n !== n || n === Infinity) {
|
|
826
|
+
return 0;
|
|
827
|
+
}
|
|
828
|
+
var hash = n | 0;
|
|
829
|
+
if (hash !== n) {
|
|
830
|
+
hash ^= n * 0xffffffff;
|
|
831
|
+
}
|
|
832
|
+
while (n > 0xffffffff) {
|
|
833
|
+
n /= 0xffffffff;
|
|
834
|
+
hash ^= n;
|
|
835
|
+
}
|
|
836
|
+
return smi(hash);
|
|
948
837
|
}
|
|
949
|
-
|
|
950
838
|
function cachedHashString(string) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
839
|
+
var hashed = stringHashCache[string];
|
|
840
|
+
if (hashed === undefined) {
|
|
841
|
+
hashed = hashString(string);
|
|
842
|
+
if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
|
|
843
|
+
STRING_HASH_CACHE_SIZE = 0;
|
|
844
|
+
stringHashCache = {};
|
|
845
|
+
}
|
|
846
|
+
STRING_HASH_CACHE_SIZE++;
|
|
847
|
+
stringHashCache[string] = hashed;
|
|
957
848
|
}
|
|
958
|
-
|
|
959
|
-
stringHashCache[string] = hashed;
|
|
960
|
-
}
|
|
961
|
-
return hashed;
|
|
849
|
+
return hashed;
|
|
962
850
|
}
|
|
963
|
-
|
|
964
851
|
// http://jsperf.com/hashing-strings
|
|
965
852
|
function hashString(string) {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
853
|
+
// This is the hash from JVM
|
|
854
|
+
// The hash code for a string is computed as
|
|
855
|
+
// s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
|
|
856
|
+
// where s[i] is the ith character of the string and n is the length of
|
|
857
|
+
// the string. We "mod" the result to make it between 0 (inclusive) and 2^31
|
|
858
|
+
// (exclusive) by dropping high bits.
|
|
859
|
+
var hashed = 0;
|
|
860
|
+
for (var ii = 0; ii < string.length; ii++) {
|
|
861
|
+
hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
|
|
862
|
+
}
|
|
863
|
+
return smi(hashed);
|
|
977
864
|
}
|
|
978
|
-
|
|
979
865
|
function hashSymbol(sym) {
|
|
980
|
-
|
|
981
|
-
|
|
866
|
+
var hashed = symbolMap[sym];
|
|
867
|
+
if (hashed !== undefined) {
|
|
868
|
+
return hashed;
|
|
869
|
+
}
|
|
870
|
+
hashed = nextHash();
|
|
871
|
+
symbolMap[sym] = hashed;
|
|
982
872
|
return hashed;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
hashed = nextHash();
|
|
986
|
-
|
|
987
|
-
symbolMap[sym] = hashed;
|
|
988
|
-
|
|
989
|
-
return hashed;
|
|
990
873
|
}
|
|
991
|
-
|
|
874
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
992
875
|
function hashJSObj(obj) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
876
|
+
var hashed;
|
|
877
|
+
if (usingWeakMap) {
|
|
878
|
+
// @ts-expect-error weakMap is defined
|
|
879
|
+
hashed = weakMap.get(obj);
|
|
880
|
+
if (hashed !== undefined) {
|
|
881
|
+
return hashed;
|
|
882
|
+
}
|
|
998
883
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
hashed = obj[UID_HASH_KEY];
|
|
1002
|
-
if (hashed !== undefined) {
|
|
1003
|
-
return hashed;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
if (!canDefineProperty) {
|
|
1007
|
-
hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
|
|
884
|
+
// @ts-expect-error used for old code, will be removed
|
|
885
|
+
hashed = obj[UID_HASH_KEY];
|
|
1008
886
|
if (hashed !== undefined) {
|
|
1009
|
-
|
|
887
|
+
return hashed;
|
|
1010
888
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
889
|
+
if (!canDefineProperty) {
|
|
890
|
+
// @ts-expect-error used for old code, will be removed
|
|
891
|
+
hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
|
|
892
|
+
if (hashed !== undefined) {
|
|
893
|
+
return hashed;
|
|
894
|
+
}
|
|
895
|
+
hashed = getIENodeHash(obj);
|
|
896
|
+
if (hashed !== undefined) {
|
|
897
|
+
return hashed;
|
|
898
|
+
}
|
|
1015
899
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
obj.propertyIsEnumerable !== undefined &&
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
900
|
+
hashed = nextHash();
|
|
901
|
+
if (usingWeakMap) {
|
|
902
|
+
// @ts-expect-error weakMap is defined
|
|
903
|
+
weakMap.set(obj, hashed);
|
|
904
|
+
}
|
|
905
|
+
else if (isExtensible !== undefined && isExtensible(obj) === false) {
|
|
906
|
+
throw new Error('Non-extensible objects are not allowed as keys.');
|
|
907
|
+
}
|
|
908
|
+
else if (canDefineProperty) {
|
|
909
|
+
Object.defineProperty(obj, UID_HASH_KEY, {
|
|
910
|
+
enumerable: false,
|
|
911
|
+
configurable: false,
|
|
912
|
+
writable: false,
|
|
913
|
+
value: hashed,
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
else if (obj.propertyIsEnumerable !== undefined &&
|
|
917
|
+
obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
|
|
918
|
+
// Since we can't define a non-enumerable property on the object
|
|
919
|
+
// we'll hijack one of the less-used non-enumerable properties to
|
|
920
|
+
// save our hash on it. Since this is a function it will not show up in
|
|
921
|
+
// `JSON.stringify` which is what we want.
|
|
922
|
+
obj.propertyIsEnumerable = function () {
|
|
923
|
+
return this.constructor.prototype.propertyIsEnumerable.apply(this,
|
|
924
|
+
// eslint-disable-next-line prefer-rest-params
|
|
925
|
+
arguments);
|
|
926
|
+
};
|
|
927
|
+
// @ts-expect-error used for old code, will be removed
|
|
928
|
+
obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
|
|
929
|
+
// @ts-expect-error used for old code, will be removed
|
|
930
|
+
}
|
|
931
|
+
else if (obj.nodeType !== undefined) {
|
|
932
|
+
// At this point we couldn't get the IE `uniqueID` to use as a hash
|
|
933
|
+
// and we couldn't use a non-enumerable property to exploit the
|
|
934
|
+
// dontEnum bug so we simply add the `UID_HASH_KEY` on the node
|
|
935
|
+
// itself.
|
|
936
|
+
// @ts-expect-error used for old code, will be removed
|
|
937
|
+
obj[UID_HASH_KEY] = hashed;
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
throw new Error('Unable to set a non-enumerable property on object.');
|
|
941
|
+
}
|
|
942
|
+
return hashed;
|
|
1057
943
|
}
|
|
1058
|
-
|
|
1059
944
|
// Get references to ES5 object methods.
|
|
1060
945
|
var isExtensible = Object.isExtensible;
|
|
1061
|
-
|
|
1062
946
|
// True if Object.defineProperty works as expected. IE8 fails this test.
|
|
947
|
+
// TODO remove this as widely available https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
|
|
1063
948
|
var canDefineProperty = (function () {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
949
|
+
try {
|
|
950
|
+
Object.defineProperty({}, '@', {});
|
|
951
|
+
return true;
|
|
952
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
953
|
+
}
|
|
954
|
+
catch (e) {
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
1071
957
|
})();
|
|
1072
|
-
|
|
1073
958
|
// IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
|
|
1074
959
|
// and avoid memory leaks from the IE cloneNode bug.
|
|
960
|
+
// TODO remove this method as only used if `canDefineProperty` is false
|
|
1075
961
|
function getIENodeHash(node) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
962
|
+
// @ts-expect-error don't care
|
|
963
|
+
if (node && node.nodeType > 0) {
|
|
964
|
+
// @ts-expect-error don't care
|
|
965
|
+
switch (node.nodeType) {
|
|
966
|
+
case 1: // Element
|
|
967
|
+
// @ts-expect-error don't care
|
|
968
|
+
return node.uniqueID;
|
|
969
|
+
case 9: // Document
|
|
970
|
+
// @ts-expect-error don't care
|
|
971
|
+
return node.documentElement && node.documentElement.uniqueID;
|
|
972
|
+
}
|
|
1082
973
|
}
|
|
1083
|
-
}
|
|
1084
974
|
}
|
|
1085
|
-
|
|
1086
975
|
function valueOf(obj) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
976
|
+
return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
|
|
977
|
+
? // @ts-expect-error weird the "obj" parameter as `valueOf` should not have a parameter
|
|
978
|
+
obj.valueOf(obj)
|
|
979
|
+
: obj;
|
|
1090
980
|
}
|
|
1091
|
-
|
|
1092
981
|
function nextHash() {
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
982
|
+
var nextHash = ++_objHashUID;
|
|
983
|
+
if (_objHashUID & 0x40000000) {
|
|
984
|
+
_objHashUID = 0;
|
|
985
|
+
}
|
|
986
|
+
return nextHash;
|
|
1098
987
|
}
|
|
1099
|
-
|
|
1100
988
|
// If possible, use a WeakMap.
|
|
989
|
+
// TODO using WeakMap should be true everywhere now that WeakMap is widely supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap
|
|
1101
990
|
var usingWeakMap = typeof WeakMap === 'function';
|
|
1102
991
|
var weakMap;
|
|
1103
992
|
if (usingWeakMap) {
|
|
1104
|
-
|
|
993
|
+
weakMap = new WeakMap();
|
|
1105
994
|
}
|
|
1106
|
-
|
|
1107
995
|
var symbolMap = Object.create(null);
|
|
1108
|
-
|
|
1109
996
|
var _objHashUID = 0;
|
|
1110
|
-
|
|
997
|
+
// TODO remove string as Symbol is now widely supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
|
|
1111
998
|
var UID_HASH_KEY = '__immutablehash__';
|
|
1112
999
|
if (typeof Symbol === 'function') {
|
|
1113
|
-
|
|
1000
|
+
UID_HASH_KEY = Symbol(UID_HASH_KEY);
|
|
1114
1001
|
}
|
|
1115
|
-
|
|
1116
1002
|
var STRING_HASH_CACHE_MIN_STRLEN = 16;
|
|
1117
1003
|
var STRING_HASH_CACHE_MAX_SIZE = 255;
|
|
1118
1004
|
var STRING_HASH_CACHE_SIZE = 0;
|
|
@@ -2128,283 +2014,102 @@
|
|
|
2128
2014
|
return a > b ? 1 : a < b ? -1 : 0;
|
|
2129
2015
|
}
|
|
2130
2016
|
|
|
2131
|
-
// http://jsperf.com/copy-array-inline
|
|
2132
|
-
function arrCopy(arr, offset) {
|
|
2133
|
-
offset = offset || 0;
|
|
2134
|
-
var len = Math.max(0, arr.length - offset);
|
|
2135
|
-
var newArr = new Array(len);
|
|
2136
|
-
for (var ii = 0; ii < len; ii++) {
|
|
2137
|
-
// @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
|
|
2138
|
-
newArr[ii] = arr[ii + offset];
|
|
2139
|
-
}
|
|
2140
|
-
return newArr;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
function invariant(condition, error) {
|
|
2144
|
-
if (!condition)
|
|
2145
|
-
{ throw new Error(error); }
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
function assertNotInfinite(size) {
|
|
2149
|
-
invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
|
-
function coerceKeyPath(keyPath) {
|
|
2153
|
-
if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
|
|
2154
|
-
return keyPath;
|
|
2155
|
-
}
|
|
2156
|
-
if (isOrdered(keyPath)) {
|
|
2157
|
-
return keyPath.toArray();
|
|
2158
|
-
}
|
|
2159
|
-
throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
|
-
var toString = Object.prototype.toString;
|
|
2163
|
-
function isPlainObject(value) {
|
|
2164
|
-
// The base prototype's toString deals with Argument objects and native namespaces like Math
|
|
2165
|
-
if (!value ||
|
|
2166
|
-
typeof value !== 'object' ||
|
|
2167
|
-
toString.call(value) !== '[object Object]') {
|
|
2168
|
-
return false;
|
|
2169
|
-
}
|
|
2170
|
-
var proto = Object.getPrototypeOf(value);
|
|
2171
|
-
if (proto === null) {
|
|
2172
|
-
return true;
|
|
2173
|
-
}
|
|
2174
|
-
// Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
|
|
2175
|
-
var parentProto = proto;
|
|
2176
|
-
var nextProto = Object.getPrototypeOf(proto);
|
|
2177
|
-
while (nextProto !== null) {
|
|
2178
|
-
parentProto = nextProto;
|
|
2179
|
-
nextProto = Object.getPrototypeOf(parentProto);
|
|
2180
|
-
}
|
|
2181
|
-
return parentProto === proto;
|
|
2182
|
-
}
|
|
2183
|
-
|
|
2184
|
-
/**
|
|
2185
|
-
* Returns true if the value is a potentially-persistent data structure, either
|
|
2186
|
-
* provided by Immutable.js or a plain Array or Object.
|
|
2187
|
-
*/
|
|
2188
|
-
function isDataStructure(value) {
|
|
2189
|
-
return (typeof value === 'object' &&
|
|
2190
|
-
(isImmutable(value) || Array.isArray(value) || isPlainObject(value)));
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
2017
|
/**
|
|
2194
|
-
*
|
|
2018
|
+
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
|
|
2019
|
+
* and `hashCode()` methods.
|
|
2020
|
+
*
|
|
2021
|
+
* Any two instances of *value objects* can be compared for value equality with
|
|
2022
|
+
* `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
|
|
2195
2023
|
*/
|
|
2196
|
-
function
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
return JSON.stringify(value);
|
|
2203
|
-
}
|
|
2024
|
+
function isValueObject(maybeValue) {
|
|
2025
|
+
return Boolean(maybeValue &&
|
|
2026
|
+
// @ts-expect-error: maybeValue is typed as `{}`
|
|
2027
|
+
typeof maybeValue.equals === 'function' &&
|
|
2028
|
+
// @ts-expect-error: maybeValue is typed as `{}`
|
|
2029
|
+
typeof maybeValue.hashCode === 'function');
|
|
2204
2030
|
}
|
|
2205
2031
|
|
|
2206
2032
|
/**
|
|
2207
|
-
*
|
|
2033
|
+
* An extension of the "same-value" algorithm as [described for use by ES6 Map
|
|
2034
|
+
* and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
|
|
2208
2035
|
*
|
|
2209
|
-
*
|
|
2210
|
-
*
|
|
2211
|
-
* `
|
|
2036
|
+
* NaN is considered the same as NaN, however -0 and 0 are considered the same
|
|
2037
|
+
* value, which is different from the algorithm described by
|
|
2038
|
+
* [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
|
2212
2039
|
*
|
|
2213
|
-
*
|
|
2214
|
-
*
|
|
2215
|
-
* import { has } from 'immutable';
|
|
2040
|
+
* This is extended further to allow Objects to describe the values they
|
|
2041
|
+
* represent, by way of `valueOf` or `equals` (and `hashCode`).
|
|
2216
2042
|
*
|
|
2217
|
-
*
|
|
2218
|
-
*
|
|
2219
|
-
* has({ x: 123, y: 456 }, 'x') // true
|
|
2220
|
-
* has({ x: 123, y: 456 }, 'z') // false
|
|
2221
|
-
* ```
|
|
2222
|
-
*/
|
|
2223
|
-
function has(collection, key) {
|
|
2224
|
-
return isImmutable(collection)
|
|
2225
|
-
? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
|
|
2226
|
-
collection.has(key)
|
|
2227
|
-
: // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
|
|
2228
|
-
isDataStructure(collection) && hasOwnProperty.call(collection, key);
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
function get(collection, key, notSetValue) {
|
|
2232
|
-
return isImmutable(collection)
|
|
2233
|
-
? collection.get(key, notSetValue)
|
|
2234
|
-
: !has(collection, key)
|
|
2235
|
-
? notSetValue
|
|
2236
|
-
: // @ts-expect-error weird "get" here,
|
|
2237
|
-
typeof collection.get === 'function'
|
|
2238
|
-
? // @ts-expect-error weird "get" here,
|
|
2239
|
-
collection.get(key)
|
|
2240
|
-
: // @ts-expect-error key is unknown here,
|
|
2241
|
-
collection[key];
|
|
2242
|
-
}
|
|
2243
|
-
|
|
2244
|
-
function shallowCopy(from) {
|
|
2245
|
-
if (Array.isArray(from)) {
|
|
2246
|
-
return arrCopy(from);
|
|
2247
|
-
}
|
|
2248
|
-
var to = {};
|
|
2249
|
-
for (var key in from) {
|
|
2250
|
-
if (hasOwnProperty.call(from, key)) {
|
|
2251
|
-
to[key] = from[key];
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
return to;
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
function remove(collection, key) {
|
|
2258
|
-
if (!isDataStructure(collection)) {
|
|
2259
|
-
throw new TypeError('Cannot update non-data-structure value: ' + collection);
|
|
2260
|
-
}
|
|
2261
|
-
if (isImmutable(collection)) {
|
|
2262
|
-
// @ts-expect-error weird "remove" here,
|
|
2263
|
-
if (!collection.remove) {
|
|
2264
|
-
throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
|
|
2265
|
-
}
|
|
2266
|
-
// @ts-expect-error weird "remove" here,
|
|
2267
|
-
return collection.remove(key);
|
|
2268
|
-
}
|
|
2269
|
-
// @ts-expect-error assert that key is a string, a number or a symbol here
|
|
2270
|
-
if (!hasOwnProperty.call(collection, key)) {
|
|
2271
|
-
return collection;
|
|
2272
|
-
}
|
|
2273
|
-
var collectionCopy = shallowCopy(collection);
|
|
2274
|
-
if (Array.isArray(collectionCopy)) {
|
|
2275
|
-
// @ts-expect-error assert that key is a number here
|
|
2276
|
-
collectionCopy.splice(key, 1);
|
|
2277
|
-
}
|
|
2278
|
-
else {
|
|
2279
|
-
// @ts-expect-error assert that key is a string, a number or a symbol here
|
|
2280
|
-
delete collectionCopy[key];
|
|
2281
|
-
}
|
|
2282
|
-
return collectionCopy;
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
function set(collection, key, value) {
|
|
2286
|
-
if (!isDataStructure(collection)) {
|
|
2287
|
-
throw new TypeError('Cannot update non-data-structure value: ' + collection);
|
|
2288
|
-
}
|
|
2289
|
-
if (isImmutable(collection)) {
|
|
2290
|
-
// @ts-expect-error weird "set" here,
|
|
2291
|
-
if (!collection.set) {
|
|
2292
|
-
throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
|
|
2293
|
-
}
|
|
2294
|
-
// @ts-expect-error weird "set" here,
|
|
2295
|
-
return collection.set(key, value);
|
|
2296
|
-
}
|
|
2297
|
-
// @ts-expect-error mix of key and string here. Probably need a more fine type here
|
|
2298
|
-
if (hasOwnProperty.call(collection, key) && value === collection[key]) {
|
|
2299
|
-
return collection;
|
|
2300
|
-
}
|
|
2301
|
-
var collectionCopy = shallowCopy(collection);
|
|
2302
|
-
// @ts-expect-error mix of key and string here. Probably need a more fine type here
|
|
2303
|
-
collectionCopy[key] = value;
|
|
2304
|
-
return collectionCopy;
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2307
|
-
function updateIn$1(collection, keyPath, notSetValue, updater) {
|
|
2308
|
-
if (!updater) {
|
|
2309
|
-
// handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
|
|
2310
|
-
// @ts-expect-error updater is a function here
|
|
2311
|
-
updater = notSetValue;
|
|
2312
|
-
notSetValue = undefined;
|
|
2313
|
-
}
|
|
2314
|
-
var updatedValue = updateInDeeply(isImmutable(collection),
|
|
2315
|
-
// @ts-expect-error type issues with Record and mixed types
|
|
2316
|
-
collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
|
|
2317
|
-
// @ts-expect-error mixed return type
|
|
2318
|
-
return updatedValue === NOT_SET ? notSetValue : updatedValue;
|
|
2319
|
-
}
|
|
2320
|
-
function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
|
|
2321
|
-
var wasNotSet = existing === NOT_SET;
|
|
2322
|
-
if (i === keyPath.length) {
|
|
2323
|
-
var existingValue = wasNotSet ? notSetValue : existing;
|
|
2324
|
-
// @ts-expect-error mixed type with optional value
|
|
2325
|
-
var newValue = updater(existingValue);
|
|
2326
|
-
// @ts-expect-error mixed type
|
|
2327
|
-
return newValue === existingValue ? existing : newValue;
|
|
2328
|
-
}
|
|
2329
|
-
if (!wasNotSet && !isDataStructure(existing)) {
|
|
2330
|
-
throw new TypeError('Cannot update within non-data-structure value in path [' +
|
|
2331
|
-
Array.from(keyPath).slice(0, i).map(quoteString) +
|
|
2332
|
-
']: ' +
|
|
2333
|
-
existing);
|
|
2334
|
-
}
|
|
2335
|
-
var key = keyPath[i];
|
|
2336
|
-
var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
|
|
2337
|
-
var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
|
|
2338
|
-
// @ts-expect-error mixed type
|
|
2339
|
-
nextExisting, keyPath, i + 1, notSetValue, updater);
|
|
2340
|
-
return nextUpdated === nextExisting
|
|
2341
|
-
? existing
|
|
2342
|
-
: nextUpdated === NOT_SET
|
|
2343
|
-
? remove(existing, key)
|
|
2344
|
-
: set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
/**
|
|
2348
|
-
* Returns a copy of the collection with the value at the key path set to the
|
|
2349
|
-
* provided value.
|
|
2043
|
+
* Note: because of this extension, the key equality of Immutable.Map and the
|
|
2044
|
+
* value equality of Immutable.Set will differ from ES6 Map and Set.
|
|
2350
2045
|
*
|
|
2351
|
-
*
|
|
2352
|
-
* work with plain Objects and Arrays.
|
|
2046
|
+
* ### Defining custom values
|
|
2353
2047
|
*
|
|
2354
|
-
*
|
|
2355
|
-
*
|
|
2356
|
-
*
|
|
2048
|
+
* The easiest way to describe the value an object represents is by implementing
|
|
2049
|
+
* `valueOf`. For example, `Date` represents a value by returning a unix
|
|
2050
|
+
* timestamp for `valueOf`:
|
|
2357
2051
|
*
|
|
2358
|
-
*
|
|
2359
|
-
*
|
|
2360
|
-
*
|
|
2361
|
-
*
|
|
2362
|
-
|
|
2363
|
-
function setIn$1(collection, keyPath, value) {
|
|
2364
|
-
return updateIn$1(collection, keyPath, NOT_SET, function () { return value; });
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
function setIn(keyPath, v) {
|
|
2368
|
-
return setIn$1(this, keyPath, v);
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
/**
|
|
2372
|
-
* Returns a copy of the collection with the value at the key path removed.
|
|
2052
|
+
* var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
|
|
2053
|
+
* var date2 = new Date(1234567890000);
|
|
2054
|
+
* date1.valueOf(); // 1234567890000
|
|
2055
|
+
* assert( date1 !== date2 );
|
|
2056
|
+
* assert( Immutable.is( date1, date2 ) );
|
|
2373
2057
|
*
|
|
2374
|
-
*
|
|
2375
|
-
*
|
|
2058
|
+
* Note: overriding `valueOf` may have other implications if you use this object
|
|
2059
|
+
* where JavaScript expects a primitive, such as implicit string coercion.
|
|
2376
2060
|
*
|
|
2377
|
-
*
|
|
2378
|
-
*
|
|
2379
|
-
* import { removeIn } from 'immutable';
|
|
2061
|
+
* For more complex types, especially collections, implementing `valueOf` may
|
|
2062
|
+
* not be performant. An alternative is to implement `equals` and `hashCode`.
|
|
2380
2063
|
*
|
|
2381
|
-
*
|
|
2382
|
-
*
|
|
2383
|
-
*
|
|
2384
|
-
*
|
|
2064
|
+
* `equals` takes another object, presumably of similar type, and returns true
|
|
2065
|
+
* if it is equal. Equality is symmetrical, so the same result should be
|
|
2066
|
+
* returned if this and the argument are flipped.
|
|
2067
|
+
*
|
|
2068
|
+
* assert( a.equals(b) === b.equals(a) );
|
|
2069
|
+
*
|
|
2070
|
+
* `hashCode` returns a 32bit integer number representing the object which will
|
|
2071
|
+
* be used to determine how to store the value object in a Map or Set. You must
|
|
2072
|
+
* provide both or neither methods, one must not exist without the other.
|
|
2073
|
+
*
|
|
2074
|
+
* Also, an important relationship between these methods must be upheld: if two
|
|
2075
|
+
* values are equal, they *must* return the same hashCode. If the values are not
|
|
2076
|
+
* equal, they might have the same hashCode; this is called a hash collision,
|
|
2077
|
+
* and while undesirable for performance reasons, it is acceptable.
|
|
2078
|
+
*
|
|
2079
|
+
* if (a.equals(b)) {
|
|
2080
|
+
* assert( a.hashCode() === b.hashCode() );
|
|
2081
|
+
* }
|
|
2082
|
+
*
|
|
2083
|
+
* All Immutable collections are Value Objects: they implement `equals()`
|
|
2084
|
+
* and `hashCode()`.
|
|
2385
2085
|
*/
|
|
2386
|
-
function
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2086
|
+
function is(valueA, valueB) {
|
|
2087
|
+
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
2088
|
+
return true;
|
|
2089
|
+
}
|
|
2090
|
+
if (!valueA || !valueB) {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
2093
|
+
if (typeof valueA.valueOf === 'function' &&
|
|
2094
|
+
typeof valueB.valueOf === 'function') {
|
|
2095
|
+
valueA = valueA.valueOf();
|
|
2096
|
+
valueB = valueB.valueOf();
|
|
2097
|
+
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
|
2098
|
+
return true;
|
|
2099
|
+
}
|
|
2100
|
+
if (!valueA || !valueB) {
|
|
2101
|
+
return false;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
return !!(isValueObject(valueA) &&
|
|
2105
|
+
isValueObject(valueB) &&
|
|
2106
|
+
valueA.equals(valueB));
|
|
2404
2107
|
}
|
|
2405
2108
|
|
|
2406
|
-
function
|
|
2407
|
-
|
|
2109
|
+
function update$1(collection, key, notSetValue, updater) {
|
|
2110
|
+
return updateIn(
|
|
2111
|
+
// @ts-expect-error Index signature for type string is missing in type V[]
|
|
2112
|
+
collection, [key], notSetValue, updater);
|
|
2408
2113
|
}
|
|
2409
2114
|
|
|
2410
2115
|
function merge$1() {
|
|
@@ -2459,6 +2164,62 @@
|
|
|
2459
2164
|
});
|
|
2460
2165
|
}
|
|
2461
2166
|
|
|
2167
|
+
var toString = Object.prototype.toString;
|
|
2168
|
+
function isPlainObject(value) {
|
|
2169
|
+
// The base prototype's toString deals with Argument objects and native namespaces like Math
|
|
2170
|
+
if (!value ||
|
|
2171
|
+
typeof value !== 'object' ||
|
|
2172
|
+
toString.call(value) !== '[object Object]') {
|
|
2173
|
+
return false;
|
|
2174
|
+
}
|
|
2175
|
+
var proto = Object.getPrototypeOf(value);
|
|
2176
|
+
if (proto === null) {
|
|
2177
|
+
return true;
|
|
2178
|
+
}
|
|
2179
|
+
// Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
|
|
2180
|
+
var parentProto = proto;
|
|
2181
|
+
var nextProto = Object.getPrototypeOf(proto);
|
|
2182
|
+
while (nextProto !== null) {
|
|
2183
|
+
parentProto = nextProto;
|
|
2184
|
+
nextProto = Object.getPrototypeOf(parentProto);
|
|
2185
|
+
}
|
|
2186
|
+
return parentProto === proto;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Returns true if the value is a potentially-persistent data structure, either
|
|
2191
|
+
* provided by Immutable.js or a plain Array or Object.
|
|
2192
|
+
*/
|
|
2193
|
+
function isDataStructure(value) {
|
|
2194
|
+
return (typeof value === 'object' &&
|
|
2195
|
+
(isImmutable(value) || Array.isArray(value) || isPlainObject(value)));
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// http://jsperf.com/copy-array-inline
|
|
2199
|
+
function arrCopy(arr, offset) {
|
|
2200
|
+
offset = offset || 0;
|
|
2201
|
+
var len = Math.max(0, arr.length - offset);
|
|
2202
|
+
var newArr = new Array(len);
|
|
2203
|
+
for (var ii = 0; ii < len; ii++) {
|
|
2204
|
+
// @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
|
|
2205
|
+
newArr[ii] = arr[ii + offset];
|
|
2206
|
+
}
|
|
2207
|
+
return newArr;
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
function shallowCopy(from) {
|
|
2211
|
+
if (Array.isArray(from)) {
|
|
2212
|
+
return arrCopy(from);
|
|
2213
|
+
}
|
|
2214
|
+
var to = {};
|
|
2215
|
+
for (var key in from) {
|
|
2216
|
+
if (hasOwnProperty.call(from, key)) {
|
|
2217
|
+
to[key] = from[key];
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
return to;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2462
2223
|
function merge(collection) {
|
|
2463
2224
|
var sources = [], len = arguments.length - 1;
|
|
2464
2225
|
while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
|
|
@@ -2576,19 +2337,48 @@
|
|
|
2576
2337
|
return mergeDeepWithSources(this, iters, merger);
|
|
2577
2338
|
}
|
|
2578
2339
|
|
|
2579
|
-
function
|
|
2340
|
+
function mergeDeepIn(keyPath) {
|
|
2580
2341
|
var iters = [], len = arguments.length - 1;
|
|
2581
2342
|
while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
|
|
2582
2343
|
|
|
2583
|
-
return updateIn
|
|
2344
|
+
return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
|
|
2345
|
+
);
|
|
2584
2346
|
}
|
|
2585
2347
|
|
|
2586
|
-
function
|
|
2348
|
+
function mergeIn(keyPath) {
|
|
2587
2349
|
var iters = [], len = arguments.length - 1;
|
|
2588
2350
|
while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
|
|
2589
2351
|
|
|
2590
|
-
return updateIn
|
|
2591
|
-
|
|
2352
|
+
return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
/**
|
|
2356
|
+
* Returns a copy of the collection with the value at the key path set to the
|
|
2357
|
+
* provided value.
|
|
2358
|
+
*
|
|
2359
|
+
* A functional alternative to `collection.setIn(keypath)` which will also
|
|
2360
|
+
* work with plain Objects and Arrays.
|
|
2361
|
+
*/
|
|
2362
|
+
function setIn$1(collection, keyPath, value) {
|
|
2363
|
+
return updateIn(collection, keyPath, NOT_SET, function () { return value; });
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
function setIn(keyPath, v) {
|
|
2367
|
+
return setIn$1(this, keyPath, v);
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
function update(key, notSetValue, updater) {
|
|
2371
|
+
return arguments.length === 1
|
|
2372
|
+
? key(this)
|
|
2373
|
+
: update$1(this, key, notSetValue, updater);
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
function updateIn$1(keyPath, notSetValue, updater) {
|
|
2377
|
+
return updateIn(this, keyPath, notSetValue, updater);
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
function wasAltered() {
|
|
2381
|
+
return this.__altered;
|
|
2592
2382
|
}
|
|
2593
2383
|
|
|
2594
2384
|
function withMutations(fn) {
|
|
@@ -2597,16 +2387,25 @@
|
|
|
2597
2387
|
return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
|
|
2598
2388
|
}
|
|
2599
2389
|
|
|
2600
|
-
|
|
2601
|
-
|
|
2390
|
+
var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
|
|
2391
|
+
/**
|
|
2392
|
+
* True if `maybeMap` is a Map.
|
|
2393
|
+
*
|
|
2394
|
+
* Also true for OrderedMaps.
|
|
2395
|
+
*/
|
|
2396
|
+
function isMap(maybeMap) {
|
|
2397
|
+
return Boolean(maybeMap &&
|
|
2398
|
+
// @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
|
|
2399
|
+
maybeMap[IS_MAP_SYMBOL]);
|
|
2602
2400
|
}
|
|
2603
2401
|
|
|
2604
|
-
function
|
|
2605
|
-
|
|
2402
|
+
function invariant(condition, error) {
|
|
2403
|
+
if (!condition)
|
|
2404
|
+
{ throw new Error(error); }
|
|
2606
2405
|
}
|
|
2607
2406
|
|
|
2608
|
-
function
|
|
2609
|
-
|
|
2407
|
+
function assertNotInfinite(size) {
|
|
2408
|
+
invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
|
|
2610
2409
|
}
|
|
2611
2410
|
|
|
2612
2411
|
var Map = /*@__PURE__*/(function (KeyedCollection) {
|
|
@@ -2743,7 +2542,7 @@
|
|
|
2743
2542
|
MapPrototype.setIn = setIn;
|
|
2744
2543
|
MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
|
|
2745
2544
|
MapPrototype.update = update;
|
|
2746
|
-
MapPrototype.updateIn = updateIn;
|
|
2545
|
+
MapPrototype.updateIn = updateIn$1;
|
|
2747
2546
|
MapPrototype.merge = MapPrototype.concat = merge$1;
|
|
2748
2547
|
MapPrototype.mergeWith = mergeWith$1;
|
|
2749
2548
|
MapPrototype.mergeDeep = mergeDeep;
|
|
@@ -3345,45 +3144,200 @@
|
|
|
3345
3144
|
return newArray;
|
|
3346
3145
|
}
|
|
3347
3146
|
|
|
3348
|
-
function spliceIn(array, idx, val, canEdit) {
|
|
3349
|
-
var newLen = array.length + 1;
|
|
3350
|
-
if (canEdit && idx + 1 === newLen) {
|
|
3351
|
-
array[idx] = val;
|
|
3352
|
-
return array;
|
|
3353
|
-
}
|
|
3354
|
-
var newArray = new Array(newLen);
|
|
3355
|
-
var after = 0;
|
|
3356
|
-
for (var ii = 0; ii < newLen; ii++) {
|
|
3357
|
-
if (ii === idx) {
|
|
3358
|
-
newArray[ii] = val;
|
|
3359
|
-
after = -1;
|
|
3360
|
-
} else {
|
|
3361
|
-
newArray[ii] = array[ii + after];
|
|
3147
|
+
function spliceIn(array, idx, val, canEdit) {
|
|
3148
|
+
var newLen = array.length + 1;
|
|
3149
|
+
if (canEdit && idx + 1 === newLen) {
|
|
3150
|
+
array[idx] = val;
|
|
3151
|
+
return array;
|
|
3152
|
+
}
|
|
3153
|
+
var newArray = new Array(newLen);
|
|
3154
|
+
var after = 0;
|
|
3155
|
+
for (var ii = 0; ii < newLen; ii++) {
|
|
3156
|
+
if (ii === idx) {
|
|
3157
|
+
newArray[ii] = val;
|
|
3158
|
+
after = -1;
|
|
3159
|
+
} else {
|
|
3160
|
+
newArray[ii] = array[ii + after];
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
return newArray;
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
function spliceOut(array, idx, canEdit) {
|
|
3167
|
+
var newLen = array.length - 1;
|
|
3168
|
+
if (canEdit && idx === newLen) {
|
|
3169
|
+
array.pop();
|
|
3170
|
+
return array;
|
|
3171
|
+
}
|
|
3172
|
+
var newArray = new Array(newLen);
|
|
3173
|
+
var after = 0;
|
|
3174
|
+
for (var ii = 0; ii < newLen; ii++) {
|
|
3175
|
+
if (ii === idx) {
|
|
3176
|
+
after = 1;
|
|
3177
|
+
}
|
|
3178
|
+
newArray[ii] = array[ii + after];
|
|
3179
|
+
}
|
|
3180
|
+
return newArray;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
var MAX_ARRAY_MAP_SIZE = SIZE / 4;
|
|
3184
|
+
var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
|
|
3185
|
+
var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
|
|
3186
|
+
|
|
3187
|
+
function coerceKeyPath(keyPath) {
|
|
3188
|
+
if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
|
|
3189
|
+
return keyPath;
|
|
3190
|
+
}
|
|
3191
|
+
if (isOrdered(keyPath)) {
|
|
3192
|
+
return keyPath.toArray();
|
|
3193
|
+
}
|
|
3194
|
+
throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
/**
|
|
3198
|
+
* Converts a value to a string, adding quotes if a string was provided.
|
|
3199
|
+
*/
|
|
3200
|
+
function quoteString(value) {
|
|
3201
|
+
try {
|
|
3202
|
+
return typeof value === 'string' ? JSON.stringify(value) : String(value);
|
|
3203
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3204
|
+
}
|
|
3205
|
+
catch (_ignoreError) {
|
|
3206
|
+
return JSON.stringify(value);
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
|
|
3210
|
+
/**
|
|
3211
|
+
* Returns true if the key is defined in the provided collection.
|
|
3212
|
+
*
|
|
3213
|
+
* A functional alternative to `collection.has(key)` which will also work with
|
|
3214
|
+
* plain Objects and Arrays as an alternative for
|
|
3215
|
+
* `collection.hasOwnProperty(key)`.
|
|
3216
|
+
*/
|
|
3217
|
+
function has(collection, key) {
|
|
3218
|
+
return isImmutable(collection)
|
|
3219
|
+
? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
|
|
3220
|
+
collection.has(key)
|
|
3221
|
+
: // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
|
|
3222
|
+
isDataStructure(collection) && hasOwnProperty.call(collection, key);
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
function get(collection, key, notSetValue) {
|
|
3226
|
+
return isImmutable(collection)
|
|
3227
|
+
? collection.get(key, notSetValue)
|
|
3228
|
+
: !has(collection, key)
|
|
3229
|
+
? notSetValue
|
|
3230
|
+
: // @ts-expect-error weird "get" here,
|
|
3231
|
+
typeof collection.get === 'function'
|
|
3232
|
+
? // @ts-expect-error weird "get" here,
|
|
3233
|
+
collection.get(key)
|
|
3234
|
+
: // @ts-expect-error key is unknown here,
|
|
3235
|
+
collection[key];
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
function remove(collection, key) {
|
|
3239
|
+
if (!isDataStructure(collection)) {
|
|
3240
|
+
throw new TypeError('Cannot update non-data-structure value: ' + collection);
|
|
3241
|
+
}
|
|
3242
|
+
if (isImmutable(collection)) {
|
|
3243
|
+
// @ts-expect-error weird "remove" here,
|
|
3244
|
+
if (!collection.remove) {
|
|
3245
|
+
throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
|
|
3246
|
+
}
|
|
3247
|
+
// @ts-expect-error weird "remove" here,
|
|
3248
|
+
return collection.remove(key);
|
|
3249
|
+
}
|
|
3250
|
+
// @ts-expect-error assert that key is a string, a number or a symbol here
|
|
3251
|
+
if (!hasOwnProperty.call(collection, key)) {
|
|
3252
|
+
return collection;
|
|
3253
|
+
}
|
|
3254
|
+
var collectionCopy = shallowCopy(collection);
|
|
3255
|
+
if (Array.isArray(collectionCopy)) {
|
|
3256
|
+
// @ts-expect-error assert that key is a number here
|
|
3257
|
+
collectionCopy.splice(key, 1);
|
|
3258
|
+
}
|
|
3259
|
+
else {
|
|
3260
|
+
// @ts-expect-error assert that key is a string, a number or a symbol here
|
|
3261
|
+
delete collectionCopy[key];
|
|
3262
|
+
}
|
|
3263
|
+
return collectionCopy;
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
function set(collection, key, value) {
|
|
3267
|
+
if (!isDataStructure(collection)) {
|
|
3268
|
+
throw new TypeError('Cannot update non-data-structure value: ' + collection);
|
|
3269
|
+
}
|
|
3270
|
+
if (isImmutable(collection)) {
|
|
3271
|
+
// @ts-expect-error weird "set" here,
|
|
3272
|
+
if (!collection.set) {
|
|
3273
|
+
throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
|
|
3274
|
+
}
|
|
3275
|
+
// @ts-expect-error weird "set" here,
|
|
3276
|
+
return collection.set(key, value);
|
|
3277
|
+
}
|
|
3278
|
+
// @ts-expect-error mix of key and string here. Probably need a more fine type here
|
|
3279
|
+
if (hasOwnProperty.call(collection, key) && value === collection[key]) {
|
|
3280
|
+
return collection;
|
|
3281
|
+
}
|
|
3282
|
+
var collectionCopy = shallowCopy(collection);
|
|
3283
|
+
// @ts-expect-error mix of key and string here. Probably need a more fine type here
|
|
3284
|
+
collectionCopy[key] = value;
|
|
3285
|
+
return collectionCopy;
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
function updateIn(collection, keyPath, notSetValue, updater) {
|
|
3289
|
+
if (!updater) {
|
|
3290
|
+
// handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
|
|
3291
|
+
// @ts-expect-error updater is a function here
|
|
3292
|
+
updater = notSetValue;
|
|
3293
|
+
notSetValue = undefined;
|
|
3362
3294
|
}
|
|
3363
|
-
|
|
3364
|
-
|
|
3295
|
+
var updatedValue = updateInDeeply(isImmutable(collection),
|
|
3296
|
+
// @ts-expect-error type issues with Record and mixed types
|
|
3297
|
+
collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
|
|
3298
|
+
// @ts-expect-error mixed return type
|
|
3299
|
+
return updatedValue === NOT_SET ? notSetValue : updatedValue;
|
|
3365
3300
|
}
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
var after = 0;
|
|
3375
|
-
for (var ii = 0; ii < newLen; ii++) {
|
|
3376
|
-
if (ii === idx) {
|
|
3377
|
-
after = 1;
|
|
3301
|
+
function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
|
|
3302
|
+
var wasNotSet = existing === NOT_SET;
|
|
3303
|
+
if (i === keyPath.length) {
|
|
3304
|
+
var existingValue = wasNotSet ? notSetValue : existing;
|
|
3305
|
+
// @ts-expect-error mixed type with optional value
|
|
3306
|
+
var newValue = updater(existingValue);
|
|
3307
|
+
// @ts-expect-error mixed type
|
|
3308
|
+
return newValue === existingValue ? existing : newValue;
|
|
3378
3309
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3310
|
+
if (!wasNotSet && !isDataStructure(existing)) {
|
|
3311
|
+
throw new TypeError('Cannot update within non-data-structure value in path [' +
|
|
3312
|
+
Array.from(keyPath).slice(0, i).map(quoteString) +
|
|
3313
|
+
']: ' +
|
|
3314
|
+
existing);
|
|
3315
|
+
}
|
|
3316
|
+
var key = keyPath[i];
|
|
3317
|
+
var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
|
|
3318
|
+
var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
|
|
3319
|
+
// @ts-expect-error mixed type
|
|
3320
|
+
nextExisting, keyPath, i + 1, notSetValue, updater);
|
|
3321
|
+
return nextUpdated === nextExisting
|
|
3322
|
+
? existing
|
|
3323
|
+
: nextUpdated === NOT_SET
|
|
3324
|
+
? remove(existing, key)
|
|
3325
|
+
: set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
|
|
3382
3326
|
}
|
|
3383
3327
|
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3328
|
+
/**
|
|
3329
|
+
* Returns a copy of the collection with the value at the key path removed.
|
|
3330
|
+
*
|
|
3331
|
+
* A functional alternative to `collection.removeIn(keypath)` which will also
|
|
3332
|
+
* work with plain Objects and Arrays.
|
|
3333
|
+
*/
|
|
3334
|
+
function removeIn(collection, keyPath) {
|
|
3335
|
+
return updateIn(collection, keyPath, function () { return NOT_SET; });
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
function deleteIn(keyPath) {
|
|
3339
|
+
return removeIn(this, keyPath);
|
|
3340
|
+
}
|
|
3387
3341
|
|
|
3388
3342
|
var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
|
|
3389
3343
|
/**
|
|
@@ -3644,7 +3598,7 @@
|
|
|
3644
3598
|
ListPrototype.setIn = setIn;
|
|
3645
3599
|
ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
|
|
3646
3600
|
ListPrototype.update = update;
|
|
3647
|
-
ListPrototype.updateIn = updateIn;
|
|
3601
|
+
ListPrototype.updateIn = updateIn$1;
|
|
3648
3602
|
ListPrototype.mergeIn = mergeIn;
|
|
3649
3603
|
ListPrototype.mergeDeepIn = mergeDeepIn;
|
|
3650
3604
|
ListPrototype.withMutations = withMutations;
|
|
@@ -4076,6 +4030,13 @@
|
|
|
4076
4030
|
return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
|
|
4077
4031
|
}
|
|
4078
4032
|
|
|
4033
|
+
/**
|
|
4034
|
+
* True if `maybeOrderedMap` is an OrderedMap.
|
|
4035
|
+
*/
|
|
4036
|
+
function isOrderedMap(maybeOrderedMap) {
|
|
4037
|
+
return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
|
|
4038
|
+
}
|
|
4039
|
+
|
|
4079
4040
|
var OrderedMap = /*@__PURE__*/(function (Map) {
|
|
4080
4041
|
function OrderedMap(value) {
|
|
4081
4042
|
// eslint-disable-next-line no-constructor-return
|
|
@@ -4474,23 +4435,45 @@
|
|
|
4474
4435
|
return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
|
|
4475
4436
|
}
|
|
4476
4437
|
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4438
|
+
function reduce(collection, reducer, reduction, context, useFirst, reverse) {
|
|
4439
|
+
// @ts-expect-error Migrate to CollectionImpl in v6
|
|
4440
|
+
assertNotInfinite(collection.size);
|
|
4441
|
+
// @ts-expect-error Migrate to CollectionImpl in v6
|
|
4442
|
+
collection.__iterate(function (v, k, c) {
|
|
4443
|
+
if (useFirst) {
|
|
4444
|
+
useFirst = false;
|
|
4445
|
+
reduction = v;
|
|
4446
|
+
}
|
|
4447
|
+
else {
|
|
4448
|
+
reduction = reducer.call(context, reduction, v, k, c);
|
|
4449
|
+
}
|
|
4450
|
+
}, reverse);
|
|
4451
|
+
return reduction;
|
|
4487
4452
|
}
|
|
4453
|
+
function keyMapper(v, k) {
|
|
4454
|
+
return k;
|
|
4455
|
+
}
|
|
4456
|
+
function entryMapper(v, k) {
|
|
4457
|
+
return [k, v];
|
|
4458
|
+
}
|
|
4459
|
+
function not(predicate) {
|
|
4460
|
+
return function () {
|
|
4461
|
+
var args = [], len = arguments.length;
|
|
4462
|
+
while ( len-- ) args[ len ] = arguments[ len ];
|
|
4488
4463
|
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
function
|
|
4493
|
-
return
|
|
4464
|
+
return !predicate.apply(this, args);
|
|
4465
|
+
};
|
|
4466
|
+
}
|
|
4467
|
+
function neg(predicate) {
|
|
4468
|
+
return function () {
|
|
4469
|
+
var args = [], len = arguments.length;
|
|
4470
|
+
while ( len-- ) args[ len ] = arguments[ len ];
|
|
4471
|
+
|
|
4472
|
+
return -predicate.apply(this, args);
|
|
4473
|
+
};
|
|
4474
|
+
}
|
|
4475
|
+
function defaultNegComparator(a, b) {
|
|
4476
|
+
return a < b ? 1 : a > b ? -1 : 0;
|
|
4494
4477
|
}
|
|
4495
4478
|
|
|
4496
4479
|
function deepEqual(a, b) {
|
|
@@ -4563,44 +4546,154 @@
|
|
|
4563
4546
|
}
|
|
4564
4547
|
|
|
4565
4548
|
/**
|
|
4566
|
-
*
|
|
4549
|
+
* Returns a lazy seq of nums from start (inclusive) to end
|
|
4550
|
+
* (exclusive), by step, where start defaults to 0, step to 1, and end to
|
|
4551
|
+
* infinity. When start is equal to end, returns empty list.
|
|
4567
4552
|
*/
|
|
4568
|
-
function
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
var keyCopier = function (key) {
|
|
4572
|
-
// @ts-expect-error how to handle symbol ?
|
|
4573
|
-
ctor.prototype[key] = methods[key];
|
|
4574
|
-
};
|
|
4575
|
-
Object.keys(methods).forEach(keyCopier);
|
|
4576
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
4577
|
-
Object.getOwnPropertySymbols &&
|
|
4578
|
-
Object.getOwnPropertySymbols(methods).forEach(keyCopier);
|
|
4579
|
-
return ctor;
|
|
4580
|
-
}
|
|
4553
|
+
var Range = /*@__PURE__*/(function (IndexedSeq) {
|
|
4554
|
+
function Range(start, end, step) {
|
|
4555
|
+
if ( step === void 0 ) step = 1;
|
|
4581
4556
|
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4557
|
+
if (!(this instanceof Range)) {
|
|
4558
|
+
// eslint-disable-next-line no-constructor-return
|
|
4559
|
+
return new Range(start, end, step);
|
|
4560
|
+
}
|
|
4561
|
+
invariant(step !== 0, 'Cannot step a Range by 0');
|
|
4562
|
+
invariant(
|
|
4563
|
+
start !== undefined,
|
|
4564
|
+
'You must define a start value when using Range'
|
|
4565
|
+
);
|
|
4566
|
+
invariant(
|
|
4567
|
+
end !== undefined,
|
|
4568
|
+
'You must define an end value when using Range'
|
|
4569
|
+
);
|
|
4570
|
+
|
|
4571
|
+
step = Math.abs(step);
|
|
4572
|
+
if (end < start) {
|
|
4573
|
+
step = -step;
|
|
4574
|
+
}
|
|
4575
|
+
this._start = start;
|
|
4576
|
+
this._end = end;
|
|
4577
|
+
this._step = step;
|
|
4578
|
+
this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
|
|
4579
|
+
if (this.size === 0) {
|
|
4580
|
+
if (EMPTY_RANGE) {
|
|
4581
|
+
// eslint-disable-next-line no-constructor-return
|
|
4582
|
+
return EMPTY_RANGE;
|
|
4583
|
+
}
|
|
4584
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
4585
|
+
EMPTY_RANGE = this;
|
|
4589
4586
|
}
|
|
4590
|
-
value = Seq(value);
|
|
4591
4587
|
}
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4588
|
+
|
|
4589
|
+
if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
|
|
4590
|
+
Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
|
|
4591
|
+
Range.prototype.constructor = Range;
|
|
4592
|
+
|
|
4593
|
+
Range.prototype.toString = function toString () {
|
|
4594
|
+
return this.size === 0
|
|
4595
|
+
? 'Range []'
|
|
4596
|
+
: ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
|
|
4597
|
+
};
|
|
4598
|
+
|
|
4599
|
+
Range.prototype.get = function get (index, notSetValue) {
|
|
4600
|
+
return this.has(index)
|
|
4601
|
+
? this._start + wrapIndex(this, index) * this._step
|
|
4602
|
+
: notSetValue;
|
|
4603
|
+
};
|
|
4604
|
+
|
|
4605
|
+
Range.prototype.includes = function includes (searchValue) {
|
|
4606
|
+
var possibleIndex = (searchValue - this._start) / this._step;
|
|
4607
|
+
return (
|
|
4608
|
+
possibleIndex >= 0 &&
|
|
4609
|
+
possibleIndex < this.size &&
|
|
4610
|
+
possibleIndex === Math.floor(possibleIndex)
|
|
4611
|
+
);
|
|
4612
|
+
};
|
|
4613
|
+
|
|
4614
|
+
Range.prototype.slice = function slice (begin, end) {
|
|
4615
|
+
if (wholeSlice(begin, end, this.size)) {
|
|
4616
|
+
return this;
|
|
4617
|
+
}
|
|
4618
|
+
begin = resolveBegin(begin, this.size);
|
|
4619
|
+
end = resolveEnd(end, this.size);
|
|
4620
|
+
if (end <= begin) {
|
|
4621
|
+
return new Range(0, 0);
|
|
4622
|
+
}
|
|
4623
|
+
return new Range(
|
|
4624
|
+
this.get(begin, this._end),
|
|
4625
|
+
this.get(end, this._end),
|
|
4626
|
+
this._step
|
|
4627
|
+
);
|
|
4628
|
+
};
|
|
4629
|
+
|
|
4630
|
+
Range.prototype.indexOf = function indexOf (searchValue) {
|
|
4631
|
+
var offsetValue = searchValue - this._start;
|
|
4632
|
+
if (offsetValue % this._step === 0) {
|
|
4633
|
+
var index = offsetValue / this._step;
|
|
4634
|
+
if (index >= 0 && index < this.size) {
|
|
4635
|
+
return index;
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
return -1;
|
|
4639
|
+
};
|
|
4640
|
+
|
|
4641
|
+
Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
|
|
4642
|
+
return this.indexOf(searchValue);
|
|
4643
|
+
};
|
|
4644
|
+
|
|
4645
|
+
Range.prototype.__iterate = function __iterate (fn, reverse) {
|
|
4646
|
+
var size = this.size;
|
|
4647
|
+
var step = this._step;
|
|
4648
|
+
var value = reverse ? this._start + (size - 1) * step : this._start;
|
|
4649
|
+
var i = 0;
|
|
4650
|
+
while (i !== size) {
|
|
4651
|
+
if (fn(value, reverse ? size - ++i : i++, this) === false) {
|
|
4652
|
+
break;
|
|
4653
|
+
}
|
|
4654
|
+
value += reverse ? -step : step;
|
|
4655
|
+
}
|
|
4656
|
+
return i;
|
|
4657
|
+
};
|
|
4658
|
+
|
|
4659
|
+
Range.prototype.__iterator = function __iterator (type, reverse) {
|
|
4660
|
+
var size = this.size;
|
|
4661
|
+
var step = this._step;
|
|
4662
|
+
var value = reverse ? this._start + (size - 1) * step : this._start;
|
|
4663
|
+
var i = 0;
|
|
4664
|
+
return new Iterator(function () {
|
|
4665
|
+
if (i === size) {
|
|
4666
|
+
return iteratorDone();
|
|
4667
|
+
}
|
|
4668
|
+
var v = value;
|
|
4669
|
+
value += reverse ? -step : step;
|
|
4670
|
+
return iteratorValue(type, reverse ? size - ++i : i++, v);
|
|
4596
4671
|
});
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4672
|
+
};
|
|
4673
|
+
|
|
4674
|
+
Range.prototype.equals = function equals (other) {
|
|
4675
|
+
return other instanceof Range
|
|
4676
|
+
? this._start === other._start &&
|
|
4677
|
+
this._end === other._end &&
|
|
4678
|
+
this._step === other._step
|
|
4679
|
+
: deepEqual(this, other);
|
|
4680
|
+
};
|
|
4681
|
+
|
|
4682
|
+
return Range;
|
|
4683
|
+
}(IndexedSeq));
|
|
4684
|
+
|
|
4685
|
+
var EMPTY_RANGE;
|
|
4686
|
+
|
|
4687
|
+
var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
|
|
4688
|
+
/**
|
|
4689
|
+
* True if `maybeSet` is a Set.
|
|
4690
|
+
*
|
|
4691
|
+
* Also true for OrderedSets.
|
|
4692
|
+
*/
|
|
4693
|
+
function isSet(maybeSet) {
|
|
4694
|
+
return Boolean(maybeSet &&
|
|
4695
|
+
// @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
|
|
4696
|
+
maybeSet[IS_SET_SYMBOL]);
|
|
4604
4697
|
}
|
|
4605
4698
|
|
|
4606
4699
|
var Set = /*@__PURE__*/(function (SetCollection) {
|
|
@@ -4845,159 +4938,12 @@
|
|
|
4845
4938
|
return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
|
|
4846
4939
|
}
|
|
4847
4940
|
|
|
4848
|
-
/**
|
|
4849
|
-
* Returns a lazy seq of nums from start (inclusive) to end
|
|
4850
|
-
* (exclusive), by step, where start defaults to 0, step to 1, and end to
|
|
4851
|
-
* infinity. When start is equal to end, returns empty list.
|
|
4852
|
-
*/
|
|
4853
|
-
var Range = /*@__PURE__*/(function (IndexedSeq) {
|
|
4854
|
-
function Range(start, end, step) {
|
|
4855
|
-
if ( step === void 0 ) step = 1;
|
|
4856
|
-
|
|
4857
|
-
if (!(this instanceof Range)) {
|
|
4858
|
-
// eslint-disable-next-line no-constructor-return
|
|
4859
|
-
return new Range(start, end, step);
|
|
4860
|
-
}
|
|
4861
|
-
invariant(step !== 0, 'Cannot step a Range by 0');
|
|
4862
|
-
invariant(
|
|
4863
|
-
start !== undefined,
|
|
4864
|
-
'You must define a start value when using Range'
|
|
4865
|
-
);
|
|
4866
|
-
invariant(
|
|
4867
|
-
end !== undefined,
|
|
4868
|
-
'You must define an end value when using Range'
|
|
4869
|
-
);
|
|
4870
|
-
|
|
4871
|
-
step = Math.abs(step);
|
|
4872
|
-
if (end < start) {
|
|
4873
|
-
step = -step;
|
|
4874
|
-
}
|
|
4875
|
-
this._start = start;
|
|
4876
|
-
this._end = end;
|
|
4877
|
-
this._step = step;
|
|
4878
|
-
this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
|
|
4879
|
-
if (this.size === 0) {
|
|
4880
|
-
if (EMPTY_RANGE) {
|
|
4881
|
-
// eslint-disable-next-line no-constructor-return
|
|
4882
|
-
return EMPTY_RANGE;
|
|
4883
|
-
}
|
|
4884
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
4885
|
-
EMPTY_RANGE = this;
|
|
4886
|
-
}
|
|
4887
|
-
}
|
|
4888
|
-
|
|
4889
|
-
if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
|
|
4890
|
-
Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
|
|
4891
|
-
Range.prototype.constructor = Range;
|
|
4892
|
-
|
|
4893
|
-
Range.prototype.toString = function toString () {
|
|
4894
|
-
return this.size === 0
|
|
4895
|
-
? 'Range []'
|
|
4896
|
-
: ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
|
|
4897
|
-
};
|
|
4898
|
-
|
|
4899
|
-
Range.prototype.get = function get (index, notSetValue) {
|
|
4900
|
-
return this.has(index)
|
|
4901
|
-
? this._start + wrapIndex(this, index) * this._step
|
|
4902
|
-
: notSetValue;
|
|
4903
|
-
};
|
|
4904
|
-
|
|
4905
|
-
Range.prototype.includes = function includes (searchValue) {
|
|
4906
|
-
var possibleIndex = (searchValue - this._start) / this._step;
|
|
4907
|
-
return (
|
|
4908
|
-
possibleIndex >= 0 &&
|
|
4909
|
-
possibleIndex < this.size &&
|
|
4910
|
-
possibleIndex === Math.floor(possibleIndex)
|
|
4911
|
-
);
|
|
4912
|
-
};
|
|
4913
|
-
|
|
4914
|
-
Range.prototype.slice = function slice (begin, end) {
|
|
4915
|
-
if (wholeSlice(begin, end, this.size)) {
|
|
4916
|
-
return this;
|
|
4917
|
-
}
|
|
4918
|
-
begin = resolveBegin(begin, this.size);
|
|
4919
|
-
end = resolveEnd(end, this.size);
|
|
4920
|
-
if (end <= begin) {
|
|
4921
|
-
return new Range(0, 0);
|
|
4922
|
-
}
|
|
4923
|
-
return new Range(
|
|
4924
|
-
this.get(begin, this._end),
|
|
4925
|
-
this.get(end, this._end),
|
|
4926
|
-
this._step
|
|
4927
|
-
);
|
|
4928
|
-
};
|
|
4929
|
-
|
|
4930
|
-
Range.prototype.indexOf = function indexOf (searchValue) {
|
|
4931
|
-
var offsetValue = searchValue - this._start;
|
|
4932
|
-
if (offsetValue % this._step === 0) {
|
|
4933
|
-
var index = offsetValue / this._step;
|
|
4934
|
-
if (index >= 0 && index < this.size) {
|
|
4935
|
-
return index;
|
|
4936
|
-
}
|
|
4937
|
-
}
|
|
4938
|
-
return -1;
|
|
4939
|
-
};
|
|
4940
|
-
|
|
4941
|
-
Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
|
|
4942
|
-
return this.indexOf(searchValue);
|
|
4943
|
-
};
|
|
4944
|
-
|
|
4945
|
-
Range.prototype.__iterate = function __iterate (fn, reverse) {
|
|
4946
|
-
var size = this.size;
|
|
4947
|
-
var step = this._step;
|
|
4948
|
-
var value = reverse ? this._start + (size - 1) * step : this._start;
|
|
4949
|
-
var i = 0;
|
|
4950
|
-
while (i !== size) {
|
|
4951
|
-
if (fn(value, reverse ? size - ++i : i++, this) === false) {
|
|
4952
|
-
break;
|
|
4953
|
-
}
|
|
4954
|
-
value += reverse ? -step : step;
|
|
4955
|
-
}
|
|
4956
|
-
return i;
|
|
4957
|
-
};
|
|
4958
|
-
|
|
4959
|
-
Range.prototype.__iterator = function __iterator (type, reverse) {
|
|
4960
|
-
var size = this.size;
|
|
4961
|
-
var step = this._step;
|
|
4962
|
-
var value = reverse ? this._start + (size - 1) * step : this._start;
|
|
4963
|
-
var i = 0;
|
|
4964
|
-
return new Iterator(function () {
|
|
4965
|
-
if (i === size) {
|
|
4966
|
-
return iteratorDone();
|
|
4967
|
-
}
|
|
4968
|
-
var v = value;
|
|
4969
|
-
value += reverse ? -step : step;
|
|
4970
|
-
return iteratorValue(type, reverse ? size - ++i : i++, v);
|
|
4971
|
-
});
|
|
4972
|
-
};
|
|
4973
|
-
|
|
4974
|
-
Range.prototype.equals = function equals (other) {
|
|
4975
|
-
return other instanceof Range
|
|
4976
|
-
? this._start === other._start &&
|
|
4977
|
-
this._end === other._end &&
|
|
4978
|
-
this._step === other._step
|
|
4979
|
-
: deepEqual(this, other);
|
|
4980
|
-
};
|
|
4981
|
-
|
|
4982
|
-
return Range;
|
|
4983
|
-
}(IndexedSeq));
|
|
4984
|
-
|
|
4985
|
-
var EMPTY_RANGE;
|
|
4986
|
-
|
|
4987
4941
|
/**
|
|
4988
4942
|
* Returns the value at the provided key path starting at the provided
|
|
4989
4943
|
* collection, or notSetValue if the key path is not defined.
|
|
4990
4944
|
*
|
|
4991
4945
|
* A functional alternative to `collection.getIn(keypath)` which will also
|
|
4992
4946
|
* work with plain Objects and Arrays.
|
|
4993
|
-
*
|
|
4994
|
-
* <!-- runkit:activate -->
|
|
4995
|
-
* ```js
|
|
4996
|
-
* import { getIn } from 'immutable';
|
|
4997
|
-
*
|
|
4998
|
-
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
|
|
4999
|
-
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
|
|
5000
|
-
* ```
|
|
5001
4947
|
*/
|
|
5002
4948
|
function getIn$1(collection, searchKeyPath, notSetValue) {
|
|
5003
4949
|
var keyPath = coerceKeyPath(searchKeyPath);
|
|
@@ -5021,14 +4967,6 @@
|
|
|
5021
4967
|
*
|
|
5022
4968
|
* A functional alternative to `collection.hasIn(keypath)` which will also
|
|
5023
4969
|
* work with plain Objects and Arrays.
|
|
5024
|
-
*
|
|
5025
|
-
* <!-- runkit:activate -->
|
|
5026
|
-
* ```js
|
|
5027
|
-
* import { hasIn } from 'immutable';
|
|
5028
|
-
*
|
|
5029
|
-
* hasIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // true
|
|
5030
|
-
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
|
|
5031
|
-
* ```
|
|
5032
4970
|
*/
|
|
5033
4971
|
function hasIn$1(collection, keyPath) {
|
|
5034
4972
|
return getIn$1(collection, keyPath, NOT_SET) !== NOT_SET;
|
|
@@ -5047,6 +4985,91 @@
|
|
|
5047
4985
|
return object;
|
|
5048
4986
|
}
|
|
5049
4987
|
|
|
4988
|
+
function toJS(value) {
|
|
4989
|
+
if (!value || typeof value !== 'object') {
|
|
4990
|
+
return value;
|
|
4991
|
+
}
|
|
4992
|
+
if (!isCollection(value)) {
|
|
4993
|
+
if (!isDataStructure(value)) {
|
|
4994
|
+
return value;
|
|
4995
|
+
}
|
|
4996
|
+
// @ts-expect-error until Seq has been migrated to TypeScript
|
|
4997
|
+
value = Seq(value);
|
|
4998
|
+
}
|
|
4999
|
+
if (isKeyed(value)) {
|
|
5000
|
+
var result$1 = {};
|
|
5001
|
+
// @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type
|
|
5002
|
+
value.__iterate(function (v, k) {
|
|
5003
|
+
result$1[k] = toJS(v);
|
|
5004
|
+
});
|
|
5005
|
+
return result$1;
|
|
5006
|
+
}
|
|
5007
|
+
var result = [];
|
|
5008
|
+
// @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types
|
|
5009
|
+
value.__iterate(function (v) {
|
|
5010
|
+
result.push(toJS(v));
|
|
5011
|
+
});
|
|
5012
|
+
return result;
|
|
5013
|
+
}
|
|
5014
|
+
|
|
5015
|
+
function hashCollection(collection) {
|
|
5016
|
+
// @ts-expect-error Migrate to CollectionImpl in v6
|
|
5017
|
+
if (collection.size === Infinity) {
|
|
5018
|
+
return 0;
|
|
5019
|
+
}
|
|
5020
|
+
var ordered = isOrdered(collection);
|
|
5021
|
+
var keyed = isKeyed(collection);
|
|
5022
|
+
var h = ordered ? 1 : 0;
|
|
5023
|
+
// @ts-expect-error Migrate to CollectionImpl in v6
|
|
5024
|
+
collection.__iterate(keyed
|
|
5025
|
+
? ordered
|
|
5026
|
+
? function (v, k) {
|
|
5027
|
+
h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
|
|
5028
|
+
}
|
|
5029
|
+
: function (v, k) {
|
|
5030
|
+
h = (h + hashMerge(hash(v), hash(k))) | 0;
|
|
5031
|
+
}
|
|
5032
|
+
: ordered
|
|
5033
|
+
? function (v) {
|
|
5034
|
+
h = (31 * h + hash(v)) | 0;
|
|
5035
|
+
}
|
|
5036
|
+
: function (v) {
|
|
5037
|
+
h = (h + hash(v)) | 0;
|
|
5038
|
+
});
|
|
5039
|
+
// @ts-expect-error Migrate to CollectionImpl in v6
|
|
5040
|
+
return murmurHashOfSize(collection.size, h);
|
|
5041
|
+
}
|
|
5042
|
+
function murmurHashOfSize(size, h) {
|
|
5043
|
+
h = imul(h, 0xcc9e2d51);
|
|
5044
|
+
h = imul((h << 15) | (h >>> -15), 0x1b873593);
|
|
5045
|
+
h = imul((h << 13) | (h >>> -13), 5);
|
|
5046
|
+
h = ((h + 0xe6546b64) | 0) ^ size;
|
|
5047
|
+
h = imul(h ^ (h >>> 16), 0x85ebca6b);
|
|
5048
|
+
h = imul(h ^ (h >>> 13), 0xc2b2ae35);
|
|
5049
|
+
h = smi(h ^ (h >>> 16));
|
|
5050
|
+
return h;
|
|
5051
|
+
}
|
|
5052
|
+
function hashMerge(a, b) {
|
|
5053
|
+
return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
|
|
5054
|
+
}
|
|
5055
|
+
|
|
5056
|
+
/**
|
|
5057
|
+
* Contributes additional methods to a constructor
|
|
5058
|
+
*/
|
|
5059
|
+
function mixin(ctor,
|
|
5060
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
5061
|
+
methods) {
|
|
5062
|
+
var keyCopier = function (key) {
|
|
5063
|
+
// @ts-expect-error how to handle symbol ?
|
|
5064
|
+
ctor.prototype[key] = methods[key];
|
|
5065
|
+
};
|
|
5066
|
+
Object.keys(methods).forEach(keyCopier);
|
|
5067
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
|
|
5068
|
+
Object.getOwnPropertySymbols &&
|
|
5069
|
+
Object.getOwnPropertySymbols(methods).forEach(keyCopier);
|
|
5070
|
+
return ctor;
|
|
5071
|
+
}
|
|
5072
|
+
|
|
5050
5073
|
Collection.Iterator = Iterator;
|
|
5051
5074
|
|
|
5052
5075
|
mixin(Collection, {
|
|
@@ -5685,89 +5708,15 @@
|
|
|
5685
5708
|
|
|
5686
5709
|
// #pragma Helper functions
|
|
5687
5710
|
|
|
5688
|
-
function reduce(collection, reducer, reduction, context, useFirst, reverse) {
|
|
5689
|
-
assertNotInfinite(collection.size);
|
|
5690
|
-
collection.__iterate(function (v, k, c) {
|
|
5691
|
-
if (useFirst) {
|
|
5692
|
-
useFirst = false;
|
|
5693
|
-
reduction = v;
|
|
5694
|
-
} else {
|
|
5695
|
-
reduction = reducer.call(context, reduction, v, k, c);
|
|
5696
|
-
}
|
|
5697
|
-
}, reverse);
|
|
5698
|
-
return reduction;
|
|
5699
|
-
}
|
|
5700
|
-
|
|
5701
|
-
function keyMapper(v, k) {
|
|
5702
|
-
return k;
|
|
5703
|
-
}
|
|
5704
|
-
|
|
5705
|
-
function entryMapper(v, k) {
|
|
5706
|
-
return [k, v];
|
|
5707
|
-
}
|
|
5708
|
-
|
|
5709
|
-
function not(predicate) {
|
|
5710
|
-
return function () {
|
|
5711
|
-
return !predicate.apply(this, arguments);
|
|
5712
|
-
};
|
|
5713
|
-
}
|
|
5714
|
-
|
|
5715
|
-
function neg(predicate) {
|
|
5716
|
-
return function () {
|
|
5717
|
-
return -predicate.apply(this, arguments);
|
|
5718
|
-
};
|
|
5719
|
-
}
|
|
5720
|
-
|
|
5721
5711
|
function defaultZipper() {
|
|
5722
5712
|
return arrCopy(arguments);
|
|
5723
5713
|
}
|
|
5724
5714
|
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
if (collection.size === Infinity) {
|
|
5731
|
-
return 0;
|
|
5732
|
-
}
|
|
5733
|
-
var ordered = isOrdered(collection);
|
|
5734
|
-
var keyed = isKeyed(collection);
|
|
5735
|
-
var h = ordered ? 1 : 0;
|
|
5736
|
-
|
|
5737
|
-
collection.__iterate(
|
|
5738
|
-
keyed
|
|
5739
|
-
? ordered
|
|
5740
|
-
? function (v, k) {
|
|
5741
|
-
h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
|
|
5742
|
-
}
|
|
5743
|
-
: function (v, k) {
|
|
5744
|
-
h = (h + hashMerge(hash(v), hash(k))) | 0;
|
|
5745
|
-
}
|
|
5746
|
-
: ordered
|
|
5747
|
-
? function (v) {
|
|
5748
|
-
h = (31 * h + hash(v)) | 0;
|
|
5749
|
-
}
|
|
5750
|
-
: function (v) {
|
|
5751
|
-
h = (h + hash(v)) | 0;
|
|
5752
|
-
}
|
|
5753
|
-
);
|
|
5754
|
-
|
|
5755
|
-
return murmurHashOfSize(collection.size, h);
|
|
5756
|
-
}
|
|
5757
|
-
|
|
5758
|
-
function murmurHashOfSize(size, h) {
|
|
5759
|
-
h = imul(h, 0xcc9e2d51);
|
|
5760
|
-
h = imul((h << 15) | (h >>> -15), 0x1b873593);
|
|
5761
|
-
h = imul((h << 13) | (h >>> -13), 5);
|
|
5762
|
-
h = ((h + 0xe6546b64) | 0) ^ size;
|
|
5763
|
-
h = imul(h ^ (h >>> 16), 0x85ebca6b);
|
|
5764
|
-
h = imul(h ^ (h >>> 13), 0xc2b2ae35);
|
|
5765
|
-
h = smi(h ^ (h >>> 16));
|
|
5766
|
-
return h;
|
|
5767
|
-
}
|
|
5768
|
-
|
|
5769
|
-
function hashMerge(a, b) {
|
|
5770
|
-
return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
|
|
5715
|
+
/**
|
|
5716
|
+
* True if `maybeOrderedSet` is an OrderedSet.
|
|
5717
|
+
*/
|
|
5718
|
+
function isOrderedSet(maybeOrderedSet) {
|
|
5719
|
+
return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
|
|
5771
5720
|
}
|
|
5772
5721
|
|
|
5773
5722
|
var OrderedSet = /*@__PURE__*/(function (Set) {
|
|
@@ -5829,9 +5778,12 @@
|
|
|
5829
5778
|
);
|
|
5830
5779
|
}
|
|
5831
5780
|
|
|
5781
|
+
/**
|
|
5782
|
+
* Describes which item in a pair should be placed first when sorting
|
|
5783
|
+
*/
|
|
5832
5784
|
var PairSorting = {
|
|
5833
|
-
|
|
5834
|
-
|
|
5785
|
+
LeftThenRight: -1,
|
|
5786
|
+
RightThenLeft: 1,
|
|
5835
5787
|
};
|
|
5836
5788
|
|
|
5837
5789
|
function throwOnInvalidDefaultValues(defaultValues) {
|
|
@@ -6036,7 +5988,7 @@
|
|
|
6036
5988
|
RecordPrototype.mergeDeepIn = mergeDeepIn;
|
|
6037
5989
|
RecordPrototype.setIn = setIn;
|
|
6038
5990
|
RecordPrototype.update = update;
|
|
6039
|
-
RecordPrototype.updateIn = updateIn;
|
|
5991
|
+
RecordPrototype.updateIn = updateIn$1;
|
|
6040
5992
|
RecordPrototype.withMutations = withMutations;
|
|
6041
5993
|
RecordPrototype.asMutable = asMutable;
|
|
6042
5994
|
RecordPrototype.asImmutable = asImmutable;
|
|
@@ -6224,7 +6176,9 @@
|
|
|
6224
6176
|
return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
|
|
6225
6177
|
}
|
|
6226
6178
|
|
|
6227
|
-
var version = "5.1.
|
|
6179
|
+
var version = "5.1.4";
|
|
6180
|
+
|
|
6181
|
+
/* eslint-disable import/order */
|
|
6228
6182
|
|
|
6229
6183
|
// Note: Iterable is deprecated
|
|
6230
6184
|
var Iterable = Collection;
|
|
@@ -6274,7 +6228,7 @@
|
|
|
6274
6228
|
exports.set = set;
|
|
6275
6229
|
exports.setIn = setIn$1;
|
|
6276
6230
|
exports.update = update$1;
|
|
6277
|
-
exports.updateIn = updateIn
|
|
6231
|
+
exports.updateIn = updateIn;
|
|
6278
6232
|
exports.version = version;
|
|
6279
6233
|
|
|
6280
6234
|
}));
|