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