immutable 4.0.0-rc.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +255 -174
- package/dist/immutable.d.ts +1160 -677
- package/dist/immutable.es.js +809 -635
- package/dist/immutable.js +5100 -4917
- package/dist/immutable.js.flow +972 -287
- package/dist/immutable.min.js +53 -36
- package/package.json +8 -98
- package/contrib/cursor/README.md +0 -43
- package/contrib/cursor/__tests__/Cursor.ts.skip +0 -395
- package/contrib/cursor/index.d.ts +0 -287
- package/contrib/cursor/index.js +0 -360
- package/dist/immutable-nonambient.d.ts +0 -5149
package/dist/immutable.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2014-present, Facebook, Inc.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
/**
|
|
9
2
|
* Immutable data encourages pure functions (data-in, data-out) and lends itself
|
|
10
3
|
* to much simpler application development and enabling techniques from
|
|
@@ -73,14 +66,14 @@
|
|
|
73
66
|
* `getIn` which expects an `Iterable` path:
|
|
74
67
|
*
|
|
75
68
|
* ```
|
|
76
|
-
* getIn(path: Iterable<string | number>):
|
|
69
|
+
* getIn(path: Iterable<string | number>): unknown
|
|
77
70
|
* ```
|
|
78
71
|
*
|
|
79
72
|
* To use this method, we could pass an array: `data.getIn([ "key", 2 ])`.
|
|
80
73
|
*
|
|
81
74
|
*
|
|
82
75
|
* Note: All examples are presented in the modern [ES2015][] version of
|
|
83
|
-
* JavaScript.
|
|
76
|
+
* JavaScript. Use tools like Babel to support older browsers.
|
|
84
77
|
*
|
|
85
78
|
* For example:
|
|
86
79
|
*
|
|
@@ -92,13 +85,12 @@
|
|
|
92
85
|
* ```
|
|
93
86
|
*
|
|
94
87
|
* [ES2015]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
|
|
95
|
-
* [TypeScript]:
|
|
88
|
+
* [TypeScript]: https://www.typescriptlang.org/
|
|
96
89
|
* [Flow]: https://flowtype.org/
|
|
97
90
|
* [Iterable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
98
91
|
*/
|
|
99
92
|
|
|
100
|
-
declare
|
|
101
|
-
|
|
93
|
+
declare namespace Immutable {
|
|
102
94
|
/**
|
|
103
95
|
* Lists are ordered indexed dense collections, much like a JavaScript
|
|
104
96
|
* Array.
|
|
@@ -113,26 +105,25 @@ declare module Immutable {
|
|
|
113
105
|
* "unset" index and an index set to `undefined`. `List#forEach` visits all
|
|
114
106
|
* indices from 0 to size, regardless of whether they were explicitly defined.
|
|
115
107
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
namespace List {
|
|
118
109
|
/**
|
|
119
110
|
* True if the provided value is a List
|
|
120
111
|
*
|
|
121
112
|
* <!-- runkit:activate -->
|
|
122
113
|
* ```js
|
|
123
|
-
* const { List } = require('immutable
|
|
114
|
+
* const { List } = require('immutable');
|
|
124
115
|
* List.isList([]); // false
|
|
125
116
|
* List.isList(List()); // true
|
|
126
117
|
* ```
|
|
127
118
|
*/
|
|
128
|
-
function isList(maybeList:
|
|
119
|
+
function isList(maybeList: unknown): maybeList is List<unknown>;
|
|
129
120
|
|
|
130
121
|
/**
|
|
131
122
|
* Creates a new List containing `values`.
|
|
132
123
|
*
|
|
133
124
|
* <!-- runkit:activate -->
|
|
134
125
|
* ```js
|
|
135
|
-
* const { List } = require('immutable
|
|
126
|
+
* const { List } = require('immutable');
|
|
136
127
|
* List.of(1, 2, 3, 4)
|
|
137
128
|
* // List [ 1, 2, 3, 4 ]
|
|
138
129
|
* ```
|
|
@@ -141,7 +132,7 @@ declare module Immutable {
|
|
|
141
132
|
*
|
|
142
133
|
* <!-- runkit:activate -->
|
|
143
134
|
* ```js
|
|
144
|
-
* const { List } = require('immutable
|
|
135
|
+
* const { List } = require('immutable');
|
|
145
136
|
* List.of({x:1}, 2, [3], 4)
|
|
146
137
|
* // List [ { x: 1 }, 2, [ 3 ], 4 ]
|
|
147
138
|
* ```
|
|
@@ -153,9 +144,12 @@ declare module Immutable {
|
|
|
153
144
|
* Create a new immutable List containing the values of the provided
|
|
154
145
|
* collection-like.
|
|
155
146
|
*
|
|
147
|
+
* Note: `List` is a factory function and not a class, and does not use the
|
|
148
|
+
* `new` keyword during construction.
|
|
149
|
+
*
|
|
156
150
|
* <!-- runkit:activate -->
|
|
157
151
|
* ```js
|
|
158
|
-
* const { List, Set } = require('immutable
|
|
152
|
+
* const { List, Set } = require('immutable')
|
|
159
153
|
*
|
|
160
154
|
* const emptyList = List()
|
|
161
155
|
* // List []
|
|
@@ -177,12 +171,9 @@ declare module Immutable {
|
|
|
177
171
|
* listFromPlainSet.equals(listFromPlainArray) // true
|
|
178
172
|
* ```
|
|
179
173
|
*/
|
|
180
|
-
|
|
181
|
-
export function List<T>(): List<T>;
|
|
182
|
-
export function List<T>(collection: Iterable<T>): List<T>;
|
|
183
|
-
|
|
184
|
-
export interface List<T> extends Collection.Indexed<T> {
|
|
174
|
+
function List<T>(collection?: Iterable<T> | ArrayLike<T>): List<T>;
|
|
185
175
|
|
|
176
|
+
interface List<T> extends Collection.Indexed<T> {
|
|
186
177
|
/**
|
|
187
178
|
* The number of items in this List.
|
|
188
179
|
*/
|
|
@@ -201,7 +192,7 @@ declare module Immutable {
|
|
|
201
192
|
* enough to include the `index`.
|
|
202
193
|
*
|
|
203
194
|
* <!-- runkit:activate
|
|
204
|
-
* { "preamble": "const { List } = require('immutable
|
|
195
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
205
196
|
* -->
|
|
206
197
|
* ```js
|
|
207
198
|
* const originalList = List([ 0 ]);
|
|
@@ -234,7 +225,7 @@ declare module Immutable {
|
|
|
234
225
|
* Note: `delete` cannot be safely used in IE8
|
|
235
226
|
*
|
|
236
227
|
* <!-- runkit:activate
|
|
237
|
-
* { "preamble": "const { List } = require('immutable
|
|
228
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
238
229
|
* -->
|
|
239
230
|
* ```js
|
|
240
231
|
* List([ 0, 1, 2, 3, 4 ]).delete(0);
|
|
@@ -258,7 +249,7 @@ declare module Immutable {
|
|
|
258
249
|
* This is synonymous with `list.splice(index, 0, value)`.
|
|
259
250
|
*
|
|
260
251
|
* <!-- runkit:activate
|
|
261
|
-
* { "preamble": "const { List } = require('immutable
|
|
252
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
262
253
|
* -->
|
|
263
254
|
* ```js
|
|
264
255
|
* List([ 0, 1, 2, 3, 4 ]).insert(6, 5)
|
|
@@ -276,7 +267,7 @@ declare module Immutable {
|
|
|
276
267
|
* Returns a new List with 0 size and no values in constant time.
|
|
277
268
|
*
|
|
278
269
|
* <!-- runkit:activate
|
|
279
|
-
* { "preamble": "const { List } = require('immutable
|
|
270
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
280
271
|
* -->
|
|
281
272
|
* ```js
|
|
282
273
|
* List([ 1, 2, 3, 4 ]).clear()
|
|
@@ -292,7 +283,7 @@ declare module Immutable {
|
|
|
292
283
|
* List's `size`.
|
|
293
284
|
*
|
|
294
285
|
* <!-- runkit:activate
|
|
295
|
-
* { "preamble": "const { List } = require('immutable
|
|
286
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
296
287
|
* -->
|
|
297
288
|
* ```js
|
|
298
289
|
* List([ 1, 2, 3, 4 ]).push(5)
|
|
@@ -325,7 +316,7 @@ declare module Immutable {
|
|
|
325
316
|
* values ahead to higher indices.
|
|
326
317
|
*
|
|
327
318
|
* <!-- runkit:activate
|
|
328
|
-
* { "preamble": "const { List } = require('immutable
|
|
319
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
329
320
|
* -->
|
|
330
321
|
* ```js
|
|
331
322
|
* List([ 2, 3, 4]).unshift(1);
|
|
@@ -345,7 +336,7 @@ declare module Immutable {
|
|
|
345
336
|
* value in this List.
|
|
346
337
|
*
|
|
347
338
|
* <!-- runkit:activate
|
|
348
|
-
* { "preamble": "const { List } = require('immutable
|
|
339
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
349
340
|
* -->
|
|
350
341
|
* ```js
|
|
351
342
|
* List([ 0, 1, 2, 3, 4 ]).shift();
|
|
@@ -366,7 +357,7 @@ declare module Immutable {
|
|
|
366
357
|
* List. `v.update(-1)` updates the last item in the List.
|
|
367
358
|
*
|
|
368
359
|
* <!-- runkit:activate
|
|
369
|
-
* { "preamble": "const { List } = require('immutable
|
|
360
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
370
361
|
* -->
|
|
371
362
|
* ```js
|
|
372
363
|
* const list = List([ 'a', 'b', 'c' ])
|
|
@@ -380,7 +371,7 @@ declare module Immutable {
|
|
|
380
371
|
* For example, to sum a List after mapping and filtering:
|
|
381
372
|
*
|
|
382
373
|
* <!-- runkit:activate
|
|
383
|
-
* { "preamble": "const { List } = require('immutable
|
|
374
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
384
375
|
* -->
|
|
385
376
|
* ```js
|
|
386
377
|
* function sum(collection) {
|
|
@@ -399,7 +390,7 @@ declare module Immutable {
|
|
|
399
390
|
* @see `Map#update`
|
|
400
391
|
*/
|
|
401
392
|
update(index: number, notSetValue: T, updater: (value: T) => T): this;
|
|
402
|
-
update(index: number, updater: (value: T) => T): this;
|
|
393
|
+
update(index: number, updater: (value: T | undefined) => T): this;
|
|
403
394
|
update<R>(updater: (value: this) => R): R;
|
|
404
395
|
|
|
405
396
|
/**
|
|
@@ -414,7 +405,6 @@ declare module Immutable {
|
|
|
414
405
|
*/
|
|
415
406
|
setSize(size: number): List<T>;
|
|
416
407
|
|
|
417
|
-
|
|
418
408
|
// Deep persistent changes
|
|
419
409
|
|
|
420
410
|
/**
|
|
@@ -426,7 +416,7 @@ declare module Immutable {
|
|
|
426
416
|
*
|
|
427
417
|
* <!-- runkit:activate -->
|
|
428
418
|
* ```js
|
|
429
|
-
* const { List } = require('immutable
|
|
419
|
+
* const { List } = require('immutable')
|
|
430
420
|
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
|
431
421
|
* list.setIn([3, 0], 999);
|
|
432
422
|
* // List [ 0, 1, 2, List [ 999, 4 ] ]
|
|
@@ -438,7 +428,7 @@ declare module Immutable {
|
|
|
438
428
|
*
|
|
439
429
|
* <!-- runkit:activate -->
|
|
440
430
|
* ```js
|
|
441
|
-
* const { List } = require('immutable
|
|
431
|
+
* const { List } = require('immutable')
|
|
442
432
|
* const list = List([ 0, 1, 2, { plain: 'object' }])
|
|
443
433
|
* list.setIn([3, 'plain'], 'value');
|
|
444
434
|
* // List([ 0, 1, 2, { plain: 'value' }])
|
|
@@ -446,7 +436,7 @@ declare module Immutable {
|
|
|
446
436
|
*
|
|
447
437
|
* Note: `setIn` can be used in `withMutations`.
|
|
448
438
|
*/
|
|
449
|
-
setIn(keyPath: Iterable<
|
|
439
|
+
setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
|
450
440
|
|
|
451
441
|
/**
|
|
452
442
|
* Returns a new List having removed the value at this `keyPath`. If any
|
|
@@ -454,7 +444,7 @@ declare module Immutable {
|
|
|
454
444
|
*
|
|
455
445
|
* <!-- runkit:activate -->
|
|
456
446
|
* ```js
|
|
457
|
-
* const { List } = require('immutable
|
|
447
|
+
* const { List } = require('immutable')
|
|
458
448
|
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
|
459
449
|
* list.deleteIn([3, 0]);
|
|
460
450
|
* // List [ 0, 1, 2, List [ 4 ] ]
|
|
@@ -466,7 +456,7 @@ declare module Immutable {
|
|
|
466
456
|
*
|
|
467
457
|
* <!-- runkit:activate -->
|
|
468
458
|
* ```js
|
|
469
|
-
* const { List } = require('immutable
|
|
459
|
+
* const { List } = require('immutable')
|
|
470
460
|
* const list = List([ 0, 1, 2, { plain: 'object' }])
|
|
471
461
|
* list.removeIn([3, 'plain']);
|
|
472
462
|
* // List([ 0, 1, 2, {}])
|
|
@@ -476,30 +466,40 @@ declare module Immutable {
|
|
|
476
466
|
*
|
|
477
467
|
* @alias removeIn
|
|
478
468
|
*/
|
|
479
|
-
deleteIn(keyPath: Iterable<
|
|
480
|
-
removeIn(keyPath: Iterable<
|
|
469
|
+
deleteIn(keyPath: Iterable<unknown>): this;
|
|
470
|
+
removeIn(keyPath: Iterable<unknown>): this;
|
|
481
471
|
|
|
482
472
|
/**
|
|
483
473
|
* Note: `updateIn` can be used in `withMutations`.
|
|
484
474
|
*
|
|
485
475
|
* @see `Map#updateIn`
|
|
486
476
|
*/
|
|
487
|
-
updateIn(
|
|
488
|
-
|
|
477
|
+
updateIn(
|
|
478
|
+
keyPath: Iterable<unknown>,
|
|
479
|
+
notSetValue: unknown,
|
|
480
|
+
updater: (value: unknown) => unknown
|
|
481
|
+
): this;
|
|
482
|
+
updateIn(
|
|
483
|
+
keyPath: Iterable<unknown>,
|
|
484
|
+
updater: (value: unknown) => unknown
|
|
485
|
+
): this;
|
|
489
486
|
|
|
490
487
|
/**
|
|
491
488
|
* Note: `mergeIn` can be used in `withMutations`.
|
|
492
489
|
*
|
|
493
490
|
* @see `Map#mergeIn`
|
|
494
491
|
*/
|
|
495
|
-
mergeIn(keyPath: Iterable<
|
|
492
|
+
mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
|
|
496
493
|
|
|
497
494
|
/**
|
|
498
495
|
* Note: `mergeDeepIn` can be used in `withMutations`.
|
|
499
496
|
*
|
|
500
497
|
* @see `Map#mergeDeepIn`
|
|
501
498
|
*/
|
|
502
|
-
mergeDeepIn(
|
|
499
|
+
mergeDeepIn(
|
|
500
|
+
keyPath: Iterable<unknown>,
|
|
501
|
+
...collections: Array<unknown>
|
|
502
|
+
): this;
|
|
503
503
|
|
|
504
504
|
// Transient changes
|
|
505
505
|
|
|
@@ -510,7 +510,7 @@ declare module Immutable {
|
|
|
510
510
|
*
|
|
511
511
|
* @see `Map#withMutations`
|
|
512
512
|
*/
|
|
513
|
-
withMutations(mutator: (mutable: this) =>
|
|
513
|
+
withMutations(mutator: (mutable: this) => unknown): this;
|
|
514
514
|
|
|
515
515
|
/**
|
|
516
516
|
* An alternative API for withMutations()
|
|
@@ -550,19 +550,16 @@ declare module Immutable {
|
|
|
550
550
|
* `mapper` function.
|
|
551
551
|
*
|
|
552
552
|
* <!-- runkit:activate
|
|
553
|
-
* { "preamble": "const { List } = require('immutable
|
|
553
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
554
554
|
* -->
|
|
555
555
|
* ```js
|
|
556
556
|
* List([ 1, 2 ]).map(x => 10 * x)
|
|
557
557
|
* // List [ 10, 20 ]
|
|
558
558
|
* ```
|
|
559
|
-
*
|
|
560
|
-
* Note: `map()` always returns a new instance, even if it produced the same
|
|
561
|
-
* value at every step.
|
|
562
559
|
*/
|
|
563
560
|
map<M>(
|
|
564
561
|
mapper: (value: T, key: number, iter: this) => M,
|
|
565
|
-
context?:
|
|
562
|
+
context?: unknown
|
|
566
563
|
): List<M>;
|
|
567
564
|
|
|
568
565
|
/**
|
|
@@ -572,7 +569,7 @@ declare module Immutable {
|
|
|
572
569
|
*/
|
|
573
570
|
flatMap<M>(
|
|
574
571
|
mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
|
575
|
-
context?:
|
|
572
|
+
context?: unknown
|
|
576
573
|
): List<M>;
|
|
577
574
|
|
|
578
575
|
/**
|
|
@@ -584,11 +581,11 @@ declare module Immutable {
|
|
|
584
581
|
*/
|
|
585
582
|
filter<F extends T>(
|
|
586
583
|
predicate: (value: T, index: number, iter: this) => value is F,
|
|
587
|
-
context?:
|
|
584
|
+
context?: unknown
|
|
588
585
|
): List<F>;
|
|
589
586
|
filter(
|
|
590
|
-
predicate: (value: T, index: number, iter: this) =>
|
|
591
|
-
context?:
|
|
587
|
+
predicate: (value: T, index: number, iter: this) => unknown,
|
|
588
|
+
context?: unknown
|
|
592
589
|
): this;
|
|
593
590
|
|
|
594
591
|
/**
|
|
@@ -597,7 +594,7 @@ declare module Immutable {
|
|
|
597
594
|
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
|
598
595
|
*
|
|
599
596
|
* <!-- runkit:activate
|
|
600
|
-
* { "preamble": "const { List } = require('immutable
|
|
597
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
601
598
|
* -->
|
|
602
599
|
* ```js
|
|
603
600
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -605,9 +602,12 @@ declare module Immutable {
|
|
|
605
602
|
* const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
606
603
|
* ```
|
|
607
604
|
*/
|
|
608
|
-
zip<U>(other: Collection<
|
|
609
|
-
zip<U,V>(
|
|
610
|
-
|
|
605
|
+
zip<U>(other: Collection<unknown, U>): List<[T, U]>;
|
|
606
|
+
zip<U, V>(
|
|
607
|
+
other: Collection<unknown, U>,
|
|
608
|
+
other2: Collection<unknown, V>
|
|
609
|
+
): List<[T, U, V]>;
|
|
610
|
+
zip(...collections: Array<Collection<unknown, unknown>>): List<unknown>;
|
|
611
611
|
|
|
612
612
|
/**
|
|
613
613
|
* Returns a List "zipped" with the provided collections.
|
|
@@ -616,7 +616,7 @@ declare module Immutable {
|
|
|
616
616
|
* exhausted. Missing values from shorter collections are filled with `undefined`.
|
|
617
617
|
*
|
|
618
618
|
* <!-- runkit:activate
|
|
619
|
-
* { "preamble": "const { List } = require('immutable
|
|
619
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
620
620
|
* -->
|
|
621
621
|
* ```js
|
|
622
622
|
* const a = List([ 1, 2 ]);
|
|
@@ -628,16 +628,19 @@ declare module Immutable {
|
|
|
628
628
|
* input, some results may contain undefined values. TypeScript cannot
|
|
629
629
|
* account for these without cases (as of v2.5).
|
|
630
630
|
*/
|
|
631
|
-
zipAll<U>(other: Collection<
|
|
632
|
-
zipAll<U,V>(
|
|
633
|
-
|
|
631
|
+
zipAll<U>(other: Collection<unknown, U>): List<[T, U]>;
|
|
632
|
+
zipAll<U, V>(
|
|
633
|
+
other: Collection<unknown, U>,
|
|
634
|
+
other2: Collection<unknown, V>
|
|
635
|
+
): List<[T, U, V]>;
|
|
636
|
+
zipAll(...collections: Array<Collection<unknown, unknown>>): List<unknown>;
|
|
634
637
|
|
|
635
638
|
/**
|
|
636
639
|
* Returns a List "zipped" with the provided collections by using a
|
|
637
640
|
* custom `zipper` function.
|
|
638
641
|
*
|
|
639
642
|
* <!-- runkit:activate
|
|
640
|
-
* { "preamble": "const { List } = require('immutable
|
|
643
|
+
* { "preamble": "const { List } = require('immutable');" }
|
|
641
644
|
* -->
|
|
642
645
|
* ```js
|
|
643
646
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -648,20 +651,19 @@ declare module Immutable {
|
|
|
648
651
|
*/
|
|
649
652
|
zipWith<U, Z>(
|
|
650
653
|
zipper: (value: T, otherValue: U) => Z,
|
|
651
|
-
otherCollection: Collection<
|
|
654
|
+
otherCollection: Collection<unknown, U>
|
|
652
655
|
): List<Z>;
|
|
653
656
|
zipWith<U, V, Z>(
|
|
654
657
|
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
|
655
|
-
otherCollection: Collection<
|
|
656
|
-
thirdCollection: Collection<
|
|
658
|
+
otherCollection: Collection<unknown, U>,
|
|
659
|
+
thirdCollection: Collection<unknown, V>
|
|
657
660
|
): List<Z>;
|
|
658
661
|
zipWith<Z>(
|
|
659
|
-
zipper: (...
|
|
660
|
-
...collections: Array<Collection<
|
|
662
|
+
zipper: (...values: Array<unknown>) => Z,
|
|
663
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
661
664
|
): List<Z>;
|
|
662
665
|
}
|
|
663
666
|
|
|
664
|
-
|
|
665
667
|
/**
|
|
666
668
|
* Immutable Map is an unordered Collection.Keyed of (key, value) pairs with
|
|
667
669
|
* `O(log32 N)` gets and `O(log32 N)` persistent sets.
|
|
@@ -678,7 +680,7 @@ declare module Immutable {
|
|
|
678
680
|
*
|
|
679
681
|
* <!-- runkit:activate -->
|
|
680
682
|
* ```js
|
|
681
|
-
* const { Map, List } = require('immutable
|
|
683
|
+
* const { Map, List } = require('immutable');
|
|
682
684
|
* Map().set(List([ 1 ]), 'listofone').get(List([ 1 ]));
|
|
683
685
|
* // 'listofone'
|
|
684
686
|
* ```
|
|
@@ -689,26 +691,25 @@ declare module Immutable {
|
|
|
689
691
|
*
|
|
690
692
|
* Implemented by a hash-array mapped trie.
|
|
691
693
|
*/
|
|
692
|
-
|
|
693
|
-
|
|
694
|
+
namespace Map {
|
|
694
695
|
/**
|
|
695
696
|
* True if the provided value is a Map
|
|
696
697
|
*
|
|
697
698
|
* <!-- runkit:activate -->
|
|
698
699
|
* ```js
|
|
699
|
-
* const { Map } = require('immutable
|
|
700
|
+
* const { Map } = require('immutable')
|
|
700
701
|
* Map.isMap({}) // false
|
|
701
702
|
* Map.isMap(Map()) // true
|
|
702
703
|
* ```
|
|
703
704
|
*/
|
|
704
|
-
function isMap(maybeMap:
|
|
705
|
+
function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
|
|
705
706
|
|
|
706
707
|
/**
|
|
707
708
|
* Creates a new Map from alternating keys and values
|
|
708
709
|
*
|
|
709
710
|
* <!-- runkit:activate -->
|
|
710
711
|
* ```js
|
|
711
|
-
* const { Map } = require('immutable
|
|
712
|
+
* const { Map } = require('immutable')
|
|
712
713
|
* Map.of(
|
|
713
714
|
* 'key', 'value',
|
|
714
715
|
* 'numerical value', 3,
|
|
@@ -719,7 +720,7 @@ declare module Immutable {
|
|
|
719
720
|
*
|
|
720
721
|
* @deprecated Use Map([ [ 'k', 'v' ] ]) or Map({ k: 'v' })
|
|
721
722
|
*/
|
|
722
|
-
function of(...keyValues: Array<
|
|
723
|
+
function of(...keyValues: Array<unknown>): Map<unknown, unknown>;
|
|
723
724
|
}
|
|
724
725
|
|
|
725
726
|
/**
|
|
@@ -728,9 +729,12 @@ declare module Immutable {
|
|
|
728
729
|
* Created with the same key value pairs as the provided Collection.Keyed or
|
|
729
730
|
* JavaScript Object or expects a Collection of [K, V] tuple entries.
|
|
730
731
|
*
|
|
732
|
+
* Note: `Map` is a factory function and not a class, and does not use the
|
|
733
|
+
* `new` keyword during construction.
|
|
734
|
+
*
|
|
731
735
|
* <!-- runkit:activate -->
|
|
732
736
|
* ```js
|
|
733
|
-
* const { Map } = require('immutable
|
|
737
|
+
* const { Map } = require('immutable')
|
|
734
738
|
* Map({ key: "value" })
|
|
735
739
|
* Map([ [ "key", "value" ] ])
|
|
736
740
|
* ```
|
|
@@ -740,7 +744,7 @@ declare module Immutable {
|
|
|
740
744
|
* quote-less shorthand, while Immutable Maps accept keys of any type.
|
|
741
745
|
*
|
|
742
746
|
* <!-- runkit:activate
|
|
743
|
-
* { "preamble": "const { Map } = require('immutable
|
|
747
|
+
* { "preamble": "const { Map } = require('immutable');" }
|
|
744
748
|
* -->
|
|
745
749
|
* ```js
|
|
746
750
|
* let obj = { 1: "one" }
|
|
@@ -755,14 +759,11 @@ declare module Immutable {
|
|
|
755
759
|
* but since Immutable Map keys can be of any type the argument to `get()` is
|
|
756
760
|
* not altered.
|
|
757
761
|
*/
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
export function Map<K, V>(): Map<K, V>;
|
|
762
|
-
export function Map(): Map<any, any>;
|
|
763
|
-
|
|
764
|
-
export interface Map<K, V> extends Collection.Keyed<K, V> {
|
|
762
|
+
function Map<K, V>(collection?: Iterable<[K, V]>): Map<K, V>;
|
|
763
|
+
function Map<V>(obj: { [key: string]: V }): Map<string, V>;
|
|
764
|
+
function Map<K extends string, V>(obj: { [P in K]?: V }): Map<K, V>;
|
|
765
765
|
|
|
766
|
+
interface Map<K, V> extends Collection.Keyed<K, V> {
|
|
766
767
|
/**
|
|
767
768
|
* The number of entries in this Map.
|
|
768
769
|
*/
|
|
@@ -776,7 +777,7 @@ declare module Immutable {
|
|
|
776
777
|
*
|
|
777
778
|
* <!-- runkit:activate -->
|
|
778
779
|
* ```js
|
|
779
|
-
* const { Map } = require('immutable
|
|
780
|
+
* const { Map } = require('immutable')
|
|
780
781
|
* const originalMap = Map()
|
|
781
782
|
* const newerMap = originalMap.set('key', 'value')
|
|
782
783
|
* const newestMap = newerMap.set('key', 'newer value')
|
|
@@ -801,7 +802,7 @@ declare module Immutable {
|
|
|
801
802
|
*
|
|
802
803
|
* <!-- runkit:activate -->
|
|
803
804
|
* ```js
|
|
804
|
-
* const { Map } = require('immutable
|
|
805
|
+
* const { Map } = require('immutable')
|
|
805
806
|
* const originalMap = Map({
|
|
806
807
|
* key: 'value',
|
|
807
808
|
* otherKey: 'other value'
|
|
@@ -823,7 +824,7 @@ declare module Immutable {
|
|
|
823
824
|
*
|
|
824
825
|
* <!-- runkit:activate -->
|
|
825
826
|
* ```js
|
|
826
|
-
* const { Map } = require('immutable
|
|
827
|
+
* const { Map } = require('immutable')
|
|
827
828
|
* const names = Map({ a: "Aaron", b: "Barry", c: "Connor" })
|
|
828
829
|
* names.deleteAll([ 'a', 'c' ])
|
|
829
830
|
* // Map { "b": "Barry" }
|
|
@@ -841,7 +842,7 @@ declare module Immutable {
|
|
|
841
842
|
*
|
|
842
843
|
* <!-- runkit:activate -->
|
|
843
844
|
* ```js
|
|
844
|
-
* const { Map } = require('immutable
|
|
845
|
+
* const { Map } = require('immutable')
|
|
845
846
|
* Map({ key: 'value' }).clear()
|
|
846
847
|
* // Map {}
|
|
847
848
|
* ```
|
|
@@ -858,7 +859,7 @@ declare module Immutable {
|
|
|
858
859
|
*
|
|
859
860
|
* <!-- runkit:activate -->
|
|
860
861
|
* ```js
|
|
861
|
-
* const { Map } = require('immutable
|
|
862
|
+
* const { Map } = require('immutable')
|
|
862
863
|
* const aMap = Map({ key: 'value' })
|
|
863
864
|
* const newMap = aMap.update('key', value => value + value)
|
|
864
865
|
* // Map { "key": "valuevalue" }
|
|
@@ -869,7 +870,7 @@ declare module Immutable {
|
|
|
869
870
|
* `update` and `push` can be used together:
|
|
870
871
|
*
|
|
871
872
|
* <!-- runkit:activate
|
|
872
|
-
* { "preamble": "const { Map, List } = require('immutable
|
|
873
|
+
* { "preamble": "const { Map, List } = require('immutable');" }
|
|
873
874
|
* -->
|
|
874
875
|
* ```js
|
|
875
876
|
* const aMap = Map({ nestedList: List([ 1, 2, 3 ]) })
|
|
@@ -881,7 +882,7 @@ declare module Immutable {
|
|
|
881
882
|
* function when the value at the key does not exist in the Map.
|
|
882
883
|
*
|
|
883
884
|
* <!-- runkit:activate
|
|
884
|
-
* { "preamble": "const { Map } = require('immutable
|
|
885
|
+
* { "preamble": "const { Map } = require('immutable');" }
|
|
885
886
|
* -->
|
|
886
887
|
* ```js
|
|
887
888
|
* const aMap = Map({ key: 'value' })
|
|
@@ -894,7 +895,7 @@ declare module Immutable {
|
|
|
894
895
|
* is provided.
|
|
895
896
|
*
|
|
896
897
|
* <!-- runkit:activate
|
|
897
|
-
* { "preamble": "const { Map } = require('immutable
|
|
898
|
+
* { "preamble": "const { Map } = require('immutable');" }
|
|
898
899
|
* -->
|
|
899
900
|
* ```js
|
|
900
901
|
* const aMap = Map({ apples: 10 })
|
|
@@ -910,7 +911,7 @@ declare module Immutable {
|
|
|
910
911
|
* The previous example behaves differently when written with default values:
|
|
911
912
|
*
|
|
912
913
|
* <!-- runkit:activate
|
|
913
|
-
* { "preamble": "const { Map } = require('immutable
|
|
914
|
+
* { "preamble": "const { Map } = require('immutable');" }
|
|
914
915
|
* -->
|
|
915
916
|
* ```js
|
|
916
917
|
* const aMap = Map({ apples: 10 })
|
|
@@ -922,7 +923,7 @@ declare module Immutable {
|
|
|
922
923
|
* returned as well.
|
|
923
924
|
*
|
|
924
925
|
* <!-- runkit:activate
|
|
925
|
-
* { "preamble": "const { Map } = require('immutable
|
|
926
|
+
* { "preamble": "const { Map } = require('immutable');" }
|
|
926
927
|
* -->
|
|
927
928
|
* ```js
|
|
928
929
|
* const aMap = Map({ key: 'value' })
|
|
@@ -936,7 +937,7 @@ declare module Immutable {
|
|
|
936
937
|
* For example, to sum the values in a Map
|
|
937
938
|
*
|
|
938
939
|
* <!-- runkit:activate
|
|
939
|
-
* { "preamble": "const { Map } = require('immutable
|
|
940
|
+
* { "preamble": "const { Map } = require('immutable');" }
|
|
940
941
|
* -->
|
|
941
942
|
* ```js
|
|
942
943
|
* function sum(collection) {
|
|
@@ -953,7 +954,7 @@ declare module Immutable {
|
|
|
953
954
|
* Note: `update(key)` can be used in `withMutations`.
|
|
954
955
|
*/
|
|
955
956
|
update(key: K, notSetValue: V, updater: (value: V) => V): this;
|
|
956
|
-
update(key: K, updater: (value: V) => V): this;
|
|
957
|
+
update(key: K, updater: (value: V | undefined) => V): this;
|
|
957
958
|
update<R>(updater: (value: this) => R): R;
|
|
958
959
|
|
|
959
960
|
/**
|
|
@@ -966,7 +967,7 @@ declare module Immutable {
|
|
|
966
967
|
*
|
|
967
968
|
* <!-- runkit:activate -->
|
|
968
969
|
* ```js
|
|
969
|
-
* const { Map } = require('immutable
|
|
970
|
+
* const { Map } = require('immutable')
|
|
970
971
|
* const one = Map({ a: 10, b: 20, c: 30 })
|
|
971
972
|
* const two = Map({ b: 40, a: 50, d: 60 })
|
|
972
973
|
* one.merge(two) // Map { "a": 50, "b": 40, "c": 30, "d": 60 }
|
|
@@ -977,10 +978,18 @@ declare module Immutable {
|
|
|
977
978
|
*
|
|
978
979
|
* @alias concat
|
|
979
980
|
*/
|
|
980
|
-
merge<KC, VC>(
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
981
|
+
merge<KC, VC>(
|
|
982
|
+
...collections: Array<Iterable<[KC, VC]>>
|
|
983
|
+
): Map<K | KC, V | VC>;
|
|
984
|
+
merge<C>(
|
|
985
|
+
...collections: Array<{ [key: string]: C }>
|
|
986
|
+
): Map<K | string, V | C>;
|
|
987
|
+
concat<KC, VC>(
|
|
988
|
+
...collections: Array<Iterable<[KC, VC]>>
|
|
989
|
+
): Map<K | KC, V | VC>;
|
|
990
|
+
concat<C>(
|
|
991
|
+
...collections: Array<{ [key: string]: C }>
|
|
992
|
+
): Map<K | string, V | C>;
|
|
984
993
|
|
|
985
994
|
/**
|
|
986
995
|
* Like `merge()`, `mergeWith()` returns a new Map resulting from merging
|
|
@@ -989,7 +998,7 @@ declare module Immutable {
|
|
|
989
998
|
*
|
|
990
999
|
* <!-- runkit:activate -->
|
|
991
1000
|
* ```js
|
|
992
|
-
* const { Map } = require('immutable
|
|
1001
|
+
* const { Map } = require('immutable')
|
|
993
1002
|
* const one = Map({ a: 10, b: 20, c: 30 })
|
|
994
1003
|
* const two = Map({ b: 40, a: 50, d: 60 })
|
|
995
1004
|
* one.mergeWith((oldVal, newVal) => oldVal / newVal, two)
|
|
@@ -1002,20 +1011,26 @@ declare module Immutable {
|
|
|
1002
1011
|
*/
|
|
1003
1012
|
mergeWith(
|
|
1004
1013
|
merger: (oldVal: V, newVal: V, key: K) => V,
|
|
1005
|
-
...collections: Array<Iterable<[K, V]> | {[key: string]: V}>
|
|
1014
|
+
...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
|
|
1006
1015
|
): this;
|
|
1007
1016
|
|
|
1008
1017
|
/**
|
|
1009
|
-
* Like `merge()`, but when two
|
|
1010
|
-
* recursing deeply through the nested
|
|
1018
|
+
* Like `merge()`, but when two compatible collections are encountered with
|
|
1019
|
+
* the same key, it merges them as well, recursing deeply through the nested
|
|
1020
|
+
* data. Two collections are considered to be compatible (and thus will be
|
|
1021
|
+
* merged together) if they both fall into one of three categories: keyed
|
|
1022
|
+
* (e.g., `Map`s, `Record`s, and objects), indexed (e.g., `List`s and
|
|
1023
|
+
* arrays), or set-like (e.g., `Set`s). If they fall into separate
|
|
1024
|
+
* categories, `mergeDeep` will replace the existing collection with the
|
|
1025
|
+
* collection being merged in. This behavior can be customized by using
|
|
1026
|
+
* `mergeDeepWith()`.
|
|
1011
1027
|
*
|
|
1012
|
-
* Note:
|
|
1013
|
-
*
|
|
1014
|
-
* a deeper level.
|
|
1028
|
+
* Note: Indexed and set-like collections are merged using
|
|
1029
|
+
* `concat()`/`union()` and therefore do not recurse.
|
|
1015
1030
|
*
|
|
1016
1031
|
* <!-- runkit:activate -->
|
|
1017
1032
|
* ```js
|
|
1018
|
-
* const { Map } = require('immutable
|
|
1033
|
+
* const { Map } = require('immutable')
|
|
1019
1034
|
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
|
1020
1035
|
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
|
1021
1036
|
* one.mergeDeep(two)
|
|
@@ -1028,15 +1043,20 @@ declare module Immutable {
|
|
|
1028
1043
|
*
|
|
1029
1044
|
* Note: `mergeDeep` can be used in `withMutations`.
|
|
1030
1045
|
*/
|
|
1031
|
-
mergeDeep(
|
|
1046
|
+
mergeDeep(
|
|
1047
|
+
...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
|
|
1048
|
+
): this;
|
|
1032
1049
|
|
|
1033
1050
|
/**
|
|
1034
|
-
* Like `mergeDeep()`, but when two non-
|
|
1035
|
-
*
|
|
1051
|
+
* Like `mergeDeep()`, but when two non-collections or incompatible
|
|
1052
|
+
* collections are encountered at the same key, it uses the `merger`
|
|
1053
|
+
* function to determine the resulting value. Collections are considered
|
|
1054
|
+
* incompatible if they fall into separate categories between keyed,
|
|
1055
|
+
* indexed, and set-like.
|
|
1036
1056
|
*
|
|
1037
1057
|
* <!-- runkit:activate -->
|
|
1038
1058
|
* ```js
|
|
1039
|
-
* const { Map } = require('immutable
|
|
1059
|
+
* const { Map } = require('immutable')
|
|
1040
1060
|
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
|
1041
1061
|
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
|
1042
1062
|
* one.mergeDeepWith((oldVal, newVal) => oldVal / newVal, two)
|
|
@@ -1046,15 +1066,14 @@ declare module Immutable {
|
|
|
1046
1066
|
* // "c": Map { "z": 3 }
|
|
1047
1067
|
* // }
|
|
1048
1068
|
* ```
|
|
1049
|
-
|
|
1069
|
+
*
|
|
1050
1070
|
* Note: `mergeDeepWith` can be used in `withMutations`.
|
|
1051
1071
|
*/
|
|
1052
1072
|
mergeDeepWith(
|
|
1053
|
-
merger: (oldVal:
|
|
1054
|
-
...collections: Array<Iterable<[K, V]> | {[key: string]: V}>
|
|
1073
|
+
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
|
1074
|
+
...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
|
|
1055
1075
|
): this;
|
|
1056
1076
|
|
|
1057
|
-
|
|
1058
1077
|
// Deep persistent changes
|
|
1059
1078
|
|
|
1060
1079
|
/**
|
|
@@ -1063,7 +1082,7 @@ declare module Immutable {
|
|
|
1063
1082
|
*
|
|
1064
1083
|
* <!-- runkit:activate -->
|
|
1065
1084
|
* ```js
|
|
1066
|
-
* const { Map } = require('immutable
|
|
1085
|
+
* const { Map } = require('immutable')
|
|
1067
1086
|
* const originalMap = Map({
|
|
1068
1087
|
* subObject: Map({
|
|
1069
1088
|
* subKey: 'subvalue',
|
|
@@ -1099,7 +1118,7 @@ declare module Immutable {
|
|
|
1099
1118
|
*
|
|
1100
1119
|
* <!-- runkit:activate -->
|
|
1101
1120
|
* ```js
|
|
1102
|
-
* const { Map } = require('immutable
|
|
1121
|
+
* const { Map } = require('immutable')
|
|
1103
1122
|
* const originalMap = Map({
|
|
1104
1123
|
* subObject: {
|
|
1105
1124
|
* subKey: 'subvalue',
|
|
@@ -1123,7 +1142,7 @@ declare module Immutable {
|
|
|
1123
1142
|
*
|
|
1124
1143
|
* Note: `setIn` can be used in `withMutations`.
|
|
1125
1144
|
*/
|
|
1126
|
-
setIn(keyPath: Iterable<
|
|
1145
|
+
setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
|
1127
1146
|
|
|
1128
1147
|
/**
|
|
1129
1148
|
* Returns a new Map having removed the value at this `keyPath`. If any keys
|
|
@@ -1133,8 +1152,8 @@ declare module Immutable {
|
|
|
1133
1152
|
*
|
|
1134
1153
|
* @alias removeIn
|
|
1135
1154
|
*/
|
|
1136
|
-
deleteIn(keyPath: Iterable<
|
|
1137
|
-
removeIn(keyPath: Iterable<
|
|
1155
|
+
deleteIn(keyPath: Iterable<unknown>): this;
|
|
1156
|
+
removeIn(keyPath: Iterable<unknown>): this;
|
|
1138
1157
|
|
|
1139
1158
|
/**
|
|
1140
1159
|
* Returns a new Map having applied the `updater` to the entry found at the
|
|
@@ -1146,7 +1165,7 @@ declare module Immutable {
|
|
|
1146
1165
|
*
|
|
1147
1166
|
* <!-- runkit:activate -->
|
|
1148
1167
|
* ```js
|
|
1149
|
-
* const { Map, List } = require('immutable
|
|
1168
|
+
* const { Map, List } = require('immutable')
|
|
1150
1169
|
* const map = Map({ inMap: Map({ inList: List([ 1, 2, 3 ]) }) })
|
|
1151
1170
|
* const newMap = map.updateIn(['inMap', 'inList'], list => list.push(4))
|
|
1152
1171
|
* // Map { "inMap": Map { "inList": List [ 1, 2, 3, 4 ] } }
|
|
@@ -1158,7 +1177,7 @@ declare module Immutable {
|
|
|
1158
1177
|
* provided, otherwise `undefined`.
|
|
1159
1178
|
*
|
|
1160
1179
|
* <!-- runkit:activate
|
|
1161
|
-
* { "preamble": "const { Map } = require('immutable
|
|
1180
|
+
* { "preamble": "const { Map } = require('immutable')" }
|
|
1162
1181
|
* -->
|
|
1163
1182
|
* ```js
|
|
1164
1183
|
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
@@ -1170,7 +1189,7 @@ declare module Immutable {
|
|
|
1170
1189
|
* no change will occur. This is still true if `notSetValue` is provided.
|
|
1171
1190
|
*
|
|
1172
1191
|
* <!-- runkit:activate
|
|
1173
|
-
* { "preamble": "const { Map } = require('immutable
|
|
1192
|
+
* { "preamble": "const { Map } = require('immutable')" }
|
|
1174
1193
|
* -->
|
|
1175
1194
|
* ```js
|
|
1176
1195
|
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
@@ -1186,7 +1205,7 @@ declare module Immutable {
|
|
|
1186
1205
|
* The previous example behaves differently when written with default values:
|
|
1187
1206
|
*
|
|
1188
1207
|
* <!-- runkit:activate
|
|
1189
|
-
* { "preamble": "const { Map } = require('immutable
|
|
1208
|
+
* { "preamble": "const { Map } = require('immutable')" }
|
|
1190
1209
|
* -->
|
|
1191
1210
|
* ```js
|
|
1192
1211
|
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
@@ -1199,7 +1218,7 @@ declare module Immutable {
|
|
|
1199
1218
|
* immutably by creating new copies of those values with the changes applied.
|
|
1200
1219
|
*
|
|
1201
1220
|
* <!-- runkit:activate
|
|
1202
|
-
* { "preamble": "const { Map } = require('immutable
|
|
1221
|
+
* { "preamble": "const { Map } = require('immutable')" }
|
|
1203
1222
|
* -->
|
|
1204
1223
|
* ```js
|
|
1205
1224
|
* const map = Map({ a: { b: { c: 10 } } })
|
|
@@ -1212,8 +1231,15 @@ declare module Immutable {
|
|
|
1212
1231
|
*
|
|
1213
1232
|
* Note: `updateIn` can be used in `withMutations`.
|
|
1214
1233
|
*/
|
|
1215
|
-
updateIn(
|
|
1216
|
-
|
|
1234
|
+
updateIn(
|
|
1235
|
+
keyPath: Iterable<unknown>,
|
|
1236
|
+
notSetValue: unknown,
|
|
1237
|
+
updater: (value: unknown) => unknown
|
|
1238
|
+
): this;
|
|
1239
|
+
updateIn(
|
|
1240
|
+
keyPath: Iterable<unknown>,
|
|
1241
|
+
updater: (value: unknown) => unknown
|
|
1242
|
+
): this;
|
|
1217
1243
|
|
|
1218
1244
|
/**
|
|
1219
1245
|
* A combination of `updateIn` and `merge`, returning a new Map, but
|
|
@@ -1227,7 +1253,7 @@ declare module Immutable {
|
|
|
1227
1253
|
*
|
|
1228
1254
|
* Note: `mergeIn` can be used in `withMutations`.
|
|
1229
1255
|
*/
|
|
1230
|
-
mergeIn(keyPath: Iterable<
|
|
1256
|
+
mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
|
|
1231
1257
|
|
|
1232
1258
|
/**
|
|
1233
1259
|
* A combination of `updateIn` and `mergeDeep`, returning a new Map, but
|
|
@@ -1241,7 +1267,10 @@ declare module Immutable {
|
|
|
1241
1267
|
*
|
|
1242
1268
|
* Note: `mergeDeepIn` can be used in `withMutations`.
|
|
1243
1269
|
*/
|
|
1244
|
-
mergeDeepIn(
|
|
1270
|
+
mergeDeepIn(
|
|
1271
|
+
keyPath: Iterable<unknown>,
|
|
1272
|
+
...collections: Array<unknown>
|
|
1273
|
+
): this;
|
|
1245
1274
|
|
|
1246
1275
|
// Transient changes
|
|
1247
1276
|
|
|
@@ -1260,7 +1289,7 @@ declare module Immutable {
|
|
|
1260
1289
|
*
|
|
1261
1290
|
* <!-- runkit:activate -->
|
|
1262
1291
|
* ```js
|
|
1263
|
-
* const { Map } = require('immutable
|
|
1292
|
+
* const { Map } = require('immutable')
|
|
1264
1293
|
* const map1 = Map()
|
|
1265
1294
|
* const map2 = map1.withMutations(map => {
|
|
1266
1295
|
* map.set('a', 1).set('b', 2).set('c', 3)
|
|
@@ -1273,21 +1302,25 @@ declare module Immutable {
|
|
|
1273
1302
|
* `withMutations`! Read the documentation for each method to see if it
|
|
1274
1303
|
* is safe to use in `withMutations`.
|
|
1275
1304
|
*/
|
|
1276
|
-
withMutations(mutator: (mutable: this) =>
|
|
1305
|
+
withMutations(mutator: (mutable: this) => unknown): this;
|
|
1277
1306
|
|
|
1278
1307
|
/**
|
|
1279
1308
|
* Another way to avoid creation of intermediate Immutable maps is to create
|
|
1280
1309
|
* a mutable copy of this collection. Mutable copies *always* return `this`,
|
|
1281
1310
|
* and thus shouldn't be used for equality. Your function should never return
|
|
1282
1311
|
* a mutable copy of a collection, only use it internally to create a new
|
|
1283
|
-
* collection.
|
|
1284
|
-
*
|
|
1312
|
+
* collection.
|
|
1313
|
+
*
|
|
1314
|
+
* If possible, use `withMutations` to work with temporary mutable copies as
|
|
1315
|
+
* it provides an easier to use API and considers many common optimizations.
|
|
1285
1316
|
*
|
|
1286
1317
|
* Note: if the collection is already mutable, `asMutable` returns itself.
|
|
1287
1318
|
*
|
|
1288
1319
|
* Note: Not all methods can be used on a mutable collection or within
|
|
1289
1320
|
* `withMutations`! Read the documentation for each method to see if it
|
|
1290
1321
|
* is safe to use in `withMutations`.
|
|
1322
|
+
*
|
|
1323
|
+
* @see `Map#asImmutable`
|
|
1291
1324
|
*/
|
|
1292
1325
|
asMutable(): this;
|
|
1293
1326
|
|
|
@@ -1301,8 +1334,15 @@ declare module Immutable {
|
|
|
1301
1334
|
|
|
1302
1335
|
/**
|
|
1303
1336
|
* The yin to `asMutable`'s yang. Because it applies to mutable collections,
|
|
1304
|
-
* this operation is *mutable* and
|
|
1305
|
-
*
|
|
1337
|
+
* this operation is *mutable* and may return itself (though may not
|
|
1338
|
+
* return itself, i.e. if the result is an empty collection). Once
|
|
1339
|
+
* performed, the original mutable copy must no longer be mutated since it
|
|
1340
|
+
* may be the immutable result.
|
|
1341
|
+
*
|
|
1342
|
+
* If possible, use `withMutations` to work with temporary mutable copies as
|
|
1343
|
+
* it provides an easier to use API and considers many common optimizations.
|
|
1344
|
+
*
|
|
1345
|
+
* @see `Map#asMutable`
|
|
1306
1346
|
*/
|
|
1307
1347
|
asImmutable(): this;
|
|
1308
1348
|
|
|
@@ -1314,13 +1354,10 @@ declare module Immutable {
|
|
|
1314
1354
|
*
|
|
1315
1355
|
* Map({ a: 1, b: 2 }).map(x => 10 * x)
|
|
1316
1356
|
* // Map { a: 10, b: 20 }
|
|
1317
|
-
*
|
|
1318
|
-
* Note: `map()` always returns a new instance, even if it produced the same
|
|
1319
|
-
* value at every step.
|
|
1320
1357
|
*/
|
|
1321
1358
|
map<M>(
|
|
1322
1359
|
mapper: (value: V, key: K, iter: this) => M,
|
|
1323
|
-
context?:
|
|
1360
|
+
context?: unknown
|
|
1324
1361
|
): Map<K, M>;
|
|
1325
1362
|
|
|
1326
1363
|
/**
|
|
@@ -1328,15 +1365,19 @@ declare module Immutable {
|
|
|
1328
1365
|
*/
|
|
1329
1366
|
mapKeys<M>(
|
|
1330
1367
|
mapper: (key: K, value: V, iter: this) => M,
|
|
1331
|
-
context?:
|
|
1368
|
+
context?: unknown
|
|
1332
1369
|
): Map<M, V>;
|
|
1333
1370
|
|
|
1334
1371
|
/**
|
|
1335
1372
|
* @see Collection.Keyed.mapEntries
|
|
1336
1373
|
*/
|
|
1337
1374
|
mapEntries<KM, VM>(
|
|
1338
|
-
mapper: (
|
|
1339
|
-
|
|
1375
|
+
mapper: (
|
|
1376
|
+
entry: [K, V],
|
|
1377
|
+
index: number,
|
|
1378
|
+
iter: this
|
|
1379
|
+
) => [KM, VM] | undefined,
|
|
1380
|
+
context?: unknown
|
|
1340
1381
|
): Map<KM, VM>;
|
|
1341
1382
|
|
|
1342
1383
|
/**
|
|
@@ -1346,7 +1387,7 @@ declare module Immutable {
|
|
|
1346
1387
|
*/
|
|
1347
1388
|
flatMap<KM, VM>(
|
|
1348
1389
|
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
|
1349
|
-
context?:
|
|
1390
|
+
context?: unknown
|
|
1350
1391
|
): Map<KM, VM>;
|
|
1351
1392
|
|
|
1352
1393
|
/**
|
|
@@ -1358,11 +1399,11 @@ declare module Immutable {
|
|
|
1358
1399
|
*/
|
|
1359
1400
|
filter<F extends V>(
|
|
1360
1401
|
predicate: (value: V, key: K, iter: this) => value is F,
|
|
1361
|
-
context?:
|
|
1402
|
+
context?: unknown
|
|
1362
1403
|
): Map<K, F>;
|
|
1363
1404
|
filter(
|
|
1364
|
-
predicate: (value: V, key: K, iter: this) =>
|
|
1365
|
-
context?:
|
|
1405
|
+
predicate: (value: V, key: K, iter: this) => unknown,
|
|
1406
|
+
context?: unknown
|
|
1366
1407
|
): this;
|
|
1367
1408
|
|
|
1368
1409
|
/**
|
|
@@ -1371,7 +1412,6 @@ declare module Immutable {
|
|
|
1371
1412
|
flip(): Map<V, K>;
|
|
1372
1413
|
}
|
|
1373
1414
|
|
|
1374
|
-
|
|
1375
1415
|
/**
|
|
1376
1416
|
* A type of Map that has the additional guarantee that the iteration order of
|
|
1377
1417
|
* entries will be the order in which they were set().
|
|
@@ -1383,13 +1423,13 @@ declare module Immutable {
|
|
|
1383
1423
|
* consume more memory. `OrderedMap#set` is amortized O(log32 N), but not
|
|
1384
1424
|
* stable.
|
|
1385
1425
|
*/
|
|
1386
|
-
|
|
1387
|
-
export module OrderedMap {
|
|
1388
|
-
|
|
1426
|
+
namespace OrderedMap {
|
|
1389
1427
|
/**
|
|
1390
1428
|
* True if the provided value is an OrderedMap.
|
|
1391
1429
|
*/
|
|
1392
|
-
function isOrderedMap(
|
|
1430
|
+
function isOrderedMap(
|
|
1431
|
+
maybeOrderedMap: unknown
|
|
1432
|
+
): maybeOrderedMap is OrderedMap<unknown, unknown>;
|
|
1393
1433
|
}
|
|
1394
1434
|
|
|
1395
1435
|
/**
|
|
@@ -1404,20 +1444,39 @@ declare module Immutable {
|
|
|
1404
1444
|
* let newOrderedMap = OrderedMap({key: "value"})
|
|
1405
1445
|
* let newOrderedMap = OrderedMap([["key", "value"]])
|
|
1406
1446
|
*
|
|
1447
|
+
* Note: `OrderedMap` is a factory function and not a class, and does not use
|
|
1448
|
+
* the `new` keyword during construction.
|
|
1407
1449
|
*/
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
export function OrderedMap<V>(obj: {[key: string]: V}): OrderedMap<string, V>;
|
|
1411
|
-
export function OrderedMap<K, V>(): OrderedMap<K, V>;
|
|
1412
|
-
export function OrderedMap(): OrderedMap<any, any>;
|
|
1413
|
-
|
|
1414
|
-
export interface OrderedMap<K, V> extends Map<K, V> {
|
|
1450
|
+
function OrderedMap<K, V>(collection?: Iterable<[K, V]>): OrderedMap<K, V>;
|
|
1451
|
+
function OrderedMap<V>(obj: { [key: string]: V }): OrderedMap<string, V>;
|
|
1415
1452
|
|
|
1453
|
+
interface OrderedMap<K, V> extends Map<K, V> {
|
|
1416
1454
|
/**
|
|
1417
1455
|
* The number of entries in this OrderedMap.
|
|
1418
1456
|
*/
|
|
1419
1457
|
readonly size: number;
|
|
1420
1458
|
|
|
1459
|
+
/**
|
|
1460
|
+
* Returns a new OrderedMap also containing the new key, value pair. If an
|
|
1461
|
+
* equivalent key already exists in this OrderedMap, it will be replaced
|
|
1462
|
+
* while maintaining the existing order.
|
|
1463
|
+
*
|
|
1464
|
+
* <!-- runkit:activate -->
|
|
1465
|
+
* ```js
|
|
1466
|
+
* const { OrderedMap } = require('immutable')
|
|
1467
|
+
* const originalMap = OrderedMap({a:1, b:1, c:1})
|
|
1468
|
+
* const updatedMap = originalMap.set('b', 2)
|
|
1469
|
+
*
|
|
1470
|
+
* originalMap
|
|
1471
|
+
* // OrderedMap {a: 1, b: 1, c: 1}
|
|
1472
|
+
* updatedMap
|
|
1473
|
+
* // OrderedMap {a: 1, b: 2, c: 1}
|
|
1474
|
+
* ```
|
|
1475
|
+
*
|
|
1476
|
+
* Note: `set` can be used in `withMutations`.
|
|
1477
|
+
*/
|
|
1478
|
+
set(key: K, value: V): this;
|
|
1479
|
+
|
|
1421
1480
|
/**
|
|
1422
1481
|
* Returns a new OrderedMap resulting from merging the provided Collections
|
|
1423
1482
|
* (or JS objects) into this OrderedMap. In other words, this takes each
|
|
@@ -1428,7 +1487,7 @@ declare module Immutable {
|
|
|
1428
1487
|
*
|
|
1429
1488
|
* <!-- runkit:activate -->
|
|
1430
1489
|
* ```js
|
|
1431
|
-
* const { OrderedMap } = require('immutable
|
|
1490
|
+
* const { OrderedMap } = require('immutable')
|
|
1432
1491
|
* const one = OrderedMap({ a: 10, b: 20, c: 30 })
|
|
1433
1492
|
* const two = OrderedMap({ b: 40, a: 50, d: 60 })
|
|
1434
1493
|
* one.merge(two) // OrderedMap { "a": 50, "b": 40, "c": 30, "d": 60 }
|
|
@@ -1439,10 +1498,18 @@ declare module Immutable {
|
|
|
1439
1498
|
*
|
|
1440
1499
|
* @alias concat
|
|
1441
1500
|
*/
|
|
1442
|
-
merge<KC, VC>(
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1501
|
+
merge<KC, VC>(
|
|
1502
|
+
...collections: Array<Iterable<[KC, VC]>>
|
|
1503
|
+
): OrderedMap<K | KC, V | VC>;
|
|
1504
|
+
merge<C>(
|
|
1505
|
+
...collections: Array<{ [key: string]: C }>
|
|
1506
|
+
): OrderedMap<K | string, V | C>;
|
|
1507
|
+
concat<KC, VC>(
|
|
1508
|
+
...collections: Array<Iterable<[KC, VC]>>
|
|
1509
|
+
): OrderedMap<K | KC, V | VC>;
|
|
1510
|
+
concat<C>(
|
|
1511
|
+
...collections: Array<{ [key: string]: C }>
|
|
1512
|
+
): OrderedMap<K | string, V | C>;
|
|
1446
1513
|
|
|
1447
1514
|
// Sequence algorithms
|
|
1448
1515
|
|
|
@@ -1458,7 +1525,7 @@ declare module Immutable {
|
|
|
1458
1525
|
*/
|
|
1459
1526
|
map<M>(
|
|
1460
1527
|
mapper: (value: V, key: K, iter: this) => M,
|
|
1461
|
-
context?:
|
|
1528
|
+
context?: unknown
|
|
1462
1529
|
): OrderedMap<K, M>;
|
|
1463
1530
|
|
|
1464
1531
|
/**
|
|
@@ -1466,15 +1533,19 @@ declare module Immutable {
|
|
|
1466
1533
|
*/
|
|
1467
1534
|
mapKeys<M>(
|
|
1468
1535
|
mapper: (key: K, value: V, iter: this) => M,
|
|
1469
|
-
context?:
|
|
1536
|
+
context?: unknown
|
|
1470
1537
|
): OrderedMap<M, V>;
|
|
1471
1538
|
|
|
1472
1539
|
/**
|
|
1473
1540
|
* @see Collection.Keyed.mapEntries
|
|
1474
1541
|
*/
|
|
1475
1542
|
mapEntries<KM, VM>(
|
|
1476
|
-
mapper: (
|
|
1477
|
-
|
|
1543
|
+
mapper: (
|
|
1544
|
+
entry: [K, V],
|
|
1545
|
+
index: number,
|
|
1546
|
+
iter: this
|
|
1547
|
+
) => [KM, VM] | undefined,
|
|
1548
|
+
context?: unknown
|
|
1478
1549
|
): OrderedMap<KM, VM>;
|
|
1479
1550
|
|
|
1480
1551
|
/**
|
|
@@ -1484,7 +1555,7 @@ declare module Immutable {
|
|
|
1484
1555
|
*/
|
|
1485
1556
|
flatMap<KM, VM>(
|
|
1486
1557
|
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
|
1487
|
-
context?:
|
|
1558
|
+
context?: unknown
|
|
1488
1559
|
): OrderedMap<KM, VM>;
|
|
1489
1560
|
|
|
1490
1561
|
/**
|
|
@@ -1496,11 +1567,11 @@ declare module Immutable {
|
|
|
1496
1567
|
*/
|
|
1497
1568
|
filter<F extends V>(
|
|
1498
1569
|
predicate: (value: V, key: K, iter: this) => value is F,
|
|
1499
|
-
context?:
|
|
1570
|
+
context?: unknown
|
|
1500
1571
|
): OrderedMap<K, F>;
|
|
1501
1572
|
filter(
|
|
1502
|
-
predicate: (value: V, key: K, iter: this) =>
|
|
1503
|
-
context?:
|
|
1573
|
+
predicate: (value: V, key: K, iter: this) => unknown,
|
|
1574
|
+
context?: unknown
|
|
1504
1575
|
): this;
|
|
1505
1576
|
|
|
1506
1577
|
/**
|
|
@@ -1509,7 +1580,6 @@ declare module Immutable {
|
|
|
1509
1580
|
flip(): OrderedMap<V, K>;
|
|
1510
1581
|
}
|
|
1511
1582
|
|
|
1512
|
-
|
|
1513
1583
|
/**
|
|
1514
1584
|
* A Collection of unique values with `O(log32 N)` adds and has.
|
|
1515
1585
|
*
|
|
@@ -1521,12 +1591,11 @@ declare module Immutable {
|
|
|
1521
1591
|
* `Immutable.is`, enabling Sets to uniquely include other Immutable
|
|
1522
1592
|
* collections, custom value types, and NaN.
|
|
1523
1593
|
*/
|
|
1524
|
-
|
|
1525
|
-
|
|
1594
|
+
namespace Set {
|
|
1526
1595
|
/**
|
|
1527
1596
|
* True if the provided value is a Set
|
|
1528
1597
|
*/
|
|
1529
|
-
function isSet(maybeSet:
|
|
1598
|
+
function isSet(maybeSet: unknown): maybeSet is Set<unknown>;
|
|
1530
1599
|
|
|
1531
1600
|
/**
|
|
1532
1601
|
* Creates a new Set containing `values`.
|
|
@@ -1537,20 +1606,20 @@ declare module Immutable {
|
|
|
1537
1606
|
* `Set.fromKeys()` creates a new immutable Set containing the keys from
|
|
1538
1607
|
* this Collection or JavaScript Object.
|
|
1539
1608
|
*/
|
|
1540
|
-
function fromKeys<T>(iter: Collection<T,
|
|
1541
|
-
function fromKeys(obj: {[key: string]:
|
|
1609
|
+
function fromKeys<T>(iter: Collection<T, unknown>): Set<T>;
|
|
1610
|
+
function fromKeys(obj: { [key: string]: unknown }): Set<string>;
|
|
1542
1611
|
|
|
1543
1612
|
/**
|
|
1544
1613
|
* `Set.intersect()` creates a new immutable Set that is the intersection of
|
|
1545
1614
|
* a collection of other sets.
|
|
1546
1615
|
*
|
|
1547
1616
|
* ```js
|
|
1548
|
-
* const { Set } = require('immutable
|
|
1617
|
+
* const { Set } = require('immutable')
|
|
1549
1618
|
* const intersected = Set.intersect([
|
|
1550
1619
|
* Set([ 'a', 'b', 'c' ])
|
|
1551
1620
|
* Set([ 'c', 'a', 't' ])
|
|
1552
1621
|
* ])
|
|
1553
|
-
* // Set [ "a", "c"
|
|
1622
|
+
* // Set [ "a", "c" ]
|
|
1554
1623
|
* ```
|
|
1555
1624
|
*/
|
|
1556
1625
|
function intersect<T>(sets: Iterable<Iterable<T>>): Set<T>;
|
|
@@ -1560,12 +1629,12 @@ declare module Immutable {
|
|
|
1560
1629
|
* collection of other sets.
|
|
1561
1630
|
*
|
|
1562
1631
|
* ```js
|
|
1563
|
-
* const { Set } = require('immutable
|
|
1632
|
+
* const { Set } = require('immutable')
|
|
1564
1633
|
* const unioned = Set.union([
|
|
1565
1634
|
* Set([ 'a', 'b', 'c' ])
|
|
1566
1635
|
* Set([ 'c', 'a', 't' ])
|
|
1567
1636
|
* ])
|
|
1568
|
-
* // Set [ "a", "b", "c", "t"
|
|
1637
|
+
* // Set [ "a", "b", "c", "t" ]
|
|
1569
1638
|
* ```
|
|
1570
1639
|
*/
|
|
1571
1640
|
function union<T>(sets: Iterable<Iterable<T>>): Set<T>;
|
|
@@ -1574,13 +1643,13 @@ declare module Immutable {
|
|
|
1574
1643
|
/**
|
|
1575
1644
|
* Create a new immutable Set containing the values of the provided
|
|
1576
1645
|
* collection-like.
|
|
1646
|
+
*
|
|
1647
|
+
* Note: `Set` is a factory function and not a class, and does not use the
|
|
1648
|
+
* `new` keyword during construction.
|
|
1577
1649
|
*/
|
|
1578
|
-
|
|
1579
|
-
export function Set<T>(): Set<T>;
|
|
1580
|
-
export function Set<T>(collection: Iterable<T>): Set<T>;
|
|
1581
|
-
|
|
1582
|
-
export interface Set<T> extends Collection.Set<T> {
|
|
1650
|
+
function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Set<T>;
|
|
1583
1651
|
|
|
1652
|
+
interface Set<T> extends Collection.Set<T> {
|
|
1584
1653
|
/**
|
|
1585
1654
|
* The number of items in this Set.
|
|
1586
1655
|
*/
|
|
@@ -1638,11 +1707,17 @@ declare module Immutable {
|
|
|
1638
1707
|
/**
|
|
1639
1708
|
* Returns a Set excluding any values contained within `collections`.
|
|
1640
1709
|
*
|
|
1710
|
+
* <!-- runkit:activate -->
|
|
1711
|
+
* ```js
|
|
1712
|
+
* const { OrderedSet } = require('immutable')
|
|
1713
|
+
* OrderedSet([ 1, 2, 3 ]).subtract([1, 3])
|
|
1714
|
+
* // OrderedSet [2]
|
|
1715
|
+
* ```
|
|
1716
|
+
*
|
|
1641
1717
|
* Note: `subtract` can be used in `withMutations`.
|
|
1642
1718
|
*/
|
|
1643
1719
|
subtract(...collections: Array<Iterable<T>>): this;
|
|
1644
1720
|
|
|
1645
|
-
|
|
1646
1721
|
// Transient changes
|
|
1647
1722
|
|
|
1648
1723
|
/**
|
|
@@ -1652,7 +1727,7 @@ declare module Immutable {
|
|
|
1652
1727
|
*
|
|
1653
1728
|
* @see `Map#withMutations`
|
|
1654
1729
|
*/
|
|
1655
|
-
withMutations(mutator: (mutable: this) =>
|
|
1730
|
+
withMutations(mutator: (mutable: this) => unknown): this;
|
|
1656
1731
|
|
|
1657
1732
|
/**
|
|
1658
1733
|
* Note: Not all methods can be used on a mutable collection or within
|
|
@@ -1681,13 +1756,10 @@ declare module Immutable {
|
|
|
1681
1756
|
*
|
|
1682
1757
|
* Set([1,2]).map(x => 10 * x)
|
|
1683
1758
|
* // Set [10,20]
|
|
1684
|
-
*
|
|
1685
|
-
* Note: `map()` always returns a new instance, even if it produced the same
|
|
1686
|
-
* value at every step.
|
|
1687
1759
|
*/
|
|
1688
1760
|
map<M>(
|
|
1689
1761
|
mapper: (value: T, key: T, iter: this) => M,
|
|
1690
|
-
context?:
|
|
1762
|
+
context?: unknown
|
|
1691
1763
|
): Set<M>;
|
|
1692
1764
|
|
|
1693
1765
|
/**
|
|
@@ -1697,7 +1769,7 @@ declare module Immutable {
|
|
|
1697
1769
|
*/
|
|
1698
1770
|
flatMap<M>(
|
|
1699
1771
|
mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
|
1700
|
-
context?:
|
|
1772
|
+
context?: unknown
|
|
1701
1773
|
): Set<M>;
|
|
1702
1774
|
|
|
1703
1775
|
/**
|
|
@@ -1709,15 +1781,14 @@ declare module Immutable {
|
|
|
1709
1781
|
*/
|
|
1710
1782
|
filter<F extends T>(
|
|
1711
1783
|
predicate: (value: T, key: T, iter: this) => value is F,
|
|
1712
|
-
context?:
|
|
1784
|
+
context?: unknown
|
|
1713
1785
|
): Set<F>;
|
|
1714
1786
|
filter(
|
|
1715
|
-
predicate: (value: T, key: T, iter: this) =>
|
|
1716
|
-
context?:
|
|
1787
|
+
predicate: (value: T, key: T, iter: this) => unknown,
|
|
1788
|
+
context?: unknown
|
|
1717
1789
|
): this;
|
|
1718
1790
|
}
|
|
1719
1791
|
|
|
1720
|
-
|
|
1721
1792
|
/**
|
|
1722
1793
|
* A type of Set that has the additional guarantee that the iteration order of
|
|
1723
1794
|
* values will be the order in which they were `add`ed.
|
|
@@ -1728,12 +1799,11 @@ declare module Immutable {
|
|
|
1728
1799
|
* consume more memory. `OrderedSet#add` is amortized O(log32 N), but not
|
|
1729
1800
|
* stable.
|
|
1730
1801
|
*/
|
|
1731
|
-
|
|
1732
|
-
|
|
1802
|
+
namespace OrderedSet {
|
|
1733
1803
|
/**
|
|
1734
1804
|
* True if the provided value is an OrderedSet.
|
|
1735
1805
|
*/
|
|
1736
|
-
function isOrderedSet(maybeOrderedSet:
|
|
1806
|
+
function isOrderedSet(maybeOrderedSet: unknown): boolean;
|
|
1737
1807
|
|
|
1738
1808
|
/**
|
|
1739
1809
|
* Creates a new OrderedSet containing `values`.
|
|
@@ -1744,20 +1814,22 @@ declare module Immutable {
|
|
|
1744
1814
|
* `OrderedSet.fromKeys()` creates a new immutable OrderedSet containing
|
|
1745
1815
|
* the keys from this Collection or JavaScript Object.
|
|
1746
1816
|
*/
|
|
1747
|
-
function fromKeys<T>(iter: Collection<T,
|
|
1748
|
-
function fromKeys(obj: {[key: string]:
|
|
1817
|
+
function fromKeys<T>(iter: Collection<T, unknown>): OrderedSet<T>;
|
|
1818
|
+
function fromKeys(obj: { [key: string]: unknown }): OrderedSet<string>;
|
|
1749
1819
|
}
|
|
1750
1820
|
|
|
1751
1821
|
/**
|
|
1752
1822
|
* Create a new immutable OrderedSet containing the values of the provided
|
|
1753
1823
|
* collection-like.
|
|
1824
|
+
*
|
|
1825
|
+
* Note: `OrderedSet` is a factory function and not a class, and does not use
|
|
1826
|
+
* the `new` keyword during construction.
|
|
1754
1827
|
*/
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
export interface OrderedSet<T> extends Set<T> {
|
|
1828
|
+
function OrderedSet<T>(
|
|
1829
|
+
collection?: Iterable<T> | ArrayLike<T>
|
|
1830
|
+
): OrderedSet<T>;
|
|
1760
1831
|
|
|
1832
|
+
interface OrderedSet<T> extends Set<T> {
|
|
1761
1833
|
/**
|
|
1762
1834
|
* The number of items in this OrderedSet.
|
|
1763
1835
|
*/
|
|
@@ -1783,13 +1855,10 @@ declare module Immutable {
|
|
|
1783
1855
|
*
|
|
1784
1856
|
* OrderedSet([ 1, 2 ]).map(x => 10 * x)
|
|
1785
1857
|
* // OrderedSet [10, 20]
|
|
1786
|
-
*
|
|
1787
|
-
* Note: `map()` always returns a new instance, even if it produced the same
|
|
1788
|
-
* value at every step.
|
|
1789
1858
|
*/
|
|
1790
1859
|
map<M>(
|
|
1791
1860
|
mapper: (value: T, key: T, iter: this) => M,
|
|
1792
|
-
context?:
|
|
1861
|
+
context?: unknown
|
|
1793
1862
|
): OrderedSet<M>;
|
|
1794
1863
|
|
|
1795
1864
|
/**
|
|
@@ -1799,7 +1868,7 @@ declare module Immutable {
|
|
|
1799
1868
|
*/
|
|
1800
1869
|
flatMap<M>(
|
|
1801
1870
|
mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
|
1802
|
-
context?:
|
|
1871
|
+
context?: unknown
|
|
1803
1872
|
): OrderedSet<M>;
|
|
1804
1873
|
|
|
1805
1874
|
/**
|
|
@@ -1811,11 +1880,11 @@ declare module Immutable {
|
|
|
1811
1880
|
*/
|
|
1812
1881
|
filter<F extends T>(
|
|
1813
1882
|
predicate: (value: T, key: T, iter: this) => value is F,
|
|
1814
|
-
context?:
|
|
1883
|
+
context?: unknown
|
|
1815
1884
|
): OrderedSet<F>;
|
|
1816
1885
|
filter(
|
|
1817
|
-
predicate: (value: T, key: T, iter: this) =>
|
|
1818
|
-
context?:
|
|
1886
|
+
predicate: (value: T, key: T, iter: this) => unknown,
|
|
1887
|
+
context?: unknown
|
|
1819
1888
|
): this;
|
|
1820
1889
|
|
|
1821
1890
|
/**
|
|
@@ -1831,9 +1900,14 @@ declare module Immutable {
|
|
|
1831
1900
|
* // OrderedSet [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
1832
1901
|
* ```
|
|
1833
1902
|
*/
|
|
1834
|
-
zip<U>(other: Collection<
|
|
1835
|
-
zip<U,V>(
|
|
1836
|
-
|
|
1903
|
+
zip<U>(other: Collection<unknown, U>): OrderedSet<[T, U]>;
|
|
1904
|
+
zip<U, V>(
|
|
1905
|
+
other1: Collection<unknown, U>,
|
|
1906
|
+
other2: Collection<unknown, V>
|
|
1907
|
+
): OrderedSet<[T, U, V]>;
|
|
1908
|
+
zip(
|
|
1909
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
1910
|
+
): OrderedSet<unknown>;
|
|
1837
1911
|
|
|
1838
1912
|
/**
|
|
1839
1913
|
* Returns a OrderedSet of the same type "zipped" with the provided
|
|
@@ -1852,9 +1926,14 @@ declare module Immutable {
|
|
|
1852
1926
|
* input, some results may contain undefined values. TypeScript cannot
|
|
1853
1927
|
* account for these without cases (as of v2.5).
|
|
1854
1928
|
*/
|
|
1855
|
-
zipAll<U>(other: Collection<
|
|
1856
|
-
zipAll<U,V>(
|
|
1857
|
-
|
|
1929
|
+
zipAll<U>(other: Collection<unknown, U>): OrderedSet<[T, U]>;
|
|
1930
|
+
zipAll<U, V>(
|
|
1931
|
+
other1: Collection<unknown, U>,
|
|
1932
|
+
other2: Collection<unknown, V>
|
|
1933
|
+
): OrderedSet<[T, U, V]>;
|
|
1934
|
+
zipAll(
|
|
1935
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
1936
|
+
): OrderedSet<unknown>;
|
|
1858
1937
|
|
|
1859
1938
|
/**
|
|
1860
1939
|
* Returns an OrderedSet of the same type "zipped" with the provided
|
|
@@ -1864,21 +1943,19 @@ declare module Immutable {
|
|
|
1864
1943
|
*/
|
|
1865
1944
|
zipWith<U, Z>(
|
|
1866
1945
|
zipper: (value: T, otherValue: U) => Z,
|
|
1867
|
-
otherCollection: Collection<
|
|
1946
|
+
otherCollection: Collection<unknown, U>
|
|
1868
1947
|
): OrderedSet<Z>;
|
|
1869
1948
|
zipWith<U, V, Z>(
|
|
1870
1949
|
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
|
1871
|
-
otherCollection: Collection<
|
|
1872
|
-
thirdCollection: Collection<
|
|
1950
|
+
otherCollection: Collection<unknown, U>,
|
|
1951
|
+
thirdCollection: Collection<unknown, V>
|
|
1873
1952
|
): OrderedSet<Z>;
|
|
1874
1953
|
zipWith<Z>(
|
|
1875
|
-
zipper: (...
|
|
1876
|
-
...collections: Array<Collection<
|
|
1954
|
+
zipper: (...values: Array<unknown>) => Z,
|
|
1955
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
1877
1956
|
): OrderedSet<Z>;
|
|
1878
|
-
|
|
1879
1957
|
}
|
|
1880
1958
|
|
|
1881
|
-
|
|
1882
1959
|
/**
|
|
1883
1960
|
* Stacks are indexed collections which support very efficient O(1) addition
|
|
1884
1961
|
* and removal from the front using `unshift(v)` and `shift()`.
|
|
@@ -1892,12 +1969,11 @@ declare module Immutable {
|
|
|
1892
1969
|
*
|
|
1893
1970
|
* Stack is implemented with a Single-Linked List.
|
|
1894
1971
|
*/
|
|
1895
|
-
|
|
1896
|
-
|
|
1972
|
+
namespace Stack {
|
|
1897
1973
|
/**
|
|
1898
1974
|
* True if the provided value is a Stack
|
|
1899
1975
|
*/
|
|
1900
|
-
function isStack(maybeStack:
|
|
1976
|
+
function isStack(maybeStack: unknown): maybeStack is Stack<unknown>;
|
|
1901
1977
|
|
|
1902
1978
|
/**
|
|
1903
1979
|
* Creates a new Stack containing `values`.
|
|
@@ -1911,13 +1987,13 @@ declare module Immutable {
|
|
|
1911
1987
|
*
|
|
1912
1988
|
* The iteration order of the provided collection is preserved in the
|
|
1913
1989
|
* resulting `Stack`.
|
|
1990
|
+
*
|
|
1991
|
+
* Note: `Stack` is a factory function and not a class, and does not use the
|
|
1992
|
+
* `new` keyword during construction.
|
|
1914
1993
|
*/
|
|
1915
|
-
|
|
1916
|
-
export function Stack<T>(): Stack<T>;
|
|
1917
|
-
export function Stack<T>(collection: Iterable<T>): Stack<T>;
|
|
1918
|
-
|
|
1919
|
-
export interface Stack<T> extends Collection.Indexed<T> {
|
|
1994
|
+
function Stack<T>(collection?: Iterable<T> | ArrayLike<T>): Stack<T>;
|
|
1920
1995
|
|
|
1996
|
+
interface Stack<T> extends Collection.Indexed<T> {
|
|
1921
1997
|
/**
|
|
1922
1998
|
* The number of items in this Stack.
|
|
1923
1999
|
*/
|
|
@@ -1930,7 +2006,6 @@ declare module Immutable {
|
|
|
1930
2006
|
*/
|
|
1931
2007
|
peek(): T | undefined;
|
|
1932
2008
|
|
|
1933
|
-
|
|
1934
2009
|
// Persistent changes
|
|
1935
2010
|
|
|
1936
2011
|
/**
|
|
@@ -1984,7 +2059,6 @@ declare module Immutable {
|
|
|
1984
2059
|
*/
|
|
1985
2060
|
pop(): Stack<T>;
|
|
1986
2061
|
|
|
1987
|
-
|
|
1988
2062
|
// Transient changes
|
|
1989
2063
|
|
|
1990
2064
|
/**
|
|
@@ -1994,7 +2068,7 @@ declare module Immutable {
|
|
|
1994
2068
|
*
|
|
1995
2069
|
* @see `Map#withMutations`
|
|
1996
2070
|
*/
|
|
1997
|
-
withMutations(mutator: (mutable: this) =>
|
|
2071
|
+
withMutations(mutator: (mutable: this) => unknown): this;
|
|
1998
2072
|
|
|
1999
2073
|
/**
|
|
2000
2074
|
* Note: Not all methods can be used on a mutable collection or within
|
|
@@ -2034,7 +2108,7 @@ declare module Immutable {
|
|
|
2034
2108
|
*/
|
|
2035
2109
|
map<M>(
|
|
2036
2110
|
mapper: (value: T, key: number, iter: this) => M,
|
|
2037
|
-
context?:
|
|
2111
|
+
context?: unknown
|
|
2038
2112
|
): Stack<M>;
|
|
2039
2113
|
|
|
2040
2114
|
/**
|
|
@@ -2044,7 +2118,7 @@ declare module Immutable {
|
|
|
2044
2118
|
*/
|
|
2045
2119
|
flatMap<M>(
|
|
2046
2120
|
mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
|
2047
|
-
context?:
|
|
2121
|
+
context?: unknown
|
|
2048
2122
|
): Stack<M>;
|
|
2049
2123
|
|
|
2050
2124
|
/**
|
|
@@ -2056,11 +2130,11 @@ declare module Immutable {
|
|
|
2056
2130
|
*/
|
|
2057
2131
|
filter<F extends T>(
|
|
2058
2132
|
predicate: (value: T, index: number, iter: this) => value is F,
|
|
2059
|
-
context?:
|
|
2133
|
+
context?: unknown
|
|
2060
2134
|
): Set<F>;
|
|
2061
2135
|
filter(
|
|
2062
|
-
predicate: (value: T, index: number, iter: this) =>
|
|
2063
|
-
context?:
|
|
2136
|
+
predicate: (value: T, index: number, iter: this) => unknown,
|
|
2137
|
+
context?: unknown
|
|
2064
2138
|
): this;
|
|
2065
2139
|
|
|
2066
2140
|
/**
|
|
@@ -2074,9 +2148,12 @@ declare module Immutable {
|
|
|
2074
2148
|
* const c = a.zip(b); // Stack [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
2075
2149
|
* ```
|
|
2076
2150
|
*/
|
|
2077
|
-
zip<U>(other: Collection<
|
|
2078
|
-
zip<U,V>(
|
|
2079
|
-
|
|
2151
|
+
zip<U>(other: Collection<unknown, U>): Stack<[T, U]>;
|
|
2152
|
+
zip<U, V>(
|
|
2153
|
+
other: Collection<unknown, U>,
|
|
2154
|
+
other2: Collection<unknown, V>
|
|
2155
|
+
): Stack<[T, U, V]>;
|
|
2156
|
+
zip(...collections: Array<Collection<unknown, unknown>>): Stack<unknown>;
|
|
2080
2157
|
|
|
2081
2158
|
/**
|
|
2082
2159
|
* Returns a Stack "zipped" with the provided collections.
|
|
@@ -2094,9 +2171,12 @@ declare module Immutable {
|
|
|
2094
2171
|
* input, some results may contain undefined values. TypeScript cannot
|
|
2095
2172
|
* account for these without cases (as of v2.5).
|
|
2096
2173
|
*/
|
|
2097
|
-
zipAll<U>(other: Collection<
|
|
2098
|
-
zipAll<U,V>(
|
|
2099
|
-
|
|
2174
|
+
zipAll<U>(other: Collection<unknown, U>): Stack<[T, U]>;
|
|
2175
|
+
zipAll<U, V>(
|
|
2176
|
+
other: Collection<unknown, U>,
|
|
2177
|
+
other2: Collection<unknown, V>
|
|
2178
|
+
): Stack<[T, U, V]>;
|
|
2179
|
+
zipAll(...collections: Array<Collection<unknown, unknown>>): Stack<unknown>;
|
|
2100
2180
|
|
|
2101
2181
|
/**
|
|
2102
2182
|
* Returns a Stack "zipped" with the provided collections by using a
|
|
@@ -2111,27 +2191,29 @@ declare module Immutable {
|
|
|
2111
2191
|
*/
|
|
2112
2192
|
zipWith<U, Z>(
|
|
2113
2193
|
zipper: (value: T, otherValue: U) => Z,
|
|
2114
|
-
otherCollection: Collection<
|
|
2194
|
+
otherCollection: Collection<unknown, U>
|
|
2115
2195
|
): Stack<Z>;
|
|
2116
2196
|
zipWith<U, V, Z>(
|
|
2117
2197
|
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
|
2118
|
-
otherCollection: Collection<
|
|
2119
|
-
thirdCollection: Collection<
|
|
2198
|
+
otherCollection: Collection<unknown, U>,
|
|
2199
|
+
thirdCollection: Collection<unknown, V>
|
|
2120
2200
|
): Stack<Z>;
|
|
2121
2201
|
zipWith<Z>(
|
|
2122
|
-
zipper: (...
|
|
2123
|
-
...collections: Array<Collection<
|
|
2202
|
+
zipper: (...values: Array<unknown>) => Z,
|
|
2203
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
2124
2204
|
): Stack<Z>;
|
|
2125
2205
|
}
|
|
2126
2206
|
|
|
2127
|
-
|
|
2128
2207
|
/**
|
|
2129
2208
|
* Returns a Seq.Indexed of numbers from `start` (inclusive) to `end`
|
|
2130
2209
|
* (exclusive), by `step`, where `start` defaults to 0, `step` to 1, and `end` to
|
|
2131
2210
|
* infinity. When `start` is equal to `end`, returns empty range.
|
|
2132
2211
|
*
|
|
2212
|
+
* Note: `Range` is a factory function and not a class, and does not use the
|
|
2213
|
+
* `new` keyword during construction.
|
|
2214
|
+
*
|
|
2133
2215
|
* ```js
|
|
2134
|
-
* const { Range } = require('immutable
|
|
2216
|
+
* const { Range } = require('immutable')
|
|
2135
2217
|
* Range() // [ 0, 1, 2, 3, ... ]
|
|
2136
2218
|
* Range(10) // [ 10, 11, 12, 13, ... ]
|
|
2137
2219
|
* Range(10, 15) // [ 10, 11, 12, 13, 14 ]
|
|
@@ -2140,21 +2222,26 @@ declare module Immutable {
|
|
|
2140
2222
|
* Range(30, 30, 5) // []
|
|
2141
2223
|
* ```
|
|
2142
2224
|
*/
|
|
2143
|
-
|
|
2144
|
-
|
|
2225
|
+
function Range(
|
|
2226
|
+
start?: number,
|
|
2227
|
+
end?: number,
|
|
2228
|
+
step?: number
|
|
2229
|
+
): Seq.Indexed<number>;
|
|
2145
2230
|
|
|
2146
2231
|
/**
|
|
2147
2232
|
* Returns a Seq.Indexed of `value` repeated `times` times. When `times` is
|
|
2148
2233
|
* not defined, returns an infinite `Seq` of `value`.
|
|
2149
2234
|
*
|
|
2235
|
+
* Note: `Repeat` is a factory function and not a class, and does not use the
|
|
2236
|
+
* `new` keyword during construction.
|
|
2237
|
+
*
|
|
2150
2238
|
* ```js
|
|
2151
|
-
* const { Repeat } = require('immutable
|
|
2239
|
+
* const { Repeat } = require('immutable')
|
|
2152
2240
|
* Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
|
|
2153
2241
|
* Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
|
|
2154
2242
|
* ```
|
|
2155
2243
|
*/
|
|
2156
|
-
|
|
2157
|
-
|
|
2244
|
+
function Repeat<T>(value: T, times?: number): Seq.Indexed<T>;
|
|
2158
2245
|
|
|
2159
2246
|
/**
|
|
2160
2247
|
* A record is similar to a JS object, but enforces a specific set of allowed
|
|
@@ -2164,21 +2251,19 @@ declare module Immutable {
|
|
|
2164
2251
|
* create Record instances.
|
|
2165
2252
|
*
|
|
2166
2253
|
* ```js
|
|
2167
|
-
* const { Record } = require('immutable
|
|
2254
|
+
* const { Record } = require('immutable')
|
|
2168
2255
|
* const ABRecord = Record({ a: 1, b: 2 })
|
|
2169
|
-
* const myRecord =
|
|
2256
|
+
* const myRecord = ABRecord({ b: 3 })
|
|
2170
2257
|
* ```
|
|
2171
2258
|
*
|
|
2172
2259
|
* Records always have a value for the keys they define. `remove`ing a key
|
|
2173
2260
|
* from a record simply resets it to the default value for that key.
|
|
2174
2261
|
*
|
|
2175
2262
|
* ```js
|
|
2176
|
-
* myRecord.size // 2
|
|
2177
2263
|
* myRecord.get('a') // 1
|
|
2178
2264
|
* myRecord.get('b') // 3
|
|
2179
2265
|
* const myRecordWithoutB = myRecord.remove('b')
|
|
2180
2266
|
* myRecordWithoutB.get('b') // 2
|
|
2181
|
-
* myRecordWithoutB.size // 2
|
|
2182
2267
|
* ```
|
|
2183
2268
|
*
|
|
2184
2269
|
* Values provided to the constructor not found in the Record type will
|
|
@@ -2187,7 +2272,7 @@ declare module Immutable {
|
|
|
2187
2272
|
* ignored for this record.
|
|
2188
2273
|
*
|
|
2189
2274
|
* ```js
|
|
2190
|
-
* const myRecord =
|
|
2275
|
+
* const myRecord = ABRecord({ b: 3, x: 10 })
|
|
2191
2276
|
* myRecord.get('x') // undefined
|
|
2192
2277
|
* ```
|
|
2193
2278
|
*
|
|
@@ -2202,10 +2287,20 @@ declare module Immutable {
|
|
|
2202
2287
|
* myRecord.b = 5 // throws Error
|
|
2203
2288
|
* ```
|
|
2204
2289
|
*
|
|
2205
|
-
* Record
|
|
2290
|
+
* Record Types can be extended as well, allowing for custom methods on your
|
|
2206
2291
|
* Record. This is not a common pattern in functional environments, but is in
|
|
2207
2292
|
* many JS programs.
|
|
2208
2293
|
*
|
|
2294
|
+
* However Record Types are more restricted than typical JavaScript classes.
|
|
2295
|
+
* They do not use a class constructor, which also means they cannot use
|
|
2296
|
+
* class properties (since those are technically part of a constructor).
|
|
2297
|
+
*
|
|
2298
|
+
* While Record Types can be syntactically created with the JavaScript `class`
|
|
2299
|
+
* form, the resulting Record function is actually a factory function, not a
|
|
2300
|
+
* class constructor. Even though Record Types are not classes, JavaScript
|
|
2301
|
+
* currently requires the use of `new` when creating new Record instances if
|
|
2302
|
+
* they are defined as a `class`.
|
|
2303
|
+
*
|
|
2209
2304
|
* ```
|
|
2210
2305
|
* class ABRecord extends Record({ a: 1, b: 2 }) {
|
|
2211
2306
|
* getAB() {
|
|
@@ -2221,12 +2316,12 @@ declare module Immutable {
|
|
|
2221
2316
|
* **Flow Typing Records:**
|
|
2222
2317
|
*
|
|
2223
2318
|
* Immutable.js exports two Flow types designed to make it easier to use
|
|
2224
|
-
* Records with flow typed code, `RecordOf<
|
|
2319
|
+
* Records with flow typed code, `RecordOf<TProps>` and `RecordFactory<TProps>`.
|
|
2225
2320
|
*
|
|
2226
2321
|
* When defining a new kind of Record factory function, use a flow type that
|
|
2227
2322
|
* describes the values the record contains along with `RecordFactory<TProps>`.
|
|
2228
2323
|
* To type instances of the Record (which the factory function returns),
|
|
2229
|
-
* use `RecordOf<
|
|
2324
|
+
* use `RecordOf<TProps>`.
|
|
2230
2325
|
*
|
|
2231
2326
|
* Typically, new Record definitions will export both the Record factory
|
|
2232
2327
|
* function as well as the Record instance type for use in other code.
|
|
@@ -2236,7 +2331,8 @@ declare module Immutable {
|
|
|
2236
2331
|
*
|
|
2237
2332
|
* // Use RecordFactory<TProps> for defining new Record factory functions.
|
|
2238
2333
|
* type Point3DProps = { x: number, y: number, z: number };
|
|
2239
|
-
* const
|
|
2334
|
+
* const defaultValues: Point3DProps = { x: 0, y: 0, z: 0 };
|
|
2335
|
+
* const makePoint3D: RecordFactory<Point3DProps> = Record(defaultValues);
|
|
2240
2336
|
* export makePoint3D;
|
|
2241
2337
|
*
|
|
2242
2338
|
* // Use RecordOf<T> for defining new instances of that Record.
|
|
@@ -2244,10 +2340,34 @@ declare module Immutable {
|
|
|
2244
2340
|
* const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 });
|
|
2245
2341
|
* ```
|
|
2246
2342
|
*
|
|
2343
|
+
* **Flow Typing Record Subclasses:**
|
|
2344
|
+
*
|
|
2345
|
+
* Records can be subclassed as a means to add additional methods to Record
|
|
2346
|
+
* instances. This is generally discouraged in favor of a more functional API,
|
|
2347
|
+
* since Subclasses have some minor overhead. However the ability to create
|
|
2348
|
+
* a rich API on Record types can be quite valuable.
|
|
2349
|
+
*
|
|
2350
|
+
* When using Flow to type Subclasses, do not use `RecordFactory<TProps>`,
|
|
2351
|
+
* instead apply the props type when subclassing:
|
|
2352
|
+
*
|
|
2353
|
+
* ```js
|
|
2354
|
+
* type PersonProps = {name: string, age: number};
|
|
2355
|
+
* const defaultValues: PersonProps = {name: 'Aristotle', age: 2400};
|
|
2356
|
+
* const PersonRecord = Record(defaultValues);
|
|
2357
|
+
* class Person extends PersonRecord<PersonProps> {
|
|
2358
|
+
* getName(): string {
|
|
2359
|
+
* return this.get('name')
|
|
2360
|
+
* }
|
|
2361
|
+
*
|
|
2362
|
+
* setName(name: string): this {
|
|
2363
|
+
* return this.set('name', name);
|
|
2364
|
+
* }
|
|
2365
|
+
* }
|
|
2366
|
+
* ```
|
|
2247
2367
|
*
|
|
2248
2368
|
* **Choosing Records vs plain JavaScript objects**
|
|
2249
2369
|
*
|
|
2250
|
-
* Records
|
|
2370
|
+
* Records offer a persistently immutable alternative to plain JavaScript
|
|
2251
2371
|
* objects, however they're not required to be used within Immutable.js
|
|
2252
2372
|
* collections. In fact, the deep-access and deep-updating functions
|
|
2253
2373
|
* like `getIn()` and `setIn()` work with plain JavaScript Objects as well.
|
|
@@ -2282,12 +2402,11 @@ declare module Immutable {
|
|
|
2282
2402
|
* form isn't free. If converting Records to plain objects is common,
|
|
2283
2403
|
* consider sticking with plain objects to begin with.
|
|
2284
2404
|
*/
|
|
2285
|
-
|
|
2286
|
-
|
|
2405
|
+
namespace Record {
|
|
2287
2406
|
/**
|
|
2288
2407
|
* True if `maybeRecord` is an instance of a Record.
|
|
2289
2408
|
*/
|
|
2290
|
-
|
|
2409
|
+
function isRecord(maybeRecord: unknown): maybeRecord is Record<{}>;
|
|
2291
2410
|
|
|
2292
2411
|
/**
|
|
2293
2412
|
* Records allow passing a second parameter to supply a descriptive name
|
|
@@ -2296,7 +2415,7 @@ declare module Immutable {
|
|
|
2296
2415
|
* method. If one was not provided, the string "Record" is returned.
|
|
2297
2416
|
*
|
|
2298
2417
|
* ```js
|
|
2299
|
-
* const { Record } = require('immutable
|
|
2418
|
+
* const { Record } = require('immutable')
|
|
2300
2419
|
* const Person = Record({
|
|
2301
2420
|
* name: null
|
|
2302
2421
|
* }, 'Person')
|
|
@@ -2306,7 +2425,7 @@ declare module Immutable {
|
|
|
2306
2425
|
* Record.getDescriptiveName(me) // "Person"
|
|
2307
2426
|
* ```
|
|
2308
2427
|
*/
|
|
2309
|
-
|
|
2428
|
+
function getDescriptiveName(record: Record<any>): string;
|
|
2310
2429
|
|
|
2311
2430
|
/**
|
|
2312
2431
|
* A Record.Factory is created by the `Record()` function. Record instances
|
|
@@ -2314,7 +2433,7 @@ declare module Immutable {
|
|
|
2314
2433
|
* type:
|
|
2315
2434
|
*
|
|
2316
2435
|
* <!-- runkit:activate
|
|
2317
|
-
* { "preamble": "const { Record } = require('immutable
|
|
2436
|
+
* { "preamble": "const { Record } = require('immutable')" }
|
|
2318
2437
|
* -->
|
|
2319
2438
|
* ```js
|
|
2320
2439
|
* // makePerson is a Record Factory function
|
|
@@ -2329,7 +2448,7 @@ declare module Immutable {
|
|
|
2329
2448
|
* access on the resulting instances:
|
|
2330
2449
|
*
|
|
2331
2450
|
* <!-- runkit:activate
|
|
2332
|
-
* { "preamble": "const { Record } = require('immutable
|
|
2451
|
+
* { "preamble": "const { Record } = require('immutable');const makePerson = Record({ name: null, favoriteColor: 'unknown' });const alan = makePerson({ name: 'Alan' });" }
|
|
2333
2452
|
* -->
|
|
2334
2453
|
* ```js
|
|
2335
2454
|
* // Use the Record API
|
|
@@ -2356,14 +2475,25 @@ declare module Immutable {
|
|
|
2356
2475
|
* const alan: Person = makePerson({ name: 'Alan' });
|
|
2357
2476
|
* ```
|
|
2358
2477
|
*/
|
|
2359
|
-
|
|
2478
|
+
namespace Factory {}
|
|
2360
2479
|
|
|
2361
|
-
|
|
2362
|
-
(values?: Partial<TProps> | Iterable<[string,
|
|
2363
|
-
|
|
2480
|
+
interface Factory<TProps extends object> {
|
|
2481
|
+
(values?: Partial<TProps> | Iterable<[string, unknown]>): Record<TProps> &
|
|
2482
|
+
Readonly<TProps>;
|
|
2483
|
+
new (
|
|
2484
|
+
values?: Partial<TProps> | Iterable<[string, unknown]>
|
|
2485
|
+
): Record<TProps> & Readonly<TProps>;
|
|
2486
|
+
|
|
2487
|
+
/**
|
|
2488
|
+
* The name provided to `Record(values, name)` can be accessed with
|
|
2489
|
+
* `displayName`.
|
|
2490
|
+
*/
|
|
2491
|
+
displayName: string;
|
|
2364
2492
|
}
|
|
2365
2493
|
|
|
2366
|
-
|
|
2494
|
+
function Factory<TProps extends object>(
|
|
2495
|
+
values?: Partial<TProps> | Iterable<[string, unknown]>
|
|
2496
|
+
): Record<TProps> & Readonly<TProps>;
|
|
2367
2497
|
}
|
|
2368
2498
|
|
|
2369
2499
|
/**
|
|
@@ -2371,14 +2501,19 @@ declare module Immutable {
|
|
|
2371
2501
|
* Record Factory, which is a function that creates Record instances.
|
|
2372
2502
|
*
|
|
2373
2503
|
* See above for examples of using `Record()`.
|
|
2504
|
+
*
|
|
2505
|
+
* Note: `Record` is a factory function and not a class, and does not use the
|
|
2506
|
+
* `new` keyword during construction.
|
|
2374
2507
|
*/
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2508
|
+
function Record<TProps extends object>(
|
|
2509
|
+
defaultValues: TProps,
|
|
2510
|
+
name?: string
|
|
2511
|
+
): Record.Factory<TProps>;
|
|
2378
2512
|
|
|
2513
|
+
interface Record<TProps extends object> {
|
|
2379
2514
|
// Reading values
|
|
2380
2515
|
|
|
2381
|
-
has(key: string): key is keyof TProps;
|
|
2516
|
+
has(key: string): key is keyof TProps & string;
|
|
2382
2517
|
|
|
2383
2518
|
/**
|
|
2384
2519
|
* Returns the value associated with the provided key, which may be the
|
|
@@ -2388,32 +2523,40 @@ declare module Immutable {
|
|
|
2388
2523
|
* notSetValue will be returned if provided. Note that this scenario would
|
|
2389
2524
|
* produce an error when using Flow or TypeScript.
|
|
2390
2525
|
*/
|
|
2391
|
-
get<K extends keyof TProps>(key: K, notSetValue
|
|
2526
|
+
get<K extends keyof TProps>(key: K, notSetValue?: unknown): TProps[K];
|
|
2527
|
+
get<T>(key: string, notSetValue: T): T;
|
|
2392
2528
|
|
|
2393
2529
|
// Reading deep values
|
|
2394
2530
|
|
|
2395
|
-
hasIn(keyPath: Iterable<
|
|
2396
|
-
getIn(keyPath: Iterable<
|
|
2531
|
+
hasIn(keyPath: Iterable<unknown>): boolean;
|
|
2532
|
+
getIn(keyPath: Iterable<unknown>): unknown;
|
|
2397
2533
|
|
|
2398
2534
|
// Value equality
|
|
2399
2535
|
|
|
2400
|
-
equals(other:
|
|
2536
|
+
equals(other: unknown): boolean;
|
|
2401
2537
|
hashCode(): number;
|
|
2402
2538
|
|
|
2403
2539
|
// Persistent changes
|
|
2404
2540
|
|
|
2405
2541
|
set<K extends keyof TProps>(key: K, value: TProps[K]): this;
|
|
2406
|
-
update<K extends keyof TProps>(
|
|
2407
|
-
|
|
2408
|
-
|
|
2542
|
+
update<K extends keyof TProps>(
|
|
2543
|
+
key: K,
|
|
2544
|
+
updater: (value: TProps[K]) => TProps[K]
|
|
2545
|
+
): this;
|
|
2546
|
+
merge(
|
|
2547
|
+
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
|
2548
|
+
): this;
|
|
2549
|
+
mergeDeep(
|
|
2550
|
+
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
|
2551
|
+
): this;
|
|
2409
2552
|
|
|
2410
2553
|
mergeWith(
|
|
2411
|
-
merger: (oldVal:
|
|
2412
|
-
...collections: Array<Partial<TProps> | Iterable<[string,
|
|
2554
|
+
merger: (oldVal: unknown, newVal: unknown, key: keyof TProps) => unknown,
|
|
2555
|
+
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
|
2413
2556
|
): this;
|
|
2414
2557
|
mergeDeepWith(
|
|
2415
|
-
merger: (oldVal:
|
|
2416
|
-
...collections: Array<Partial<TProps> | Iterable<[string,
|
|
2558
|
+
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
|
2559
|
+
...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
|
2417
2560
|
): this;
|
|
2418
2561
|
|
|
2419
2562
|
/**
|
|
@@ -2433,23 +2576,32 @@ declare module Immutable {
|
|
|
2433
2576
|
|
|
2434
2577
|
// Deep persistent changes
|
|
2435
2578
|
|
|
2436
|
-
setIn(keyPath: Iterable<
|
|
2437
|
-
updateIn(
|
|
2438
|
-
|
|
2439
|
-
|
|
2579
|
+
setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
|
2580
|
+
updateIn(
|
|
2581
|
+
keyPath: Iterable<unknown>,
|
|
2582
|
+
updater: (value: unknown) => unknown
|
|
2583
|
+
): this;
|
|
2584
|
+
mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
|
|
2585
|
+
mergeDeepIn(
|
|
2586
|
+
keyPath: Iterable<unknown>,
|
|
2587
|
+
...collections: Array<unknown>
|
|
2588
|
+
): this;
|
|
2440
2589
|
|
|
2441
2590
|
/**
|
|
2442
2591
|
* @alias removeIn
|
|
2443
2592
|
*/
|
|
2444
|
-
deleteIn(keyPath: Iterable<
|
|
2445
|
-
removeIn(keyPath: Iterable<
|
|
2593
|
+
deleteIn(keyPath: Iterable<unknown>): this;
|
|
2594
|
+
removeIn(keyPath: Iterable<unknown>): this;
|
|
2446
2595
|
|
|
2447
2596
|
// Conversion to JavaScript types
|
|
2448
2597
|
|
|
2449
2598
|
/**
|
|
2450
2599
|
* Deeply converts this Record to equivalent native JavaScript Object.
|
|
2600
|
+
*
|
|
2601
|
+
* Note: This method may not be overridden. Objects with custom
|
|
2602
|
+
* serialization to plain JS may override toJSON() instead.
|
|
2451
2603
|
*/
|
|
2452
|
-
toJS(): { [K in keyof TProps]:
|
|
2604
|
+
toJS(): { [K in keyof TProps]: unknown };
|
|
2453
2605
|
|
|
2454
2606
|
/**
|
|
2455
2607
|
* Shallowly converts this Record to equivalent native JavaScript Object.
|
|
@@ -2469,7 +2621,7 @@ declare module Immutable {
|
|
|
2469
2621
|
*
|
|
2470
2622
|
* @see `Map#withMutations`
|
|
2471
2623
|
*/
|
|
2472
|
-
withMutations(mutator: (mutable: this) =>
|
|
2624
|
+
withMutations(mutator: (mutable: this) => unknown): this;
|
|
2473
2625
|
|
|
2474
2626
|
/**
|
|
2475
2627
|
* @see `Map#asMutable`
|
|
@@ -2493,6 +2645,14 @@ declare module Immutable {
|
|
|
2493
2645
|
[Symbol.iterator](): IterableIterator<[keyof TProps, TProps[keyof TProps]]>;
|
|
2494
2646
|
}
|
|
2495
2647
|
|
|
2648
|
+
/**
|
|
2649
|
+
* RecordOf<T> is used in TypeScript to define interfaces expecting an
|
|
2650
|
+
* instance of record with type T.
|
|
2651
|
+
*
|
|
2652
|
+
* This is equivalent to an instance of a record created by a Record Factory.
|
|
2653
|
+
*/
|
|
2654
|
+
type RecordOf<TProps extends object> = Record<TProps> & Readonly<TProps>;
|
|
2655
|
+
|
|
2496
2656
|
/**
|
|
2497
2657
|
* `Seq` describes a lazy operation, allowing them to efficiently chain
|
|
2498
2658
|
* use of all the higher-order collection methods (such as `map` and `filter`)
|
|
@@ -2511,7 +2671,7 @@ declare module Immutable {
|
|
|
2511
2671
|
* `Seq`'s values are never iterated:
|
|
2512
2672
|
*
|
|
2513
2673
|
* ```js
|
|
2514
|
-
* const { Seq } = require('immutable
|
|
2674
|
+
* const { Seq } = require('immutable')
|
|
2515
2675
|
* const oddSquares = Seq([ 1, 2, 3, 4, 5, 6, 7, 8 ])
|
|
2516
2676
|
* .filter(x => x % 2 !== 0)
|
|
2517
2677
|
* .map(x => x * x)
|
|
@@ -2530,7 +2690,7 @@ declare module Immutable {
|
|
|
2530
2690
|
* <!-- runkit:activate -->
|
|
2531
2691
|
* ```js
|
|
2532
2692
|
* const { Map } = require('immutable')
|
|
2533
|
-
* const map = Map({ a: 1, b: 2, c: 3 }
|
|
2693
|
+
* const map = Map({ a: 1, b: 2, c: 3 })
|
|
2534
2694
|
* const lazySeq = Seq(map)
|
|
2535
2695
|
* ```
|
|
2536
2696
|
*
|
|
@@ -2550,7 +2710,7 @@ declare module Immutable {
|
|
|
2550
2710
|
*
|
|
2551
2711
|
* <!-- runkit:activate -->
|
|
2552
2712
|
* ```js
|
|
2553
|
-
* const { Range } = require('immutable
|
|
2713
|
+
* const { Range } = require('immutable')
|
|
2554
2714
|
* Range(1, Infinity)
|
|
2555
2715
|
* .skip(1000)
|
|
2556
2716
|
* .map(n => -n)
|
|
@@ -2568,35 +2728,40 @@ declare module Immutable {
|
|
|
2568
2728
|
* ```
|
|
2569
2729
|
*/
|
|
2570
2730
|
|
|
2571
|
-
|
|
2731
|
+
namespace Seq {
|
|
2572
2732
|
/**
|
|
2573
2733
|
* True if `maybeSeq` is a Seq, it is not backed by a concrete
|
|
2574
2734
|
* structure such as Map, List, or Set.
|
|
2575
2735
|
*/
|
|
2576
|
-
function isSeq(
|
|
2577
|
-
|
|
2736
|
+
function isSeq(
|
|
2737
|
+
maybeSeq: unknown
|
|
2738
|
+
): maybeSeq is
|
|
2739
|
+
| Seq.Indexed<unknown>
|
|
2740
|
+
| Seq.Keyed<unknown, unknown>
|
|
2741
|
+
| Seq.Set<unknown>;
|
|
2578
2742
|
|
|
2579
2743
|
/**
|
|
2580
2744
|
* `Seq` which represents key-value pairs.
|
|
2581
2745
|
*/
|
|
2582
|
-
|
|
2746
|
+
namespace Keyed {}
|
|
2583
2747
|
|
|
2584
2748
|
/**
|
|
2585
2749
|
* Always returns a Seq.Keyed, if input is not keyed, expects an
|
|
2586
2750
|
* collection of [K, V] tuples.
|
|
2751
|
+
*
|
|
2752
|
+
* Note: `Seq.Keyed` is a conversion function and not a class, and does not
|
|
2753
|
+
* use the `new` keyword during construction.
|
|
2587
2754
|
*/
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
export function Keyed<K, V>(): Seq.Keyed<K, V>;
|
|
2591
|
-
export function Keyed(): Seq.Keyed<any, any>;
|
|
2755
|
+
function Keyed<K, V>(collection?: Iterable<[K, V]>): Seq.Keyed<K, V>;
|
|
2756
|
+
function Keyed<V>(obj: { [key: string]: V }): Seq.Keyed<string, V>;
|
|
2592
2757
|
|
|
2593
|
-
|
|
2758
|
+
interface Keyed<K, V> extends Seq<K, V>, Collection.Keyed<K, V> {
|
|
2594
2759
|
/**
|
|
2595
2760
|
* Deeply converts this Keyed Seq to equivalent native JavaScript Object.
|
|
2596
2761
|
*
|
|
2597
2762
|
* Converts keys to Strings.
|
|
2598
2763
|
*/
|
|
2599
|
-
toJS():
|
|
2764
|
+
toJS(): { [key: string]: unknown };
|
|
2600
2765
|
|
|
2601
2766
|
/**
|
|
2602
2767
|
* Shallowly converts this Keyed Seq to equivalent native JavaScript Object.
|
|
@@ -2621,15 +2786,19 @@ declare module Immutable {
|
|
|
2621
2786
|
* All entries will be present in the resulting Seq, even if they
|
|
2622
2787
|
* have the same key.
|
|
2623
2788
|
*/
|
|
2624
|
-
concat<KC, VC>(
|
|
2625
|
-
|
|
2789
|
+
concat<KC, VC>(
|
|
2790
|
+
...collections: Array<Iterable<[KC, VC]>>
|
|
2791
|
+
): Seq.Keyed<K | KC, V | VC>;
|
|
2792
|
+
concat<C>(
|
|
2793
|
+
...collections: Array<{ [key: string]: C }>
|
|
2794
|
+
): Seq.Keyed<K | string, V | C>;
|
|
2626
2795
|
|
|
2627
2796
|
/**
|
|
2628
2797
|
* Returns a new Seq.Keyed with values passed through a
|
|
2629
2798
|
* `mapper` function.
|
|
2630
2799
|
*
|
|
2631
2800
|
* ```js
|
|
2632
|
-
* const { Seq } = require('immutable
|
|
2801
|
+
* const { Seq } = require('immutable')
|
|
2633
2802
|
* Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
|
|
2634
2803
|
* // Seq { "a": 10, "b": 20 }
|
|
2635
2804
|
* ```
|
|
@@ -2639,7 +2808,7 @@ declare module Immutable {
|
|
|
2639
2808
|
*/
|
|
2640
2809
|
map<M>(
|
|
2641
2810
|
mapper: (value: V, key: K, iter: this) => M,
|
|
2642
|
-
context?:
|
|
2811
|
+
context?: unknown
|
|
2643
2812
|
): Seq.Keyed<K, M>;
|
|
2644
2813
|
|
|
2645
2814
|
/**
|
|
@@ -2647,15 +2816,19 @@ declare module Immutable {
|
|
|
2647
2816
|
*/
|
|
2648
2817
|
mapKeys<M>(
|
|
2649
2818
|
mapper: (key: K, value: V, iter: this) => M,
|
|
2650
|
-
context?:
|
|
2819
|
+
context?: unknown
|
|
2651
2820
|
): Seq.Keyed<M, V>;
|
|
2652
2821
|
|
|
2653
2822
|
/**
|
|
2654
2823
|
* @see Collection.Keyed.mapEntries
|
|
2655
2824
|
*/
|
|
2656
2825
|
mapEntries<KM, VM>(
|
|
2657
|
-
mapper: (
|
|
2658
|
-
|
|
2826
|
+
mapper: (
|
|
2827
|
+
entry: [K, V],
|
|
2828
|
+
index: number,
|
|
2829
|
+
iter: this
|
|
2830
|
+
) => [KM, VM] | undefined,
|
|
2831
|
+
context?: unknown
|
|
2659
2832
|
): Seq.Keyed<KM, VM>;
|
|
2660
2833
|
|
|
2661
2834
|
/**
|
|
@@ -2665,7 +2838,7 @@ declare module Immutable {
|
|
|
2665
2838
|
*/
|
|
2666
2839
|
flatMap<KM, VM>(
|
|
2667
2840
|
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
|
2668
|
-
context?:
|
|
2841
|
+
context?: unknown
|
|
2669
2842
|
): Seq.Keyed<KM, VM>;
|
|
2670
2843
|
|
|
2671
2844
|
/**
|
|
@@ -2677,25 +2850,25 @@ declare module Immutable {
|
|
|
2677
2850
|
*/
|
|
2678
2851
|
filter<F extends V>(
|
|
2679
2852
|
predicate: (value: V, key: K, iter: this) => value is F,
|
|
2680
|
-
context?:
|
|
2853
|
+
context?: unknown
|
|
2681
2854
|
): Seq.Keyed<K, F>;
|
|
2682
2855
|
filter(
|
|
2683
|
-
predicate: (value: V, key: K, iter: this) =>
|
|
2684
|
-
context?:
|
|
2856
|
+
predicate: (value: V, key: K, iter: this) => unknown,
|
|
2857
|
+
context?: unknown
|
|
2685
2858
|
): this;
|
|
2686
2859
|
|
|
2687
2860
|
/**
|
|
2688
2861
|
* @see Collection.Keyed.flip
|
|
2689
2862
|
*/
|
|
2690
2863
|
flip(): Seq.Keyed<V, K>;
|
|
2691
|
-
}
|
|
2692
2864
|
|
|
2865
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
2866
|
+
}
|
|
2693
2867
|
|
|
2694
2868
|
/**
|
|
2695
2869
|
* `Seq` which represents an ordered indexed list of values.
|
|
2696
2870
|
*/
|
|
2697
|
-
|
|
2698
|
-
|
|
2871
|
+
namespace Indexed {
|
|
2699
2872
|
/**
|
|
2700
2873
|
* Provides an Seq.Indexed of the values provided.
|
|
2701
2874
|
*/
|
|
@@ -2705,16 +2878,19 @@ declare module Immutable {
|
|
|
2705
2878
|
/**
|
|
2706
2879
|
* Always returns Seq.Indexed, discarding associated keys and
|
|
2707
2880
|
* supplying incrementing indices.
|
|
2881
|
+
*
|
|
2882
|
+
* Note: `Seq.Indexed` is a conversion function and not a class, and does
|
|
2883
|
+
* not use the `new` keyword during construction.
|
|
2708
2884
|
*/
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2885
|
+
function Indexed<T>(
|
|
2886
|
+
collection?: Iterable<T> | ArrayLike<T>
|
|
2887
|
+
): Seq.Indexed<T>;
|
|
2712
2888
|
|
|
2713
|
-
|
|
2889
|
+
interface Indexed<T> extends Seq<number, T>, Collection.Indexed<T> {
|
|
2714
2890
|
/**
|
|
2715
2891
|
* Deeply converts this Indexed Seq to equivalent native JavaScript Array.
|
|
2716
2892
|
*/
|
|
2717
|
-
toJS(): Array<
|
|
2893
|
+
toJS(): Array<unknown>;
|
|
2718
2894
|
|
|
2719
2895
|
/**
|
|
2720
2896
|
* Shallowly converts this Indexed Seq to equivalent native JavaScript Array.
|
|
@@ -2729,19 +2905,21 @@ declare module Immutable {
|
|
|
2729
2905
|
/**
|
|
2730
2906
|
* Returns itself
|
|
2731
2907
|
*/
|
|
2732
|
-
toSeq(): this
|
|
2908
|
+
toSeq(): this;
|
|
2733
2909
|
|
|
2734
2910
|
/**
|
|
2735
2911
|
* Returns a new Seq with other collections concatenated to this one.
|
|
2736
2912
|
*/
|
|
2737
|
-
concat<C>(
|
|
2913
|
+
concat<C>(
|
|
2914
|
+
...valuesOrCollections: Array<Iterable<C> | C>
|
|
2915
|
+
): Seq.Indexed<T | C>;
|
|
2738
2916
|
|
|
2739
2917
|
/**
|
|
2740
2918
|
* Returns a new Seq.Indexed with values passed through a
|
|
2741
2919
|
* `mapper` function.
|
|
2742
2920
|
*
|
|
2743
2921
|
* ```js
|
|
2744
|
-
* const { Seq } = require('immutable
|
|
2922
|
+
* const { Seq } = require('immutable')
|
|
2745
2923
|
* Seq.Indexed([ 1, 2 ]).map(x => 10 * x)
|
|
2746
2924
|
* // Seq [ 10, 20 ]
|
|
2747
2925
|
* ```
|
|
@@ -2751,7 +2929,7 @@ declare module Immutable {
|
|
|
2751
2929
|
*/
|
|
2752
2930
|
map<M>(
|
|
2753
2931
|
mapper: (value: T, key: number, iter: this) => M,
|
|
2754
|
-
context?:
|
|
2932
|
+
context?: unknown
|
|
2755
2933
|
): Seq.Indexed<M>;
|
|
2756
2934
|
|
|
2757
2935
|
/**
|
|
@@ -2761,7 +2939,7 @@ declare module Immutable {
|
|
|
2761
2939
|
*/
|
|
2762
2940
|
flatMap<M>(
|
|
2763
2941
|
mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
|
2764
|
-
context?:
|
|
2942
|
+
context?: unknown
|
|
2765
2943
|
): Seq.Indexed<M>;
|
|
2766
2944
|
|
|
2767
2945
|
/**
|
|
@@ -2773,11 +2951,11 @@ declare module Immutable {
|
|
|
2773
2951
|
*/
|
|
2774
2952
|
filter<F extends T>(
|
|
2775
2953
|
predicate: (value: T, index: number, iter: this) => value is F,
|
|
2776
|
-
context?:
|
|
2954
|
+
context?: unknown
|
|
2777
2955
|
): Seq.Indexed<F>;
|
|
2778
2956
|
filter(
|
|
2779
|
-
predicate: (value: T, index: number, iter: this) =>
|
|
2780
|
-
context?:
|
|
2957
|
+
predicate: (value: T, index: number, iter: this) => unknown,
|
|
2958
|
+
context?: unknown
|
|
2781
2959
|
): this;
|
|
2782
2960
|
|
|
2783
2961
|
/**
|
|
@@ -2791,9 +2969,14 @@ declare module Immutable {
|
|
|
2791
2969
|
* const c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
2792
2970
|
* ```
|
|
2793
2971
|
*/
|
|
2794
|
-
zip<U>(other: Collection<
|
|
2795
|
-
zip<U,V>(
|
|
2796
|
-
|
|
2972
|
+
zip<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
|
|
2973
|
+
zip<U, V>(
|
|
2974
|
+
other: Collection<unknown, U>,
|
|
2975
|
+
other2: Collection<unknown, V>
|
|
2976
|
+
): Seq.Indexed<[T, U, V]>;
|
|
2977
|
+
zip(
|
|
2978
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
2979
|
+
): Seq.Indexed<unknown>;
|
|
2797
2980
|
|
|
2798
2981
|
/**
|
|
2799
2982
|
* Returns a Seq "zipped" with the provided collections.
|
|
@@ -2807,9 +2990,14 @@ declare module Immutable {
|
|
|
2807
2990
|
* const c = a.zipAll(b); // Seq [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
|
|
2808
2991
|
* ```
|
|
2809
2992
|
*/
|
|
2810
|
-
zipAll<U>(other: Collection<
|
|
2811
|
-
zipAll<U,V>(
|
|
2812
|
-
|
|
2993
|
+
zipAll<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
|
|
2994
|
+
zipAll<U, V>(
|
|
2995
|
+
other: Collection<unknown, U>,
|
|
2996
|
+
other2: Collection<unknown, V>
|
|
2997
|
+
): Seq.Indexed<[T, U, V]>;
|
|
2998
|
+
zipAll(
|
|
2999
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
3000
|
+
): Seq.Indexed<unknown>;
|
|
2813
3001
|
|
|
2814
3002
|
/**
|
|
2815
3003
|
* Returns a Seq "zipped" with the provided collections by using a
|
|
@@ -2824,19 +3012,20 @@ declare module Immutable {
|
|
|
2824
3012
|
*/
|
|
2825
3013
|
zipWith<U, Z>(
|
|
2826
3014
|
zipper: (value: T, otherValue: U) => Z,
|
|
2827
|
-
otherCollection: Collection<
|
|
3015
|
+
otherCollection: Collection<unknown, U>
|
|
2828
3016
|
): Seq.Indexed<Z>;
|
|
2829
3017
|
zipWith<U, V, Z>(
|
|
2830
3018
|
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
|
2831
|
-
otherCollection: Collection<
|
|
2832
|
-
thirdCollection: Collection<
|
|
3019
|
+
otherCollection: Collection<unknown, U>,
|
|
3020
|
+
thirdCollection: Collection<unknown, V>
|
|
2833
3021
|
): Seq.Indexed<Z>;
|
|
2834
3022
|
zipWith<Z>(
|
|
2835
|
-
zipper: (...
|
|
2836
|
-
...collections: Array<Collection<
|
|
3023
|
+
zipper: (...values: Array<unknown>) => Z,
|
|
3024
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
2837
3025
|
): Seq.Indexed<Z>;
|
|
2838
|
-
}
|
|
2839
3026
|
|
|
3027
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
3028
|
+
}
|
|
2840
3029
|
|
|
2841
3030
|
/**
|
|
2842
3031
|
* `Seq` which represents a set of values.
|
|
@@ -2844,8 +3033,7 @@ declare module Immutable {
|
|
|
2844
3033
|
* Because `Seq` are often lazy, `Seq.Set` does not provide the same guarantee
|
|
2845
3034
|
* of value uniqueness as the concrete `Set`.
|
|
2846
3035
|
*/
|
|
2847
|
-
|
|
2848
|
-
|
|
3036
|
+
namespace Set {
|
|
2849
3037
|
/**
|
|
2850
3038
|
* Returns a Seq.Set of the provided values
|
|
2851
3039
|
*/
|
|
@@ -2854,16 +3042,17 @@ declare module Immutable {
|
|
|
2854
3042
|
|
|
2855
3043
|
/**
|
|
2856
3044
|
* Always returns a Seq.Set, discarding associated indices or keys.
|
|
3045
|
+
*
|
|
3046
|
+
* Note: `Seq.Set` is a conversion function and not a class, and does not
|
|
3047
|
+
* use the `new` keyword during construction.
|
|
2857
3048
|
*/
|
|
2858
|
-
|
|
2859
|
-
export function Set<T>(): Seq.Set<T>;
|
|
2860
|
-
export function Set<T>(collection: Iterable<T>): Seq.Set<T>;
|
|
3049
|
+
function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Seq.Set<T>;
|
|
2861
3050
|
|
|
2862
|
-
|
|
3051
|
+
interface Set<T> extends Seq<T, T>, Collection.Set<T> {
|
|
2863
3052
|
/**
|
|
2864
3053
|
* Deeply converts this Set Seq to equivalent native JavaScript Array.
|
|
2865
3054
|
*/
|
|
2866
|
-
toJS(): Array<
|
|
3055
|
+
toJS(): Array<unknown>;
|
|
2867
3056
|
|
|
2868
3057
|
/**
|
|
2869
3058
|
* Shallowly converts this Set Seq to equivalent native JavaScript Array.
|
|
@@ -2878,7 +3067,7 @@ declare module Immutable {
|
|
|
2878
3067
|
/**
|
|
2879
3068
|
* Returns itself
|
|
2880
3069
|
*/
|
|
2881
|
-
toSeq(): this
|
|
3070
|
+
toSeq(): this;
|
|
2882
3071
|
|
|
2883
3072
|
/**
|
|
2884
3073
|
* Returns a new Seq with other collections concatenated to this one.
|
|
@@ -2902,7 +3091,7 @@ declare module Immutable {
|
|
|
2902
3091
|
*/
|
|
2903
3092
|
map<M>(
|
|
2904
3093
|
mapper: (value: T, key: T, iter: this) => M,
|
|
2905
|
-
context?:
|
|
3094
|
+
context?: unknown
|
|
2906
3095
|
): Seq.Set<M>;
|
|
2907
3096
|
|
|
2908
3097
|
/**
|
|
@@ -2912,7 +3101,7 @@ declare module Immutable {
|
|
|
2912
3101
|
*/
|
|
2913
3102
|
flatMap<M>(
|
|
2914
3103
|
mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
|
2915
|
-
context?:
|
|
3104
|
+
context?: unknown
|
|
2916
3105
|
): Seq.Set<M>;
|
|
2917
3106
|
|
|
2918
3107
|
/**
|
|
@@ -2924,14 +3113,15 @@ declare module Immutable {
|
|
|
2924
3113
|
*/
|
|
2925
3114
|
filter<F extends T>(
|
|
2926
3115
|
predicate: (value: T, key: T, iter: this) => value is F,
|
|
2927
|
-
context?:
|
|
3116
|
+
context?: unknown
|
|
2928
3117
|
): Seq.Set<F>;
|
|
2929
3118
|
filter(
|
|
2930
|
-
predicate: (value: T, key: T, iter: this) =>
|
|
2931
|
-
context?:
|
|
3119
|
+
predicate: (value: T, key: T, iter: this) => unknown,
|
|
3120
|
+
context?: unknown
|
|
2932
3121
|
): this;
|
|
2933
|
-
}
|
|
2934
3122
|
|
|
3123
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
3124
|
+
}
|
|
2935
3125
|
}
|
|
2936
3126
|
|
|
2937
3127
|
/**
|
|
@@ -2942,21 +3132,27 @@ declare module Immutable {
|
|
|
2942
3132
|
* * If a `Seq`, that same `Seq`.
|
|
2943
3133
|
* * If an `Collection`, a `Seq` of the same kind (Keyed, Indexed, or Set).
|
|
2944
3134
|
* * If an Array-like, an `Seq.Indexed`.
|
|
2945
|
-
* * If an Object
|
|
2946
|
-
* * If an Iterator, an `Seq.Indexed`.
|
|
3135
|
+
* * If an Iterable Object, an `Seq.Indexed`.
|
|
2947
3136
|
* * If an Object, a `Seq.Keyed`.
|
|
2948
3137
|
*
|
|
3138
|
+
* Note: An Iterator itself will be treated as an object, becoming a `Seq.Keyed`,
|
|
3139
|
+
* which is usually not what you want. You should turn your Iterator Object into
|
|
3140
|
+
* an iterable object by defining a Symbol.iterator (or @@iterator) method which
|
|
3141
|
+
* returns `this`.
|
|
3142
|
+
*
|
|
3143
|
+
* Note: `Seq` is a conversion function and not a class, and does not use the
|
|
3144
|
+
* `new` keyword during construction.
|
|
2949
3145
|
*/
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
export interface Seq<K, V> extends Collection<K, V> {
|
|
3146
|
+
function Seq<S extends Seq<unknown, unknown>>(seq: S): S;
|
|
3147
|
+
function Seq<K, V>(collection: Collection.Keyed<K, V>): Seq.Keyed<K, V>;
|
|
3148
|
+
function Seq<T>(collection: Collection.Set<T>): Seq.Set<T>;
|
|
3149
|
+
function Seq<T>(
|
|
3150
|
+
collection: Collection.Indexed<T> | Iterable<T> | ArrayLike<T>
|
|
3151
|
+
): Seq.Indexed<T>;
|
|
3152
|
+
function Seq<V>(obj: { [key: string]: V }): Seq.Keyed<string, V>;
|
|
3153
|
+
function Seq<K = unknown, V = unknown>(): Seq<K, V>;
|
|
2959
3154
|
|
|
3155
|
+
interface Seq<K, V> extends Collection<K, V> {
|
|
2960
3156
|
/**
|
|
2961
3157
|
* Some Seqs can describe their size lazily. When this is the case,
|
|
2962
3158
|
* size will be an integer. Otherwise it will be undefined.
|
|
@@ -2969,7 +3165,6 @@ declare module Immutable {
|
|
|
2969
3165
|
*/
|
|
2970
3166
|
readonly size: number | undefined;
|
|
2971
3167
|
|
|
2972
|
-
|
|
2973
3168
|
// Force evaluation
|
|
2974
3169
|
|
|
2975
3170
|
/**
|
|
@@ -3001,7 +3196,7 @@ declare module Immutable {
|
|
|
3001
3196
|
* `mapper` function.
|
|
3002
3197
|
*
|
|
3003
3198
|
* ```js
|
|
3004
|
-
* const { Seq } = require('immutable
|
|
3199
|
+
* const { Seq } = require('immutable')
|
|
3005
3200
|
* Seq([ 1, 2 ]).map(x => 10 * x)
|
|
3006
3201
|
* // Seq [ 10, 20 ]
|
|
3007
3202
|
* ```
|
|
@@ -3011,7 +3206,7 @@ declare module Immutable {
|
|
|
3011
3206
|
*/
|
|
3012
3207
|
map<M>(
|
|
3013
3208
|
mapper: (value: V, key: K, iter: this) => M,
|
|
3014
|
-
context?:
|
|
3209
|
+
context?: unknown
|
|
3015
3210
|
): Seq<K, M>;
|
|
3016
3211
|
|
|
3017
3212
|
/**
|
|
@@ -3019,7 +3214,7 @@ declare module Immutable {
|
|
|
3019
3214
|
* `mapper` function.
|
|
3020
3215
|
*
|
|
3021
3216
|
* ```js
|
|
3022
|
-
* const { Seq } = require('immutable
|
|
3217
|
+
* const { Seq } = require('immutable')
|
|
3023
3218
|
* Seq([ 1, 2 ]).map(x => 10 * x)
|
|
3024
3219
|
* // Seq [ 10, 20 ]
|
|
3025
3220
|
* ```
|
|
@@ -3030,7 +3225,7 @@ declare module Immutable {
|
|
|
3030
3225
|
*/
|
|
3031
3226
|
map<M>(
|
|
3032
3227
|
mapper: (value: V, key: K, iter: this) => M,
|
|
3033
|
-
context?:
|
|
3228
|
+
context?: unknown
|
|
3034
3229
|
): Seq<M, M>;
|
|
3035
3230
|
|
|
3036
3231
|
/**
|
|
@@ -3040,7 +3235,7 @@ declare module Immutable {
|
|
|
3040
3235
|
*/
|
|
3041
3236
|
flatMap<M>(
|
|
3042
3237
|
mapper: (value: V, key: K, iter: this) => Iterable<M>,
|
|
3043
|
-
context?:
|
|
3238
|
+
context?: unknown
|
|
3044
3239
|
): Seq<K, M>;
|
|
3045
3240
|
|
|
3046
3241
|
/**
|
|
@@ -3051,7 +3246,7 @@ declare module Immutable {
|
|
|
3051
3246
|
*/
|
|
3052
3247
|
flatMap<M>(
|
|
3053
3248
|
mapper: (value: V, key: K, iter: this) => Iterable<M>,
|
|
3054
|
-
context?:
|
|
3249
|
+
context?: unknown
|
|
3055
3250
|
): Seq<M, M>;
|
|
3056
3251
|
|
|
3057
3252
|
/**
|
|
@@ -3063,11 +3258,11 @@ declare module Immutable {
|
|
|
3063
3258
|
*/
|
|
3064
3259
|
filter<F extends V>(
|
|
3065
3260
|
predicate: (value: V, key: K, iter: this) => value is F,
|
|
3066
|
-
context?:
|
|
3261
|
+
context?: unknown
|
|
3067
3262
|
): Seq<K, F>;
|
|
3068
3263
|
filter(
|
|
3069
|
-
predicate: (value: V, key: K, iter: this) =>
|
|
3070
|
-
context?:
|
|
3264
|
+
predicate: (value: V, key: K, iter: this) => unknown,
|
|
3265
|
+
context?: unknown
|
|
3071
3266
|
): this;
|
|
3072
3267
|
}
|
|
3073
3268
|
|
|
@@ -3085,28 +3280,34 @@ declare module Immutable {
|
|
|
3085
3280
|
* Implementations should extend one of the subclasses, `Collection.Keyed`,
|
|
3086
3281
|
* `Collection.Indexed`, or `Collection.Set`.
|
|
3087
3282
|
*/
|
|
3088
|
-
|
|
3089
|
-
|
|
3283
|
+
namespace Collection {
|
|
3090
3284
|
/**
|
|
3091
|
-
* @deprecated use `const { isKeyed } = require('immutable
|
|
3285
|
+
* @deprecated use `const { isKeyed } = require('immutable')`
|
|
3092
3286
|
*/
|
|
3093
|
-
function isKeyed(
|
|
3287
|
+
function isKeyed(
|
|
3288
|
+
maybeKeyed: unknown
|
|
3289
|
+
): maybeKeyed is Collection.Keyed<unknown, unknown>;
|
|
3094
3290
|
|
|
3095
3291
|
/**
|
|
3096
|
-
* @deprecated use `const { isIndexed } = require('immutable
|
|
3292
|
+
* @deprecated use `const { isIndexed } = require('immutable')`
|
|
3097
3293
|
*/
|
|
3098
|
-
function isIndexed(
|
|
3294
|
+
function isIndexed(
|
|
3295
|
+
maybeIndexed: unknown
|
|
3296
|
+
): maybeIndexed is Collection.Indexed<unknown>;
|
|
3099
3297
|
|
|
3100
3298
|
/**
|
|
3101
|
-
* @deprecated use `const { isAssociative } = require('immutable
|
|
3299
|
+
* @deprecated use `const { isAssociative } = require('immutable')`
|
|
3102
3300
|
*/
|
|
3103
|
-
function isAssociative(
|
|
3301
|
+
function isAssociative(
|
|
3302
|
+
maybeAssociative: unknown
|
|
3303
|
+
): maybeAssociative is
|
|
3304
|
+
| Collection.Keyed<unknown, unknown>
|
|
3305
|
+
| Collection.Indexed<unknown>;
|
|
3104
3306
|
|
|
3105
3307
|
/**
|
|
3106
|
-
* @deprecated use `const { isOrdered } = require('immutable
|
|
3308
|
+
* @deprecated use `const { isOrdered } = require('immutable')`
|
|
3107
3309
|
*/
|
|
3108
|
-
function isOrdered(maybeOrdered:
|
|
3109
|
-
|
|
3310
|
+
function isOrdered(maybeOrdered: unknown): boolean;
|
|
3110
3311
|
|
|
3111
3312
|
/**
|
|
3112
3313
|
* Keyed Collections have discrete keys tied to each value.
|
|
@@ -3115,24 +3316,27 @@ declare module Immutable {
|
|
|
3115
3316
|
* tuple, in other words, `Collection#entries` is the default iterator for
|
|
3116
3317
|
* Keyed Collections.
|
|
3117
3318
|
*/
|
|
3118
|
-
|
|
3319
|
+
namespace Keyed {}
|
|
3119
3320
|
|
|
3120
3321
|
/**
|
|
3121
3322
|
* Creates a Collection.Keyed
|
|
3122
3323
|
*
|
|
3123
3324
|
* Similar to `Collection()`, however it expects collection-likes of [K, V]
|
|
3124
3325
|
* tuples if not constructed from a Collection.Keyed or JS Object.
|
|
3326
|
+
*
|
|
3327
|
+
* Note: `Collection.Keyed` is a conversion function and not a class, and
|
|
3328
|
+
* does not use the `new` keyword during construction.
|
|
3125
3329
|
*/
|
|
3126
|
-
|
|
3127
|
-
|
|
3330
|
+
function Keyed<K, V>(collection?: Iterable<[K, V]>): Collection.Keyed<K, V>;
|
|
3331
|
+
function Keyed<V>(obj: { [key: string]: V }): Collection.Keyed<string, V>;
|
|
3128
3332
|
|
|
3129
|
-
|
|
3333
|
+
interface Keyed<K, V> extends Collection<K, V> {
|
|
3130
3334
|
/**
|
|
3131
3335
|
* Deeply converts this Keyed collection to equivalent native JavaScript Object.
|
|
3132
3336
|
*
|
|
3133
3337
|
* Converts keys to Strings.
|
|
3134
3338
|
*/
|
|
3135
|
-
toJS():
|
|
3339
|
+
toJS(): { [key: string]: unknown };
|
|
3136
3340
|
|
|
3137
3341
|
/**
|
|
3138
3342
|
* Shallowly converts this Keyed collection to equivalent native JavaScript Object.
|
|
@@ -3152,7 +3356,6 @@ declare module Immutable {
|
|
|
3152
3356
|
*/
|
|
3153
3357
|
toSeq(): Seq.Keyed<K, V>;
|
|
3154
3358
|
|
|
3155
|
-
|
|
3156
3359
|
// Sequence functions
|
|
3157
3360
|
|
|
3158
3361
|
/**
|
|
@@ -3161,7 +3364,7 @@ declare module Immutable {
|
|
|
3161
3364
|
*
|
|
3162
3365
|
* <!-- runkit:activate -->
|
|
3163
3366
|
* ```js
|
|
3164
|
-
* const { Map } = require('immutable
|
|
3367
|
+
* const { Map } = require('immutable')
|
|
3165
3368
|
* Map({ a: 'z', b: 'y' }).flip()
|
|
3166
3369
|
* // Map { "z": "a", "y": "b" }
|
|
3167
3370
|
* ```
|
|
@@ -3171,15 +3374,19 @@ declare module Immutable {
|
|
|
3171
3374
|
/**
|
|
3172
3375
|
* Returns a new Collection with other collections concatenated to this one.
|
|
3173
3376
|
*/
|
|
3174
|
-
concat<KC, VC>(
|
|
3175
|
-
|
|
3377
|
+
concat<KC, VC>(
|
|
3378
|
+
...collections: Array<Iterable<[KC, VC]>>
|
|
3379
|
+
): Collection.Keyed<K | KC, V | VC>;
|
|
3380
|
+
concat<C>(
|
|
3381
|
+
...collections: Array<{ [key: string]: C }>
|
|
3382
|
+
): Collection.Keyed<K | string, V | C>;
|
|
3176
3383
|
|
|
3177
3384
|
/**
|
|
3178
3385
|
* Returns a new Collection.Keyed with values passed through a
|
|
3179
3386
|
* `mapper` function.
|
|
3180
3387
|
*
|
|
3181
3388
|
* ```js
|
|
3182
|
-
* const { Collection } = require('immutable
|
|
3389
|
+
* const { Collection } = require('immutable')
|
|
3183
3390
|
* Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
|
|
3184
3391
|
* // Seq { "a": 10, "b": 20 }
|
|
3185
3392
|
* ```
|
|
@@ -3189,7 +3396,7 @@ declare module Immutable {
|
|
|
3189
3396
|
*/
|
|
3190
3397
|
map<M>(
|
|
3191
3398
|
mapper: (value: V, key: K, iter: this) => M,
|
|
3192
|
-
context?:
|
|
3399
|
+
context?: unknown
|
|
3193
3400
|
): Collection.Keyed<K, M>;
|
|
3194
3401
|
|
|
3195
3402
|
/**
|
|
@@ -3198,7 +3405,7 @@ declare module Immutable {
|
|
|
3198
3405
|
*
|
|
3199
3406
|
* <!-- runkit:activate -->
|
|
3200
3407
|
* ```js
|
|
3201
|
-
* const { Map } = require('immutable
|
|
3408
|
+
* const { Map } = require('immutable')
|
|
3202
3409
|
* Map({ a: 1, b: 2 }).mapKeys(x => x.toUpperCase())
|
|
3203
3410
|
* // Map { "A": 1, "B": 2 }
|
|
3204
3411
|
* ```
|
|
@@ -3208,7 +3415,7 @@ declare module Immutable {
|
|
|
3208
3415
|
*/
|
|
3209
3416
|
mapKeys<M>(
|
|
3210
3417
|
mapper: (key: K, value: V, iter: this) => M,
|
|
3211
|
-
context?:
|
|
3418
|
+
context?: unknown
|
|
3212
3419
|
): Collection.Keyed<M, V>;
|
|
3213
3420
|
|
|
3214
3421
|
/**
|
|
@@ -3217,7 +3424,7 @@ declare module Immutable {
|
|
|
3217
3424
|
*
|
|
3218
3425
|
* <!-- runkit:activate -->
|
|
3219
3426
|
* ```js
|
|
3220
|
-
* const { Map } = require('immutable
|
|
3427
|
+
* const { Map } = require('immutable')
|
|
3221
3428
|
* Map({ a: 1, b: 2 })
|
|
3222
3429
|
* .mapEntries(([ k, v ]) => [ k.toUpperCase(), v * 2 ])
|
|
3223
3430
|
* // Map { "A": 2, "B": 4 }
|
|
@@ -3225,10 +3432,16 @@ declare module Immutable {
|
|
|
3225
3432
|
*
|
|
3226
3433
|
* Note: `mapEntries()` always returns a new instance, even if it produced
|
|
3227
3434
|
* the same entry at every step.
|
|
3435
|
+
*
|
|
3436
|
+
* If the mapper function returns `undefined`, then the entry will be filtered
|
|
3228
3437
|
*/
|
|
3229
3438
|
mapEntries<KM, VM>(
|
|
3230
|
-
mapper: (
|
|
3231
|
-
|
|
3439
|
+
mapper: (
|
|
3440
|
+
entry: [K, V],
|
|
3441
|
+
index: number,
|
|
3442
|
+
iter: this
|
|
3443
|
+
) => [KM, VM] | undefined,
|
|
3444
|
+
context?: unknown
|
|
3232
3445
|
): Collection.Keyed<KM, VM>;
|
|
3233
3446
|
|
|
3234
3447
|
/**
|
|
@@ -3238,7 +3451,7 @@ declare module Immutable {
|
|
|
3238
3451
|
*/
|
|
3239
3452
|
flatMap<KM, VM>(
|
|
3240
3453
|
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
|
3241
|
-
context?:
|
|
3454
|
+
context?: unknown
|
|
3242
3455
|
): Collection.Keyed<KM, VM>;
|
|
3243
3456
|
|
|
3244
3457
|
/**
|
|
@@ -3250,17 +3463,16 @@ declare module Immutable {
|
|
|
3250
3463
|
*/
|
|
3251
3464
|
filter<F extends V>(
|
|
3252
3465
|
predicate: (value: V, key: K, iter: this) => value is F,
|
|
3253
|
-
context?:
|
|
3466
|
+
context?: unknown
|
|
3254
3467
|
): Collection.Keyed<K, F>;
|
|
3255
3468
|
filter(
|
|
3256
|
-
predicate: (value: V, key: K, iter: this) =>
|
|
3257
|
-
context?:
|
|
3469
|
+
predicate: (value: V, key: K, iter: this) => unknown,
|
|
3470
|
+
context?: unknown
|
|
3258
3471
|
): this;
|
|
3259
3472
|
|
|
3260
3473
|
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
3261
3474
|
}
|
|
3262
3475
|
|
|
3263
|
-
|
|
3264
3476
|
/**
|
|
3265
3477
|
* Indexed Collections have incrementing numeric keys. They exhibit
|
|
3266
3478
|
* slightly different behavior than `Collection.Keyed` for some methods in order
|
|
@@ -3276,18 +3488,23 @@ declare module Immutable {
|
|
|
3276
3488
|
* preserve indices, using them as keys, convert to a Collection.Keyed by
|
|
3277
3489
|
* calling `toKeyedSeq`.
|
|
3278
3490
|
*/
|
|
3279
|
-
|
|
3491
|
+
namespace Indexed {}
|
|
3280
3492
|
|
|
3281
3493
|
/**
|
|
3282
3494
|
* Creates a new Collection.Indexed.
|
|
3495
|
+
*
|
|
3496
|
+
* Note: `Collection.Indexed` is a conversion function and not a class, and
|
|
3497
|
+
* does not use the `new` keyword during construction.
|
|
3283
3498
|
*/
|
|
3284
|
-
|
|
3499
|
+
function Indexed<T>(
|
|
3500
|
+
collection?: Iterable<T> | ArrayLike<T>
|
|
3501
|
+
): Collection.Indexed<T>;
|
|
3285
3502
|
|
|
3286
|
-
|
|
3503
|
+
interface Indexed<T> extends Collection<number, T> {
|
|
3287
3504
|
/**
|
|
3288
3505
|
* Deeply converts this Indexed collection to equivalent native JavaScript Array.
|
|
3289
3506
|
*/
|
|
3290
|
-
toJS(): Array<
|
|
3507
|
+
toJS(): Array<unknown>;
|
|
3291
3508
|
|
|
3292
3509
|
/**
|
|
3293
3510
|
* Shallowly converts this Indexed collection to equivalent native JavaScript Array.
|
|
@@ -3311,7 +3528,6 @@ declare module Immutable {
|
|
|
3311
3528
|
get<NSV>(index: number, notSetValue: NSV): T | NSV;
|
|
3312
3529
|
get(index: number): T | undefined;
|
|
3313
3530
|
|
|
3314
|
-
|
|
3315
3531
|
// Conversion to Seq
|
|
3316
3532
|
|
|
3317
3533
|
/**
|
|
@@ -3324,8 +3540,7 @@ declare module Immutable {
|
|
|
3324
3540
|
* If this is a collection of [key, value] entry tuples, it will return a
|
|
3325
3541
|
* Seq.Keyed of those entries.
|
|
3326
3542
|
*/
|
|
3327
|
-
fromEntrySeq(): Seq.Keyed<
|
|
3328
|
-
|
|
3543
|
+
fromEntrySeq(): Seq.Keyed<unknown, unknown>;
|
|
3329
3544
|
|
|
3330
3545
|
// Combination
|
|
3331
3546
|
|
|
@@ -3343,25 +3558,25 @@ declare module Immutable {
|
|
|
3343
3558
|
* second from each, etc.
|
|
3344
3559
|
*
|
|
3345
3560
|
* <!-- runkit:activate
|
|
3346
|
-
* { "preamble": "require('immutable
|
|
3561
|
+
* { "preamble": "require('immutable')"}
|
|
3347
3562
|
* -->
|
|
3348
3563
|
* ```js
|
|
3349
|
-
* const { List } = require('immutable
|
|
3564
|
+
* const { List } = require('immutable')
|
|
3350
3565
|
* List([ 1, 2, 3 ]).interleave(List([ 'A', 'B', 'C' ]))
|
|
3351
|
-
* // List [ 1, "A", 2, "B", 3, "C"
|
|
3566
|
+
* // List [ 1, "A", 2, "B", 3, "C" ]
|
|
3352
3567
|
* ```
|
|
3353
3568
|
*
|
|
3354
3569
|
* The shortest Collection stops interleave.
|
|
3355
3570
|
*
|
|
3356
3571
|
* <!-- runkit:activate
|
|
3357
|
-
* { "preamble": "const { List } = require('immutable
|
|
3572
|
+
* { "preamble": "const { List } = require('immutable')" }
|
|
3358
3573
|
* -->
|
|
3359
3574
|
* ```js
|
|
3360
3575
|
* List([ 1, 2, 3 ]).interleave(
|
|
3361
3576
|
* List([ 'A', 'B' ]),
|
|
3362
3577
|
* List([ 'X', 'Y', 'Z' ])
|
|
3363
3578
|
* )
|
|
3364
|
-
* // List [ 1, "A", "X", 2, "B", "Y"
|
|
3579
|
+
* // List [ 1, "A", "X", 2, "B", "Y" ]
|
|
3365
3580
|
* ```
|
|
3366
3581
|
*
|
|
3367
3582
|
* Since `interleave()` re-indexes values, it produces a complete copy,
|
|
@@ -3369,7 +3584,7 @@ declare module Immutable {
|
|
|
3369
3584
|
*
|
|
3370
3585
|
* Note: `interleave` *cannot* be used in `withMutations`.
|
|
3371
3586
|
*/
|
|
3372
|
-
interleave(...collections: Array<Collection<
|
|
3587
|
+
interleave(...collections: Array<Collection<unknown, T>>): this;
|
|
3373
3588
|
|
|
3374
3589
|
/**
|
|
3375
3590
|
* Splice returns a new indexed Collection by replacing a region of this
|
|
@@ -3381,7 +3596,7 @@ declare module Immutable {
|
|
|
3381
3596
|
*
|
|
3382
3597
|
* <!-- runkit:activate -->
|
|
3383
3598
|
* ```js
|
|
3384
|
-
* const { List } = require('immutable
|
|
3599
|
+
* const { List } = require('immutable')
|
|
3385
3600
|
* List([ 'a', 'b', 'c', 'd' ]).splice(1, 2, 'q', 'r', 's')
|
|
3386
3601
|
* // List [ "a", "q", "r", "s", "d" ]
|
|
3387
3602
|
* ```
|
|
@@ -3391,11 +3606,7 @@ declare module Immutable {
|
|
|
3391
3606
|
*
|
|
3392
3607
|
* Note: `splice` *cannot* be used in `withMutations`.
|
|
3393
3608
|
*/
|
|
3394
|
-
splice(
|
|
3395
|
-
index: number,
|
|
3396
|
-
removeNum: number,
|
|
3397
|
-
...values: Array<T>
|
|
3398
|
-
): this;
|
|
3609
|
+
splice(index: number, removeNum: number, ...values: Array<T>): this;
|
|
3399
3610
|
|
|
3400
3611
|
/**
|
|
3401
3612
|
* Returns a Collection of the same type "zipped" with the provided
|
|
@@ -3405,7 +3616,7 @@ declare module Immutable {
|
|
|
3405
3616
|
*
|
|
3406
3617
|
*
|
|
3407
3618
|
* <!-- runkit:activate
|
|
3408
|
-
* { "preamble": "const { List } = require('immutable
|
|
3619
|
+
* { "preamble": "const { List } = require('immutable')" }
|
|
3409
3620
|
* -->
|
|
3410
3621
|
* ```js
|
|
3411
3622
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -3413,9 +3624,14 @@ declare module Immutable {
|
|
|
3413
3624
|
* const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
3414
3625
|
* ```
|
|
3415
3626
|
*/
|
|
3416
|
-
zip<U>(other: Collection<
|
|
3417
|
-
zip<U,V>(
|
|
3418
|
-
|
|
3627
|
+
zip<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
|
|
3628
|
+
zip<U, V>(
|
|
3629
|
+
other: Collection<unknown, U>,
|
|
3630
|
+
other2: Collection<unknown, V>
|
|
3631
|
+
): Collection.Indexed<[T, U, V]>;
|
|
3632
|
+
zip(
|
|
3633
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
3634
|
+
): Collection.Indexed<unknown>;
|
|
3419
3635
|
|
|
3420
3636
|
/**
|
|
3421
3637
|
* Returns a Collection "zipped" with the provided collections.
|
|
@@ -3429,16 +3645,21 @@ declare module Immutable {
|
|
|
3429
3645
|
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
|
|
3430
3646
|
* ```
|
|
3431
3647
|
*/
|
|
3432
|
-
zipAll<U>(other: Collection<
|
|
3433
|
-
zipAll<U,V>(
|
|
3434
|
-
|
|
3648
|
+
zipAll<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
|
|
3649
|
+
zipAll<U, V>(
|
|
3650
|
+
other: Collection<unknown, U>,
|
|
3651
|
+
other2: Collection<unknown, V>
|
|
3652
|
+
): Collection.Indexed<[T, U, V]>;
|
|
3653
|
+
zipAll(
|
|
3654
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
3655
|
+
): Collection.Indexed<unknown>;
|
|
3435
3656
|
|
|
3436
3657
|
/**
|
|
3437
3658
|
* Returns a Collection of the same type "zipped" with the provided
|
|
3438
3659
|
* collections by using a custom `zipper` function.
|
|
3439
3660
|
*
|
|
3440
3661
|
* <!-- runkit:activate
|
|
3441
|
-
* { "preamble": "const { List } = require('immutable
|
|
3662
|
+
* { "preamble": "const { List } = require('immutable')" }
|
|
3442
3663
|
* -->
|
|
3443
3664
|
* ```js
|
|
3444
3665
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -3449,19 +3670,18 @@ declare module Immutable {
|
|
|
3449
3670
|
*/
|
|
3450
3671
|
zipWith<U, Z>(
|
|
3451
3672
|
zipper: (value: T, otherValue: U) => Z,
|
|
3452
|
-
otherCollection: Collection<
|
|
3673
|
+
otherCollection: Collection<unknown, U>
|
|
3453
3674
|
): Collection.Indexed<Z>;
|
|
3454
3675
|
zipWith<U, V, Z>(
|
|
3455
3676
|
zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
|
3456
|
-
otherCollection: Collection<
|
|
3457
|
-
thirdCollection: Collection<
|
|
3677
|
+
otherCollection: Collection<unknown, U>,
|
|
3678
|
+
thirdCollection: Collection<unknown, V>
|
|
3458
3679
|
): Collection.Indexed<Z>;
|
|
3459
3680
|
zipWith<Z>(
|
|
3460
|
-
zipper: (...
|
|
3461
|
-
...collections: Array<Collection<
|
|
3681
|
+
zipper: (...values: Array<unknown>) => Z,
|
|
3682
|
+
...collections: Array<Collection<unknown, unknown>>
|
|
3462
3683
|
): Collection.Indexed<Z>;
|
|
3463
3684
|
|
|
3464
|
-
|
|
3465
3685
|
// Search for value
|
|
3466
3686
|
|
|
3467
3687
|
/**
|
|
@@ -3482,7 +3702,7 @@ declare module Immutable {
|
|
|
3482
3702
|
*/
|
|
3483
3703
|
findIndex(
|
|
3484
3704
|
predicate: (value: T, index: number, iter: this) => boolean,
|
|
3485
|
-
context?:
|
|
3705
|
+
context?: unknown
|
|
3486
3706
|
): number;
|
|
3487
3707
|
|
|
3488
3708
|
/**
|
|
@@ -3491,7 +3711,7 @@ declare module Immutable {
|
|
|
3491
3711
|
*/
|
|
3492
3712
|
findLastIndex(
|
|
3493
3713
|
predicate: (value: T, index: number, iter: this) => boolean,
|
|
3494
|
-
context?:
|
|
3714
|
+
context?: unknown
|
|
3495
3715
|
): number;
|
|
3496
3716
|
|
|
3497
3717
|
// Sequence algorithms
|
|
@@ -3499,14 +3719,16 @@ declare module Immutable {
|
|
|
3499
3719
|
/**
|
|
3500
3720
|
* Returns a new Collection with other collections concatenated to this one.
|
|
3501
3721
|
*/
|
|
3502
|
-
concat<C>(
|
|
3722
|
+
concat<C>(
|
|
3723
|
+
...valuesOrCollections: Array<Iterable<C> | C>
|
|
3724
|
+
): Collection.Indexed<T | C>;
|
|
3503
3725
|
|
|
3504
3726
|
/**
|
|
3505
3727
|
* Returns a new Collection.Indexed with values passed through a
|
|
3506
3728
|
* `mapper` function.
|
|
3507
3729
|
*
|
|
3508
3730
|
* ```js
|
|
3509
|
-
* const { Collection } = require('immutable
|
|
3731
|
+
* const { Collection } = require('immutable')
|
|
3510
3732
|
* Collection.Indexed([1,2]).map(x => 10 * x)
|
|
3511
3733
|
* // Seq [ 1, 2 ]
|
|
3512
3734
|
* ```
|
|
@@ -3516,7 +3738,7 @@ declare module Immutable {
|
|
|
3516
3738
|
*/
|
|
3517
3739
|
map<M>(
|
|
3518
3740
|
mapper: (value: T, key: number, iter: this) => M,
|
|
3519
|
-
context?:
|
|
3741
|
+
context?: unknown
|
|
3520
3742
|
): Collection.Indexed<M>;
|
|
3521
3743
|
|
|
3522
3744
|
/**
|
|
@@ -3526,7 +3748,7 @@ declare module Immutable {
|
|
|
3526
3748
|
*/
|
|
3527
3749
|
flatMap<M>(
|
|
3528
3750
|
mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
|
3529
|
-
context?:
|
|
3751
|
+
context?: unknown
|
|
3530
3752
|
): Collection.Indexed<M>;
|
|
3531
3753
|
|
|
3532
3754
|
/**
|
|
@@ -3538,17 +3760,16 @@ declare module Immutable {
|
|
|
3538
3760
|
*/
|
|
3539
3761
|
filter<F extends T>(
|
|
3540
3762
|
predicate: (value: T, index: number, iter: this) => value is F,
|
|
3541
|
-
context?:
|
|
3763
|
+
context?: unknown
|
|
3542
3764
|
): Collection.Indexed<F>;
|
|
3543
3765
|
filter(
|
|
3544
|
-
predicate: (value: T, index: number, iter: this) =>
|
|
3545
|
-
context?:
|
|
3766
|
+
predicate: (value: T, index: number, iter: this) => unknown,
|
|
3767
|
+
context?: unknown
|
|
3546
3768
|
): this;
|
|
3547
3769
|
|
|
3548
3770
|
[Symbol.iterator](): IterableIterator<T>;
|
|
3549
3771
|
}
|
|
3550
3772
|
|
|
3551
|
-
|
|
3552
3773
|
/**
|
|
3553
3774
|
* Set Collections only represent values. They have no associated keys or
|
|
3554
3775
|
* indices. Duplicate values are possible in the lazy `Seq.Set`s, however
|
|
@@ -3558,7 +3779,7 @@ declare module Immutable {
|
|
|
3558
3779
|
* the value as both the first and second arguments to the provided function.
|
|
3559
3780
|
*
|
|
3560
3781
|
* ```js
|
|
3561
|
-
* const { Collection } = require('immutable
|
|
3782
|
+
* const { Collection } = require('immutable')
|
|
3562
3783
|
* const seq = Collection.Set([ 'A', 'B', 'C' ])
|
|
3563
3784
|
* // Seq { "A", "B", "C" }
|
|
3564
3785
|
* seq.forEach((v, k) =>
|
|
@@ -3566,18 +3787,21 @@ declare module Immutable {
|
|
|
3566
3787
|
* )
|
|
3567
3788
|
* ```
|
|
3568
3789
|
*/
|
|
3569
|
-
|
|
3790
|
+
namespace Set {}
|
|
3570
3791
|
|
|
3571
3792
|
/**
|
|
3572
3793
|
* Similar to `Collection()`, but always returns a Collection.Set.
|
|
3794
|
+
*
|
|
3795
|
+
* Note: `Collection.Set` is a factory function and not a class, and does
|
|
3796
|
+
* not use the `new` keyword during construction.
|
|
3573
3797
|
*/
|
|
3574
|
-
|
|
3798
|
+
function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Collection.Set<T>;
|
|
3575
3799
|
|
|
3576
|
-
|
|
3800
|
+
interface Set<T> extends Collection<T, T> {
|
|
3577
3801
|
/**
|
|
3578
3802
|
* Deeply converts this Set collection to equivalent native JavaScript Array.
|
|
3579
3803
|
*/
|
|
3580
|
-
toJS(): Array<
|
|
3804
|
+
toJS(): Array<unknown>;
|
|
3581
3805
|
|
|
3582
3806
|
/**
|
|
3583
3807
|
* Shallowly converts this Set collection to equivalent native JavaScript Array.
|
|
@@ -3616,7 +3840,7 @@ declare module Immutable {
|
|
|
3616
3840
|
*/
|
|
3617
3841
|
map<M>(
|
|
3618
3842
|
mapper: (value: T, key: T, iter: this) => M,
|
|
3619
|
-
context?:
|
|
3843
|
+
context?: unknown
|
|
3620
3844
|
): Collection.Set<M>;
|
|
3621
3845
|
|
|
3622
3846
|
/**
|
|
@@ -3626,7 +3850,7 @@ declare module Immutable {
|
|
|
3626
3850
|
*/
|
|
3627
3851
|
flatMap<M>(
|
|
3628
3852
|
mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
|
3629
|
-
context?:
|
|
3853
|
+
context?: unknown
|
|
3630
3854
|
): Collection.Set<M>;
|
|
3631
3855
|
|
|
3632
3856
|
/**
|
|
@@ -3638,16 +3862,15 @@ declare module Immutable {
|
|
|
3638
3862
|
*/
|
|
3639
3863
|
filter<F extends T>(
|
|
3640
3864
|
predicate: (value: T, key: T, iter: this) => value is F,
|
|
3641
|
-
context?:
|
|
3865
|
+
context?: unknown
|
|
3642
3866
|
): Collection.Set<F>;
|
|
3643
3867
|
filter(
|
|
3644
|
-
predicate: (value: T, key: T, iter: this) =>
|
|
3645
|
-
context?:
|
|
3868
|
+
predicate: (value: T, key: T, iter: this) => unknown,
|
|
3869
|
+
context?: unknown
|
|
3646
3870
|
): this;
|
|
3647
3871
|
|
|
3648
3872
|
[Symbol.iterator](): IterableIterator<T>;
|
|
3649
3873
|
}
|
|
3650
|
-
|
|
3651
3874
|
}
|
|
3652
3875
|
|
|
3653
3876
|
/**
|
|
@@ -3657,20 +3880,31 @@ declare module Immutable {
|
|
|
3657
3880
|
*
|
|
3658
3881
|
* * If an `Collection`, that same `Collection`.
|
|
3659
3882
|
* * If an Array-like, an `Collection.Indexed`.
|
|
3660
|
-
* * If an Object with an Iterator, an `Collection.Indexed`.
|
|
3661
|
-
* * If an Iterator, an `Collection.Indexed`.
|
|
3883
|
+
* * If an Object with an Iterator defined, an `Collection.Indexed`.
|
|
3662
3884
|
* * If an Object, an `Collection.Keyed`.
|
|
3663
3885
|
*
|
|
3664
3886
|
* This methods forces the conversion of Objects and Strings to Collections.
|
|
3665
3887
|
* If you want to ensure that a Collection of one item is returned, use
|
|
3666
3888
|
* `Seq.of`.
|
|
3889
|
+
*
|
|
3890
|
+
* Note: An Iterator itself will be treated as an object, becoming a `Seq.Keyed`,
|
|
3891
|
+
* which is usually not what you want. You should turn your Iterator Object into
|
|
3892
|
+
* an iterable object by defining a Symbol.iterator (or @@iterator) method which
|
|
3893
|
+
* returns `this`.
|
|
3894
|
+
*
|
|
3895
|
+
* Note: `Collection` is a conversion function and not a class, and does not
|
|
3896
|
+
* use the `new` keyword during construction.
|
|
3667
3897
|
*/
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3898
|
+
function Collection<I extends Collection<unknown, unknown>>(collection: I): I;
|
|
3899
|
+
function Collection<T>(
|
|
3900
|
+
collection: Iterable<T> | ArrayLike<T>
|
|
3901
|
+
): Collection.Indexed<T>;
|
|
3902
|
+
function Collection<V>(obj: {
|
|
3903
|
+
[key: string]: V;
|
|
3904
|
+
}): Collection.Keyed<string, V>;
|
|
3905
|
+
function Collection<K = unknown, V = unknown>(): Collection<K, V>;
|
|
3906
|
+
|
|
3907
|
+
interface Collection<K, V> extends ValueObject {
|
|
3674
3908
|
// Value equality
|
|
3675
3909
|
|
|
3676
3910
|
/**
|
|
@@ -3680,7 +3914,7 @@ declare module Immutable {
|
|
|
3680
3914
|
* Note: This is equivalent to `Immutable.is(this, other)`, but provided to
|
|
3681
3915
|
* allow for chained expressions.
|
|
3682
3916
|
*/
|
|
3683
|
-
equals(other:
|
|
3917
|
+
equals(other: unknown): boolean;
|
|
3684
3918
|
|
|
3685
3919
|
/**
|
|
3686
3920
|
* Computes and returns the hashed identity for this Collection.
|
|
@@ -3690,7 +3924,7 @@ declare module Immutable {
|
|
|
3690
3924
|
* lookup via a different instance.
|
|
3691
3925
|
*
|
|
3692
3926
|
* <!-- runkit:activate
|
|
3693
|
-
* { "preamble": "const { Set, List } = require('immutable
|
|
3927
|
+
* { "preamble": "const { Set, List } = require('immutable')" }
|
|
3694
3928
|
* -->
|
|
3695
3929
|
* ```js
|
|
3696
3930
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -3704,11 +3938,10 @@ declare module Immutable {
|
|
|
3704
3938
|
* to be equal][Hash Collision]. If two values have different `hashCode`s,
|
|
3705
3939
|
* they must not be equal.
|
|
3706
3940
|
*
|
|
3707
|
-
* [Hash Collision]:
|
|
3941
|
+
* [Hash Collision]: https://en.wikipedia.org/wiki/Collision_(computer_science)
|
|
3708
3942
|
*/
|
|
3709
3943
|
hashCode(): number;
|
|
3710
3944
|
|
|
3711
|
-
|
|
3712
3945
|
// Reading values
|
|
3713
3946
|
|
|
3714
3947
|
/**
|
|
@@ -3737,15 +3970,20 @@ declare module Immutable {
|
|
|
3737
3970
|
contains(value: V): boolean;
|
|
3738
3971
|
|
|
3739
3972
|
/**
|
|
3740
|
-
*
|
|
3973
|
+
* In case the `Collection` is not empty returns the first element of the
|
|
3974
|
+
* `Collection`.
|
|
3975
|
+
* In case the `Collection` is empty returns the optional default
|
|
3976
|
+
* value if provided, if no default value is provided returns undefined.
|
|
3741
3977
|
*/
|
|
3742
|
-
first(): V |
|
|
3978
|
+
first<NSV = undefined>(notSetValue?: NSV): V | NSV;
|
|
3743
3979
|
|
|
3744
3980
|
/**
|
|
3745
|
-
*
|
|
3981
|
+
* In case the `Collection` is not empty returns the last element of the
|
|
3982
|
+
* `Collection`.
|
|
3983
|
+
* In case the `Collection` is empty returns the optional default
|
|
3984
|
+
* value if provided, if no default value is provided returns undefined.
|
|
3746
3985
|
*/
|
|
3747
|
-
last(): V |
|
|
3748
|
-
|
|
3986
|
+
last<NSV = undefined>(notSetValue?: NSV): V | NSV;
|
|
3749
3987
|
|
|
3750
3988
|
// Reading deep values
|
|
3751
3989
|
|
|
@@ -3755,9 +3993,9 @@ declare module Immutable {
|
|
|
3755
3993
|
*
|
|
3756
3994
|
* <!-- runkit:activate -->
|
|
3757
3995
|
* ```js
|
|
3758
|
-
* const { Map, List } = require('immutable
|
|
3996
|
+
* const { Map, List } = require('immutable')
|
|
3759
3997
|
* const deepData = Map({ x: List([ Map({ y: 123 }) ]) });
|
|
3760
|
-
* getIn(
|
|
3998
|
+
* deepData.getIn(['x', 0, 'y']) // 123
|
|
3761
3999
|
* ```
|
|
3762
4000
|
*
|
|
3763
4001
|
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
@@ -3765,18 +4003,18 @@ declare module Immutable {
|
|
|
3765
4003
|
*
|
|
3766
4004
|
* <!-- runkit:activate -->
|
|
3767
4005
|
* ```js
|
|
3768
|
-
* const { Map, List } = require('immutable
|
|
4006
|
+
* const { Map, List } = require('immutable')
|
|
3769
4007
|
* const deepData = Map({ x: [ { y: 123 } ] });
|
|
3770
|
-
* getIn(
|
|
4008
|
+
* deepData.getIn(['x', 0, 'y']) // 123
|
|
3771
4009
|
* ```
|
|
3772
4010
|
*/
|
|
3773
|
-
getIn(searchKeyPath: Iterable<
|
|
4011
|
+
getIn(searchKeyPath: Iterable<unknown>, notSetValue?: unknown): unknown;
|
|
3774
4012
|
|
|
3775
4013
|
/**
|
|
3776
4014
|
* True if the result of following a path of keys or indices through nested
|
|
3777
4015
|
* Collections results in a set value.
|
|
3778
4016
|
*/
|
|
3779
|
-
hasIn(searchKeyPath: Iterable<
|
|
4017
|
+
hasIn(searchKeyPath: Iterable<unknown>): boolean;
|
|
3780
4018
|
|
|
3781
4019
|
// Persistent changes
|
|
3782
4020
|
|
|
@@ -3788,7 +4026,7 @@ declare module Immutable {
|
|
|
3788
4026
|
*
|
|
3789
4027
|
* <!-- runkit:activate -->
|
|
3790
4028
|
* ```js
|
|
3791
|
-
* const { Seq } = require('immutable
|
|
4029
|
+
* const { Seq } = require('immutable')
|
|
3792
4030
|
*
|
|
3793
4031
|
* function sum(collection) {
|
|
3794
4032
|
* return collection.reduce((sum, x) => sum + x, 0)
|
|
@@ -3803,7 +4041,6 @@ declare module Immutable {
|
|
|
3803
4041
|
*/
|
|
3804
4042
|
update<R>(updater: (value: this) => R): R;
|
|
3805
4043
|
|
|
3806
|
-
|
|
3807
4044
|
// Conversion to JavaScript types
|
|
3808
4045
|
|
|
3809
4046
|
/**
|
|
@@ -3812,7 +4049,7 @@ declare module Immutable {
|
|
|
3812
4049
|
* `Collection.Indexed`, and `Collection.Set` become `Array`, while
|
|
3813
4050
|
* `Collection.Keyed` become `Object`, converting keys to Strings.
|
|
3814
4051
|
*/
|
|
3815
|
-
toJS(): Array<
|
|
4052
|
+
toJS(): Array<unknown> | { [key: string]: unknown };
|
|
3816
4053
|
|
|
3817
4054
|
/**
|
|
3818
4055
|
* Shallowly converts this Collection to equivalent native JavaScript Array or Object.
|
|
@@ -3837,7 +4074,6 @@ declare module Immutable {
|
|
|
3837
4074
|
*/
|
|
3838
4075
|
toObject(): { [key: string]: V };
|
|
3839
4076
|
|
|
3840
|
-
|
|
3841
4077
|
// Conversion to Collections
|
|
3842
4078
|
|
|
3843
4079
|
/**
|
|
@@ -3884,7 +4120,7 @@ declare module Immutable {
|
|
|
3884
4120
|
*
|
|
3885
4121
|
* <!-- runkit:activate -->
|
|
3886
4122
|
* ```js
|
|
3887
|
-
* const { Map, List } = require('immutable
|
|
4123
|
+
* const { Map, List } = require('immutable')
|
|
3888
4124
|
* var myMap = Map({ a: 'Apple', b: 'Banana' })
|
|
3889
4125
|
* List(myMap) // List [ [ "a", "Apple" ], [ "b", "Banana" ] ]
|
|
3890
4126
|
* myMap.toList() // List [ "Apple", "Banana" ]
|
|
@@ -3901,7 +4137,6 @@ declare module Immutable {
|
|
|
3901
4137
|
*/
|
|
3902
4138
|
toStack(): Stack<V>;
|
|
3903
4139
|
|
|
3904
|
-
|
|
3905
4140
|
// Conversion to Seq
|
|
3906
4141
|
|
|
3907
4142
|
/**
|
|
@@ -3921,7 +4156,7 @@ declare module Immutable {
|
|
|
3921
4156
|
*
|
|
3922
4157
|
* <!-- runkit:activate -->
|
|
3923
4158
|
* ```js
|
|
3924
|
-
* const { Seq } = require('immutable
|
|
4159
|
+
* const { Seq } = require('immutable')
|
|
3925
4160
|
* const indexedSeq = Seq([ 'A', 'B', 'C' ])
|
|
3926
4161
|
* // Seq [ "A", "B", "C" ]
|
|
3927
4162
|
* indexedSeq.filter(v => v === 'B')
|
|
@@ -3944,7 +4179,6 @@ declare module Immutable {
|
|
|
3944
4179
|
*/
|
|
3945
4180
|
toSetSeq(): Seq.Set<V>;
|
|
3946
4181
|
|
|
3947
|
-
|
|
3948
4182
|
// Iterators
|
|
3949
4183
|
|
|
3950
4184
|
/**
|
|
@@ -3974,6 +4208,7 @@ declare module Immutable {
|
|
|
3974
4208
|
*/
|
|
3975
4209
|
entries(): IterableIterator<[K, V]>;
|
|
3976
4210
|
|
|
4211
|
+
[Symbol.iterator](): IterableIterator<unknown>;
|
|
3977
4212
|
|
|
3978
4213
|
// Collections (Seq)
|
|
3979
4214
|
|
|
@@ -3993,7 +4228,6 @@ declare module Immutable {
|
|
|
3993
4228
|
*/
|
|
3994
4229
|
entrySeq(): Seq.Indexed<[K, V]>;
|
|
3995
4230
|
|
|
3996
|
-
|
|
3997
4231
|
// Sequence algorithms
|
|
3998
4232
|
|
|
3999
4233
|
/**
|
|
@@ -4002,7 +4236,7 @@ declare module Immutable {
|
|
|
4002
4236
|
*
|
|
4003
4237
|
* <!-- runkit:activate -->
|
|
4004
4238
|
* ```js
|
|
4005
|
-
* const { Collection } = require('immutable
|
|
4239
|
+
* const { Collection } = require('immutable')
|
|
4006
4240
|
* Collection({ a: 1, b: 2 }).map(x => 10 * x)
|
|
4007
4241
|
* // Seq { "a": 10, "b": 20 }
|
|
4008
4242
|
* ```
|
|
@@ -4012,7 +4246,7 @@ declare module Immutable {
|
|
|
4012
4246
|
*/
|
|
4013
4247
|
map<M>(
|
|
4014
4248
|
mapper: (value: V, key: K, iter: this) => M,
|
|
4015
|
-
context?:
|
|
4249
|
+
context?: unknown
|
|
4016
4250
|
): Collection<K, M>;
|
|
4017
4251
|
|
|
4018
4252
|
/**
|
|
@@ -4021,7 +4255,7 @@ declare module Immutable {
|
|
|
4021
4255
|
*
|
|
4022
4256
|
* @ignore
|
|
4023
4257
|
*/
|
|
4024
|
-
map
|
|
4258
|
+
map(...args: Array<never>): unknown;
|
|
4025
4259
|
|
|
4026
4260
|
/**
|
|
4027
4261
|
* Returns a new Collection of the same type with only the entries for which
|
|
@@ -4029,7 +4263,7 @@ declare module Immutable {
|
|
|
4029
4263
|
*
|
|
4030
4264
|
* <!-- runkit:activate -->
|
|
4031
4265
|
* ```js
|
|
4032
|
-
* const { Map } = require('immutable
|
|
4266
|
+
* const { Map } = require('immutable')
|
|
4033
4267
|
* Map({ a: 1, b: 2, c: 3, d: 4}).filter(x => x % 2 === 0)
|
|
4034
4268
|
* // Map { "b": 2, "d": 4 }
|
|
4035
4269
|
* ```
|
|
@@ -4039,11 +4273,11 @@ declare module Immutable {
|
|
|
4039
4273
|
*/
|
|
4040
4274
|
filter<F extends V>(
|
|
4041
4275
|
predicate: (value: V, key: K, iter: this) => value is F,
|
|
4042
|
-
context?:
|
|
4276
|
+
context?: unknown
|
|
4043
4277
|
): Collection<K, F>;
|
|
4044
4278
|
filter(
|
|
4045
|
-
predicate: (value: V, key: K, iter: this) =>
|
|
4046
|
-
context?:
|
|
4279
|
+
predicate: (value: V, key: K, iter: this) => unknown,
|
|
4280
|
+
context?: unknown
|
|
4047
4281
|
): this;
|
|
4048
4282
|
|
|
4049
4283
|
/**
|
|
@@ -4052,7 +4286,7 @@ declare module Immutable {
|
|
|
4052
4286
|
*
|
|
4053
4287
|
* <!-- runkit:activate -->
|
|
4054
4288
|
* ```js
|
|
4055
|
-
* const { Map } = require('immutable
|
|
4289
|
+
* const { Map } = require('immutable')
|
|
4056
4290
|
* Map({ a: 1, b: 2, c: 3, d: 4}).filterNot(x => x % 2 === 0)
|
|
4057
4291
|
* // Map { "a": 1, "c": 3 }
|
|
4058
4292
|
* ```
|
|
@@ -4062,7 +4296,7 @@ declare module Immutable {
|
|
|
4062
4296
|
*/
|
|
4063
4297
|
filterNot(
|
|
4064
4298
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4065
|
-
context?:
|
|
4299
|
+
context?: unknown
|
|
4066
4300
|
): this;
|
|
4067
4301
|
|
|
4068
4302
|
/**
|
|
@@ -4089,7 +4323,7 @@ declare module Immutable {
|
|
|
4089
4323
|
*
|
|
4090
4324
|
* <!-- runkit:activate -->
|
|
4091
4325
|
* ```js
|
|
4092
|
-
* const { Map } = require('immutable
|
|
4326
|
+
* const { Map } = require('immutable')
|
|
4093
4327
|
* Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
|
|
4094
4328
|
* if (a < b) { return -1; }
|
|
4095
4329
|
* if (a > b) { return 1; }
|
|
@@ -4109,7 +4343,17 @@ declare module Immutable {
|
|
|
4109
4343
|
* Like `sort`, but also accepts a `comparatorValueMapper` which allows for
|
|
4110
4344
|
* sorting by more sophisticated means:
|
|
4111
4345
|
*
|
|
4112
|
-
*
|
|
4346
|
+
* <!-- runkit:activate -->
|
|
4347
|
+
* ```js
|
|
4348
|
+
* const { Map } = require('immutable')
|
|
4349
|
+
* const beattles = Map({
|
|
4350
|
+
* John: { name: "Lennon" },
|
|
4351
|
+
* Paul: { name: "McCartney" },
|
|
4352
|
+
* George: { name: "Harrison" },
|
|
4353
|
+
* Ringo: { name: "Starr" },
|
|
4354
|
+
* });
|
|
4355
|
+
* beattles.sortBy(member => member.name);
|
|
4356
|
+
* ```
|
|
4113
4357
|
*
|
|
4114
4358
|
* Note: `sortBy()` Always returns a new instance, even if the original was
|
|
4115
4359
|
* already sorted.
|
|
@@ -4129,7 +4373,7 @@ declare module Immutable {
|
|
|
4129
4373
|
*
|
|
4130
4374
|
* <!-- runkit:activate -->
|
|
4131
4375
|
* ```js
|
|
4132
|
-
* const { List, Map } = require('immutable
|
|
4376
|
+
* const { List, Map } = require('immutable')
|
|
4133
4377
|
* const listOfMaps = List([
|
|
4134
4378
|
* Map({ v: 0 }),
|
|
4135
4379
|
* Map({ v: 1 }),
|
|
@@ -4147,9 +4391,8 @@ declare module Immutable {
|
|
|
4147
4391
|
*/
|
|
4148
4392
|
groupBy<G>(
|
|
4149
4393
|
grouper: (value: V, key: K, iter: this) => G,
|
|
4150
|
-
context?:
|
|
4151
|
-
): /*Map*/Seq.Keyed<G, /*this*/Collection<K, V>>;
|
|
4152
|
-
|
|
4394
|
+
context?: unknown
|
|
4395
|
+
): /*Map*/ Seq.Keyed<G, /*this*/ Collection<K, V>>;
|
|
4153
4396
|
|
|
4154
4397
|
// Side effects
|
|
4155
4398
|
|
|
@@ -4161,11 +4404,10 @@ declare module Immutable {
|
|
|
4161
4404
|
* (including the last iteration which returned false).
|
|
4162
4405
|
*/
|
|
4163
4406
|
forEach(
|
|
4164
|
-
sideEffect: (value: V, key: K, iter: this) =>
|
|
4165
|
-
context?:
|
|
4407
|
+
sideEffect: (value: V, key: K, iter: this) => unknown,
|
|
4408
|
+
context?: unknown
|
|
4166
4409
|
): number;
|
|
4167
4410
|
|
|
4168
|
-
|
|
4169
4411
|
// Creating subsets
|
|
4170
4412
|
|
|
4171
4413
|
/**
|
|
@@ -4216,15 +4458,15 @@ declare module Immutable {
|
|
|
4216
4458
|
*
|
|
4217
4459
|
* <!-- runkit:activate -->
|
|
4218
4460
|
* ```js
|
|
4219
|
-
* const { List } = require('immutable
|
|
4461
|
+
* const { List } = require('immutable')
|
|
4220
4462
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4221
4463
|
* .skipWhile(x => x.match(/g/))
|
|
4222
|
-
* // List [ "cat", "hat", "god"
|
|
4464
|
+
* // List [ "cat", "hat", "god" ]
|
|
4223
4465
|
* ```
|
|
4224
4466
|
*/
|
|
4225
4467
|
skipWhile(
|
|
4226
4468
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4227
|
-
context?:
|
|
4469
|
+
context?: unknown
|
|
4228
4470
|
): this;
|
|
4229
4471
|
|
|
4230
4472
|
/**
|
|
@@ -4233,15 +4475,15 @@ declare module Immutable {
|
|
|
4233
4475
|
*
|
|
4234
4476
|
* <!-- runkit:activate -->
|
|
4235
4477
|
* ```js
|
|
4236
|
-
* const { List } = require('immutable
|
|
4478
|
+
* const { List } = require('immutable')
|
|
4237
4479
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4238
4480
|
* .skipUntil(x => x.match(/hat/))
|
|
4239
|
-
* // List [ "hat", "god"
|
|
4481
|
+
* // List [ "hat", "god" ]
|
|
4240
4482
|
* ```
|
|
4241
4483
|
*/
|
|
4242
4484
|
skipUntil(
|
|
4243
4485
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4244
|
-
context?:
|
|
4486
|
+
context?: unknown
|
|
4245
4487
|
): this;
|
|
4246
4488
|
|
|
4247
4489
|
/**
|
|
@@ -4262,7 +4504,7 @@ declare module Immutable {
|
|
|
4262
4504
|
*
|
|
4263
4505
|
* <!-- runkit:activate -->
|
|
4264
4506
|
* ```js
|
|
4265
|
-
* const { List } = require('immutable
|
|
4507
|
+
* const { List } = require('immutable')
|
|
4266
4508
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4267
4509
|
* .takeWhile(x => x.match(/o/))
|
|
4268
4510
|
* // List [ "dog", "frog" ]
|
|
@@ -4270,7 +4512,7 @@ declare module Immutable {
|
|
|
4270
4512
|
*/
|
|
4271
4513
|
takeWhile(
|
|
4272
4514
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4273
|
-
context?:
|
|
4515
|
+
context?: unknown
|
|
4274
4516
|
): this;
|
|
4275
4517
|
|
|
4276
4518
|
/**
|
|
@@ -4279,7 +4521,7 @@ declare module Immutable {
|
|
|
4279
4521
|
*
|
|
4280
4522
|
* <!-- runkit:activate -->
|
|
4281
4523
|
* ```js
|
|
4282
|
-
* const { List } = require('immutable
|
|
4524
|
+
* const { List } = require('immutable')
|
|
4283
4525
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4284
4526
|
* .takeUntil(x => x.match(/at/))
|
|
4285
4527
|
* // List [ "dog", "frog" ]
|
|
@@ -4287,10 +4529,9 @@ declare module Immutable {
|
|
|
4287
4529
|
*/
|
|
4288
4530
|
takeUntil(
|
|
4289
4531
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4290
|
-
context?:
|
|
4532
|
+
context?: unknown
|
|
4291
4533
|
): this;
|
|
4292
4534
|
|
|
4293
|
-
|
|
4294
4535
|
// Combination
|
|
4295
4536
|
|
|
4296
4537
|
/**
|
|
@@ -4300,7 +4541,9 @@ declare module Immutable {
|
|
|
4300
4541
|
* For Seqs, all entries will be present in the resulting Seq, even if they
|
|
4301
4542
|
* have the same key.
|
|
4302
4543
|
*/
|
|
4303
|
-
concat(
|
|
4544
|
+
concat(
|
|
4545
|
+
...valuesOrCollections: Array<unknown>
|
|
4546
|
+
): Collection<unknown, unknown>;
|
|
4304
4547
|
|
|
4305
4548
|
/**
|
|
4306
4549
|
* Flattens nested Collections.
|
|
@@ -4312,11 +4555,12 @@ declare module Immutable {
|
|
|
4312
4555
|
*
|
|
4313
4556
|
* Flattens only others Collection, not Arrays or Objects.
|
|
4314
4557
|
*
|
|
4315
|
-
* Note: `flatten(true)` operates on Collection<
|
|
4558
|
+
* Note: `flatten(true)` operates on Collection<unknown, Collection<K, V>> and
|
|
4316
4559
|
* returns Collection<K, V>
|
|
4317
4560
|
*/
|
|
4318
|
-
flatten(depth?: number): Collection<
|
|
4319
|
-
|
|
4561
|
+
flatten(depth?: number): Collection<unknown, unknown>;
|
|
4562
|
+
// tslint:disable-next-line unified-signatures
|
|
4563
|
+
flatten(shallow?: boolean): Collection<unknown, unknown>;
|
|
4320
4564
|
|
|
4321
4565
|
/**
|
|
4322
4566
|
* Flat-maps the Collection, returning a Collection of the same type.
|
|
@@ -4325,7 +4569,7 @@ declare module Immutable {
|
|
|
4325
4569
|
*/
|
|
4326
4570
|
flatMap<M>(
|
|
4327
4571
|
mapper: (value: V, key: K, iter: this) => Iterable<M>,
|
|
4328
|
-
context?:
|
|
4572
|
+
context?: unknown
|
|
4329
4573
|
): Collection<K, M>;
|
|
4330
4574
|
|
|
4331
4575
|
/**
|
|
@@ -4336,7 +4580,7 @@ declare module Immutable {
|
|
|
4336
4580
|
*/
|
|
4337
4581
|
flatMap<KM, VM>(
|
|
4338
4582
|
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
|
4339
|
-
context?:
|
|
4583
|
+
context?: unknown
|
|
4340
4584
|
): Collection<KM, VM>;
|
|
4341
4585
|
|
|
4342
4586
|
// Reducing a value
|
|
@@ -4353,7 +4597,7 @@ declare module Immutable {
|
|
|
4353
4597
|
reduce<R>(
|
|
4354
4598
|
reducer: (reduction: R, value: V, key: K, iter: this) => R,
|
|
4355
4599
|
initialReduction: R,
|
|
4356
|
-
context?:
|
|
4600
|
+
context?: unknown
|
|
4357
4601
|
): R;
|
|
4358
4602
|
reduce<R>(
|
|
4359
4603
|
reducer: (reduction: V | R, value: V, key: K, iter: this) => R
|
|
@@ -4368,7 +4612,7 @@ declare module Immutable {
|
|
|
4368
4612
|
reduceRight<R>(
|
|
4369
4613
|
reducer: (reduction: R, value: V, key: K, iter: this) => R,
|
|
4370
4614
|
initialReduction: R,
|
|
4371
|
-
context?:
|
|
4615
|
+
context?: unknown
|
|
4372
4616
|
): R;
|
|
4373
4617
|
reduceRight<R>(
|
|
4374
4618
|
reducer: (reduction: V | R, value: V, key: K, iter: this) => R
|
|
@@ -4379,7 +4623,7 @@ declare module Immutable {
|
|
|
4379
4623
|
*/
|
|
4380
4624
|
every(
|
|
4381
4625
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4382
|
-
context?:
|
|
4626
|
+
context?: unknown
|
|
4383
4627
|
): boolean;
|
|
4384
4628
|
|
|
4385
4629
|
/**
|
|
@@ -4387,7 +4631,7 @@ declare module Immutable {
|
|
|
4387
4631
|
*/
|
|
4388
4632
|
some(
|
|
4389
4633
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4390
|
-
context?:
|
|
4634
|
+
context?: unknown
|
|
4391
4635
|
): boolean;
|
|
4392
4636
|
|
|
4393
4637
|
/**
|
|
@@ -4417,7 +4661,7 @@ declare module Immutable {
|
|
|
4417
4661
|
count(): number;
|
|
4418
4662
|
count(
|
|
4419
4663
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4420
|
-
context?:
|
|
4664
|
+
context?: unknown
|
|
4421
4665
|
): number;
|
|
4422
4666
|
|
|
4423
4667
|
/**
|
|
@@ -4428,10 +4672,9 @@ declare module Immutable {
|
|
|
4428
4672
|
*/
|
|
4429
4673
|
countBy<G>(
|
|
4430
4674
|
grouper: (value: V, key: K, iter: this) => G,
|
|
4431
|
-
context?:
|
|
4675
|
+
context?: unknown
|
|
4432
4676
|
): Map<G, number>;
|
|
4433
4677
|
|
|
4434
|
-
|
|
4435
4678
|
// Search for value
|
|
4436
4679
|
|
|
4437
4680
|
/**
|
|
@@ -4439,7 +4682,7 @@ declare module Immutable {
|
|
|
4439
4682
|
*/
|
|
4440
4683
|
find(
|
|
4441
4684
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4442
|
-
context?:
|
|
4685
|
+
context?: unknown,
|
|
4443
4686
|
notSetValue?: V
|
|
4444
4687
|
): V | undefined;
|
|
4445
4688
|
|
|
@@ -4450,7 +4693,7 @@ declare module Immutable {
|
|
|
4450
4693
|
*/
|
|
4451
4694
|
findLast(
|
|
4452
4695
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4453
|
-
context?:
|
|
4696
|
+
context?: unknown,
|
|
4454
4697
|
notSetValue?: V
|
|
4455
4698
|
): V | undefined;
|
|
4456
4699
|
|
|
@@ -4459,7 +4702,7 @@ declare module Immutable {
|
|
|
4459
4702
|
*/
|
|
4460
4703
|
findEntry(
|
|
4461
4704
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4462
|
-
context?:
|
|
4705
|
+
context?: unknown,
|
|
4463
4706
|
notSetValue?: V
|
|
4464
4707
|
): [K, V] | undefined;
|
|
4465
4708
|
|
|
@@ -4471,7 +4714,7 @@ declare module Immutable {
|
|
|
4471
4714
|
*/
|
|
4472
4715
|
findLastEntry(
|
|
4473
4716
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4474
|
-
context?:
|
|
4717
|
+
context?: unknown,
|
|
4475
4718
|
notSetValue?: V
|
|
4476
4719
|
): [K, V] | undefined;
|
|
4477
4720
|
|
|
@@ -4480,7 +4723,7 @@ declare module Immutable {
|
|
|
4480
4723
|
*/
|
|
4481
4724
|
findKey(
|
|
4482
4725
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4483
|
-
context?:
|
|
4726
|
+
context?: unknown
|
|
4484
4727
|
): K | undefined;
|
|
4485
4728
|
|
|
4486
4729
|
/**
|
|
@@ -4490,7 +4733,7 @@ declare module Immutable {
|
|
|
4490
4733
|
*/
|
|
4491
4734
|
findLastKey(
|
|
4492
4735
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
4493
|
-
context?:
|
|
4736
|
+
context?: unknown
|
|
4494
4737
|
): K | undefined;
|
|
4495
4738
|
|
|
4496
4739
|
/**
|
|
@@ -4524,8 +4767,16 @@ declare module Immutable {
|
|
|
4524
4767
|
* Like `max`, but also accepts a `comparatorValueMapper` which allows for
|
|
4525
4768
|
* comparing by more sophisticated means:
|
|
4526
4769
|
*
|
|
4527
|
-
*
|
|
4528
|
-
*
|
|
4770
|
+
* <!-- runkit:activate -->
|
|
4771
|
+
* ```js
|
|
4772
|
+
* const { List, } = require('immutable');
|
|
4773
|
+
* const l = List([
|
|
4774
|
+
* { name: 'Bob', avgHit: 1 },
|
|
4775
|
+
* { name: 'Max', avgHit: 3 },
|
|
4776
|
+
* { name: 'Lili', avgHit: 2 } ,
|
|
4777
|
+
* ]);
|
|
4778
|
+
* l.maxBy(i => i.avgHit); // will output { name: 'Max', avgHit: 3 }
|
|
4779
|
+
* ```
|
|
4529
4780
|
*/
|
|
4530
4781
|
maxBy<C>(
|
|
4531
4782
|
comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
|
@@ -4553,15 +4804,22 @@ declare module Immutable {
|
|
|
4553
4804
|
* Like `min`, but also accepts a `comparatorValueMapper` which allows for
|
|
4554
4805
|
* comparing by more sophisticated means:
|
|
4555
4806
|
*
|
|
4556
|
-
*
|
|
4557
|
-
*
|
|
4807
|
+
* <!-- runkit:activate -->
|
|
4808
|
+
* ```js
|
|
4809
|
+
* const { List, } = require('immutable');
|
|
4810
|
+
* const l = List([
|
|
4811
|
+
* { name: 'Bob', avgHit: 1 },
|
|
4812
|
+
* { name: 'Max', avgHit: 3 },
|
|
4813
|
+
* { name: 'Lili', avgHit: 2 } ,
|
|
4814
|
+
* ]);
|
|
4815
|
+
* l.minBy(i => i.avgHit); // will output { name: 'Bob', avgHit: 1 }
|
|
4816
|
+
* ```
|
|
4558
4817
|
*/
|
|
4559
4818
|
minBy<C>(
|
|
4560
4819
|
comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
|
4561
4820
|
comparator?: (valueA: C, valueB: C) => number
|
|
4562
4821
|
): V | undefined;
|
|
4563
4822
|
|
|
4564
|
-
|
|
4565
4823
|
// Comparison
|
|
4566
4824
|
|
|
4567
4825
|
/**
|
|
@@ -4578,7 +4836,7 @@ declare module Immutable {
|
|
|
4578
4836
|
/**
|
|
4579
4837
|
* The interface to fulfill to qualify as a Value Object.
|
|
4580
4838
|
*/
|
|
4581
|
-
|
|
4839
|
+
interface ValueObject {
|
|
4582
4840
|
/**
|
|
4583
4841
|
* True if this and the other Collection have value equality, as defined
|
|
4584
4842
|
* by `Immutable.is()`.
|
|
@@ -4586,7 +4844,7 @@ declare module Immutable {
|
|
|
4586
4844
|
* Note: This is equivalent to `Immutable.is(this, other)`, but provided to
|
|
4587
4845
|
* allow for chained expressions.
|
|
4588
4846
|
*/
|
|
4589
|
-
equals(other:
|
|
4847
|
+
equals(other: unknown): boolean;
|
|
4590
4848
|
|
|
4591
4849
|
/**
|
|
4592
4850
|
* Computes and returns the hashed identity for this Collection.
|
|
@@ -4597,7 +4855,7 @@ declare module Immutable {
|
|
|
4597
4855
|
*
|
|
4598
4856
|
* <!-- runkit:activate -->
|
|
4599
4857
|
* ```js
|
|
4600
|
-
* const { List, Set } = require('immutable
|
|
4858
|
+
* const { List, Set } = require('immutable');
|
|
4601
4859
|
* const a = List([ 1, 2, 3 ]);
|
|
4602
4860
|
* const b = List([ 1, 2, 3 ]);
|
|
4603
4861
|
* assert.notStrictEqual(a, b); // different instances
|
|
@@ -4617,7 +4875,7 @@ declare module Immutable {
|
|
|
4617
4875
|
* organize their internal data structures, while all Immutable.js
|
|
4618
4876
|
* collections use equality during lookups.
|
|
4619
4877
|
*
|
|
4620
|
-
* [Hash Collision]:
|
|
4878
|
+
* [Hash Collision]: https://en.wikipedia.org/wiki/Collision_(computer_science)
|
|
4621
4879
|
*/
|
|
4622
4880
|
hashCode(): number;
|
|
4623
4881
|
}
|
|
@@ -4625,10 +4883,14 @@ declare module Immutable {
|
|
|
4625
4883
|
/**
|
|
4626
4884
|
* Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
|
|
4627
4885
|
*
|
|
4886
|
+
* `fromJS` will convert Arrays and [array-like objects][2] to a List, and
|
|
4887
|
+
* plain objects (without a custom prototype) to a Map. [Iterable objects][3]
|
|
4888
|
+
* may be converted to List, Map, or Set.
|
|
4889
|
+
*
|
|
4628
4890
|
* If a `reviver` is optionally provided, it will be called with every
|
|
4629
4891
|
* collection as a Seq (beginning with the most nested collections
|
|
4630
4892
|
* and proceeding to the top-level collection itself), along with the key
|
|
4631
|
-
*
|
|
4893
|
+
* referring to each collection and the parent JS object provided as `this`.
|
|
4632
4894
|
* For the top level, object, the key will be `""`. This `reviver` is expected
|
|
4633
4895
|
* to return a new Immutable Collection, allowing for custom conversions from
|
|
4634
4896
|
* deep JS objects. Finally, a `path` is provided which is the sequence of
|
|
@@ -4641,21 +4903,17 @@ declare module Immutable {
|
|
|
4641
4903
|
*
|
|
4642
4904
|
* <!-- runkit:activate -->
|
|
4643
4905
|
* ```js
|
|
4644
|
-
* const { fromJS, isKeyed } = require('immutable
|
|
4906
|
+
* const { fromJS, isKeyed } = require('immutable')
|
|
4645
4907
|
* function (key, value) {
|
|
4646
|
-
* return isKeyed(value) ? value.
|
|
4908
|
+
* return isKeyed(value) ? value.toMap() : value.toList()
|
|
4647
4909
|
* }
|
|
4648
4910
|
* ```
|
|
4649
4911
|
*
|
|
4650
|
-
* `fromJS` is conservative in its conversion. It will only convert
|
|
4651
|
-
* arrays which pass `Array.isArray` to Lists, and only raw objects (no custom
|
|
4652
|
-
* prototype) to Map.
|
|
4653
|
-
*
|
|
4654
4912
|
* Accordingly, this example converts native JS data to OrderedMap and List:
|
|
4655
4913
|
*
|
|
4656
4914
|
* <!-- runkit:activate -->
|
|
4657
4915
|
* ```js
|
|
4658
|
-
* const { fromJS, isKeyed } = require('immutable
|
|
4916
|
+
* const { fromJS, isKeyed } = require('immutable')
|
|
4659
4917
|
* fromJS({ a: {b: [10, 20, 30]}, c: 40}, function (key, value, path) {
|
|
4660
4918
|
* console.log(key, value, path)
|
|
4661
4919
|
* return isKeyed(value) ? value.toOrderedMap() : value.toList()
|
|
@@ -4672,7 +4930,7 @@ declare module Immutable {
|
|
|
4672
4930
|
*
|
|
4673
4931
|
* <!-- runkit:activate -->
|
|
4674
4932
|
* ```js
|
|
4675
|
-
* const { Map } = require('immutable
|
|
4933
|
+
* const { Map } = require('immutable')
|
|
4676
4934
|
* let obj = { 1: "one" };
|
|
4677
4935
|
* Object.keys(obj); // [ "1" ]
|
|
4678
4936
|
* assert.equal(obj["1"], obj[1]); // "one" === "one"
|
|
@@ -4687,15 +4945,19 @@ declare module Immutable {
|
|
|
4687
4945
|
*
|
|
4688
4946
|
* [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter
|
|
4689
4947
|
* "Using the reviver parameter"
|
|
4948
|
+
* [2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#working_with_array-like_objects
|
|
4949
|
+
* "Working with array-like objects"
|
|
4950
|
+
* [3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol
|
|
4951
|
+
* "The iterable protocol"
|
|
4690
4952
|
*/
|
|
4691
|
-
|
|
4692
|
-
jsValue:
|
|
4953
|
+
function fromJS(
|
|
4954
|
+
jsValue: unknown,
|
|
4693
4955
|
reviver?: (
|
|
4694
4956
|
key: string | number,
|
|
4695
|
-
sequence: Collection.Keyed<string,
|
|
4957
|
+
sequence: Collection.Keyed<string, unknown> | Collection.Indexed<unknown>,
|
|
4696
4958
|
path?: Array<string | number>
|
|
4697
|
-
) =>
|
|
4698
|
-
):
|
|
4959
|
+
) => unknown
|
|
4960
|
+
): Collection<unknown, unknown>;
|
|
4699
4961
|
|
|
4700
4962
|
/**
|
|
4701
4963
|
* Value equality check with semantics similar to `Object.is`, but treats
|
|
@@ -4707,7 +4969,7 @@ declare module Immutable {
|
|
|
4707
4969
|
*
|
|
4708
4970
|
* <!-- runkit:activate -->
|
|
4709
4971
|
* ```js
|
|
4710
|
-
* const { Map, is } = require('immutable
|
|
4972
|
+
* const { Map, is } = require('immutable')
|
|
4711
4973
|
* const map1 = Map({ a: 1, b: 1, c: 1 })
|
|
4712
4974
|
* const map2 = Map({ a: 1, b: 1, c: 1 })
|
|
4713
4975
|
* assert.equal(map1 !== map2, true)
|
|
@@ -4722,14 +4984,14 @@ declare module Immutable {
|
|
|
4722
4984
|
* Note: Unlike `Object.is`, `Immutable.is` assumes `0` and `-0` are the same
|
|
4723
4985
|
* value, matching the behavior of ES6 Map key equality.
|
|
4724
4986
|
*/
|
|
4725
|
-
|
|
4987
|
+
function is(first: unknown, second: unknown): boolean;
|
|
4726
4988
|
|
|
4727
4989
|
/**
|
|
4728
4990
|
* The `hash()` function is an important part of how Immutable determines if
|
|
4729
4991
|
* two values are equivalent and is used to determine how to store those
|
|
4730
4992
|
* values. Provided with any value, `hash()` will return a 31-bit integer.
|
|
4731
4993
|
*
|
|
4732
|
-
* When designing Objects which may be equal, it's important
|
|
4994
|
+
* When designing Objects which may be equal, it's important that when a
|
|
4733
4995
|
* `.equals()` method returns true, that both values `.hashCode()` method
|
|
4734
4996
|
* return the same value. `hash()` may be used to produce those values.
|
|
4735
4997
|
*
|
|
@@ -4746,7 +5008,7 @@ declare module Immutable {
|
|
|
4746
5008
|
*
|
|
4747
5009
|
* *New in Version 4.0*
|
|
4748
5010
|
*/
|
|
4749
|
-
|
|
5011
|
+
function hash(value: unknown): number;
|
|
4750
5012
|
|
|
4751
5013
|
/**
|
|
4752
5014
|
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
@@ -4755,7 +5017,7 @@ declare module Immutable {
|
|
|
4755
5017
|
*
|
|
4756
5018
|
* <!-- runkit:activate -->
|
|
4757
5019
|
* ```js
|
|
4758
|
-
* const { isImmutable, Map, List, Stack } = require('immutable
|
|
5020
|
+
* const { isImmutable, Map, List, Stack } = require('immutable');
|
|
4759
5021
|
* isImmutable([]); // false
|
|
4760
5022
|
* isImmutable({}); // false
|
|
4761
5023
|
* isImmutable(Map()); // true
|
|
@@ -4764,14 +5026,16 @@ declare module Immutable {
|
|
|
4764
5026
|
* isImmutable(Map().asMutable()); // true
|
|
4765
5027
|
* ```
|
|
4766
5028
|
*/
|
|
4767
|
-
|
|
5029
|
+
function isImmutable(
|
|
5030
|
+
maybeImmutable: unknown
|
|
5031
|
+
): maybeImmutable is Collection<unknown, unknown>;
|
|
4768
5032
|
|
|
4769
5033
|
/**
|
|
4770
5034
|
* True if `maybeCollection` is a Collection, or any of its subclasses.
|
|
4771
5035
|
*
|
|
4772
5036
|
* <!-- runkit:activate -->
|
|
4773
5037
|
* ```js
|
|
4774
|
-
* const { isCollection, Map, List, Stack } = require('immutable
|
|
5038
|
+
* const { isCollection, Map, List, Stack } = require('immutable');
|
|
4775
5039
|
* isCollection([]); // false
|
|
4776
5040
|
* isCollection({}); // false
|
|
4777
5041
|
* isCollection(Map()); // true
|
|
@@ -4779,14 +5043,16 @@ declare module Immutable {
|
|
|
4779
5043
|
* isCollection(Stack()); // true
|
|
4780
5044
|
* ```
|
|
4781
5045
|
*/
|
|
4782
|
-
|
|
5046
|
+
function isCollection(
|
|
5047
|
+
maybeCollection: unknown
|
|
5048
|
+
): maybeCollection is Collection<unknown, unknown>;
|
|
4783
5049
|
|
|
4784
5050
|
/**
|
|
4785
5051
|
* True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
|
|
4786
5052
|
*
|
|
4787
5053
|
* <!-- runkit:activate -->
|
|
4788
5054
|
* ```js
|
|
4789
|
-
* const { isKeyed, Map, List, Stack } = require('immutable
|
|
5055
|
+
* const { isKeyed, Map, List, Stack } = require('immutable');
|
|
4790
5056
|
* isKeyed([]); // false
|
|
4791
5057
|
* isKeyed({}); // false
|
|
4792
5058
|
* isKeyed(Map()); // true
|
|
@@ -4794,14 +5060,16 @@ declare module Immutable {
|
|
|
4794
5060
|
* isKeyed(Stack()); // false
|
|
4795
5061
|
* ```
|
|
4796
5062
|
*/
|
|
4797
|
-
|
|
5063
|
+
function isKeyed(
|
|
5064
|
+
maybeKeyed: unknown
|
|
5065
|
+
): maybeKeyed is Collection.Keyed<unknown, unknown>;
|
|
4798
5066
|
|
|
4799
5067
|
/**
|
|
4800
5068
|
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
|
|
4801
5069
|
*
|
|
4802
5070
|
* <!-- runkit:activate -->
|
|
4803
5071
|
* ```js
|
|
4804
|
-
* const { isIndexed, Map, List, Stack, Set } = require('immutable
|
|
5072
|
+
* const { isIndexed, Map, List, Stack, Set } = require('immutable');
|
|
4805
5073
|
* isIndexed([]); // false
|
|
4806
5074
|
* isIndexed({}); // false
|
|
4807
5075
|
* isIndexed(Map()); // false
|
|
@@ -4810,14 +5078,16 @@ declare module Immutable {
|
|
|
4810
5078
|
* isIndexed(Set()); // false
|
|
4811
5079
|
* ```
|
|
4812
5080
|
*/
|
|
4813
|
-
|
|
5081
|
+
function isIndexed(
|
|
5082
|
+
maybeIndexed: unknown
|
|
5083
|
+
): maybeIndexed is Collection.Indexed<unknown>;
|
|
4814
5084
|
|
|
4815
5085
|
/**
|
|
4816
5086
|
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
|
|
4817
5087
|
*
|
|
4818
5088
|
* <!-- runkit:activate -->
|
|
4819
5089
|
* ```js
|
|
4820
|
-
* const { isAssociative, Map, List, Stack, Set } = require('immutable
|
|
5090
|
+
* const { isAssociative, Map, List, Stack, Set } = require('immutable');
|
|
4821
5091
|
* isAssociative([]); // false
|
|
4822
5092
|
* isAssociative({}); // false
|
|
4823
5093
|
* isAssociative(Map()); // true
|
|
@@ -4826,7 +5096,11 @@ declare module Immutable {
|
|
|
4826
5096
|
* isAssociative(Set()); // false
|
|
4827
5097
|
* ```
|
|
4828
5098
|
*/
|
|
4829
|
-
|
|
5099
|
+
function isAssociative(
|
|
5100
|
+
maybeAssociative: unknown
|
|
5101
|
+
): maybeAssociative is
|
|
5102
|
+
| Collection.Keyed<unknown, unknown>
|
|
5103
|
+
| Collection.Indexed<unknown>;
|
|
4830
5104
|
|
|
4831
5105
|
/**
|
|
4832
5106
|
* True if `maybeOrdered` is a Collection where iteration order is well
|
|
@@ -4834,7 +5108,7 @@ declare module Immutable {
|
|
|
4834
5108
|
*
|
|
4835
5109
|
* <!-- runkit:activate -->
|
|
4836
5110
|
* ```js
|
|
4837
|
-
* const { isOrdered, Map, OrderedMap, List, Set } = require('immutable
|
|
5111
|
+
* const { isOrdered, Map, OrderedMap, List, Set } = require('immutable');
|
|
4838
5112
|
* isOrdered([]); // false
|
|
4839
5113
|
* isOrdered({}); // false
|
|
4840
5114
|
* isOrdered(Map()); // false
|
|
@@ -4843,7 +5117,7 @@ declare module Immutable {
|
|
|
4843
5117
|
* isOrdered(Set()); // false
|
|
4844
5118
|
* ```
|
|
4845
5119
|
*/
|
|
4846
|
-
|
|
5120
|
+
function isOrdered(maybeOrdered: unknown): boolean;
|
|
4847
5121
|
|
|
4848
5122
|
/**
|
|
4849
5123
|
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
|
|
@@ -4852,7 +5126,60 @@ declare module Immutable {
|
|
|
4852
5126
|
* Any two instances of *value objects* can be compared for value equality with
|
|
4853
5127
|
* `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
|
|
4854
5128
|
*/
|
|
4855
|
-
|
|
5129
|
+
function isValueObject(maybeValue: unknown): maybeValue is ValueObject;
|
|
5130
|
+
|
|
5131
|
+
/**
|
|
5132
|
+
* True if `maybeSeq` is a Seq.
|
|
5133
|
+
*/
|
|
5134
|
+
function isSeq(
|
|
5135
|
+
maybeSeq: unknown
|
|
5136
|
+
): maybeSeq is
|
|
5137
|
+
| Seq.Indexed<unknown>
|
|
5138
|
+
| Seq.Keyed<unknown, unknown>
|
|
5139
|
+
| Seq.Set<unknown>;
|
|
5140
|
+
|
|
5141
|
+
/**
|
|
5142
|
+
* True if `maybeList` is a List.
|
|
5143
|
+
*/
|
|
5144
|
+
function isList(maybeList: unknown): maybeList is List<unknown>;
|
|
5145
|
+
|
|
5146
|
+
/**
|
|
5147
|
+
* True if `maybeMap` is a Map.
|
|
5148
|
+
*
|
|
5149
|
+
* Also true for OrderedMaps.
|
|
5150
|
+
*/
|
|
5151
|
+
function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
|
|
5152
|
+
|
|
5153
|
+
/**
|
|
5154
|
+
* True if `maybeOrderedMap` is an OrderedMap.
|
|
5155
|
+
*/
|
|
5156
|
+
function isOrderedMap(
|
|
5157
|
+
maybeOrderedMap: unknown
|
|
5158
|
+
): maybeOrderedMap is OrderedMap<unknown, unknown>;
|
|
5159
|
+
|
|
5160
|
+
/**
|
|
5161
|
+
* True if `maybeStack` is a Stack.
|
|
5162
|
+
*/
|
|
5163
|
+
function isStack(maybeStack: unknown): maybeStack is Stack<unknown>;
|
|
5164
|
+
|
|
5165
|
+
/**
|
|
5166
|
+
* True if `maybeSet` is a Set.
|
|
5167
|
+
*
|
|
5168
|
+
* Also true for OrderedSets.
|
|
5169
|
+
*/
|
|
5170
|
+
function isSet(maybeSet: unknown): maybeSet is Set<unknown>;
|
|
5171
|
+
|
|
5172
|
+
/**
|
|
5173
|
+
* True if `maybeOrderedSet` is an OrderedSet.
|
|
5174
|
+
*/
|
|
5175
|
+
function isOrderedSet(
|
|
5176
|
+
maybeOrderedSet: unknown
|
|
5177
|
+
): maybeOrderedSet is OrderedSet<unknown>;
|
|
5178
|
+
|
|
5179
|
+
/**
|
|
5180
|
+
* True if `maybeRecord` is a Record.
|
|
5181
|
+
*/
|
|
5182
|
+
function isRecord(maybeRecord: unknown): maybeRecord is Record<{}>;
|
|
4856
5183
|
|
|
4857
5184
|
/**
|
|
4858
5185
|
* Returns the value within the provided collection associated with the
|
|
@@ -4863,20 +5190,40 @@ declare module Immutable {
|
|
|
4863
5190
|
*
|
|
4864
5191
|
* <!-- runkit:activate -->
|
|
4865
5192
|
* ```js
|
|
4866
|
-
* const { get } = require('immutable
|
|
5193
|
+
* const { get } = require('immutable')
|
|
4867
5194
|
* get([ 'dog', 'frog', 'cat' ], 2) // 'frog'
|
|
4868
5195
|
* get({ x: 123, y: 456 }, 'x') // 123
|
|
4869
5196
|
* get({ x: 123, y: 456 }, 'z', 'ifNotSet') // 'ifNotSet'
|
|
4870
5197
|
* ```
|
|
4871
5198
|
*/
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
5199
|
+
function get<K, V>(collection: Collection<K, V>, key: K): V | undefined;
|
|
5200
|
+
function get<K, V, NSV>(
|
|
5201
|
+
collection: Collection<K, V>,
|
|
5202
|
+
key: K,
|
|
5203
|
+
notSetValue: NSV
|
|
5204
|
+
): V | NSV;
|
|
5205
|
+
function get<TProps extends object, K extends keyof TProps>(
|
|
5206
|
+
record: Record<TProps>,
|
|
5207
|
+
key: K,
|
|
5208
|
+
notSetValue: unknown
|
|
5209
|
+
): TProps[K];
|
|
5210
|
+
function get<V>(collection: Array<V>, key: number): V | undefined;
|
|
5211
|
+
function get<V, NSV>(
|
|
5212
|
+
collection: Array<V>,
|
|
5213
|
+
key: number,
|
|
5214
|
+
notSetValue: NSV
|
|
5215
|
+
): V | NSV;
|
|
5216
|
+
function get<C extends object, K extends keyof C>(
|
|
5217
|
+
object: C,
|
|
5218
|
+
key: K,
|
|
5219
|
+
notSetValue: unknown
|
|
5220
|
+
): C[K];
|
|
5221
|
+
function get<V>(collection: { [key: string]: V }, key: string): V | undefined;
|
|
5222
|
+
function get<V, NSV>(
|
|
5223
|
+
collection: { [key: string]: V },
|
|
5224
|
+
key: string,
|
|
5225
|
+
notSetValue: NSV
|
|
5226
|
+
): V | NSV;
|
|
4880
5227
|
|
|
4881
5228
|
/**
|
|
4882
5229
|
* Returns true if the key is defined in the provided collection.
|
|
@@ -4887,14 +5234,14 @@ declare module Immutable {
|
|
|
4887
5234
|
*
|
|
4888
5235
|
* <!-- runkit:activate -->
|
|
4889
5236
|
* ```js
|
|
4890
|
-
* const { has } = require('immutable
|
|
5237
|
+
* const { has } = require('immutable')
|
|
4891
5238
|
* has([ 'dog', 'frog', 'cat' ], 2) // true
|
|
4892
5239
|
* has([ 'dog', 'frog', 'cat' ], 5) // false
|
|
4893
5240
|
* has({ x: 123, y: 456 }, 'x') // true
|
|
4894
5241
|
* has({ x: 123, y: 456 }, 'z') // false
|
|
4895
5242
|
* ```
|
|
4896
5243
|
*/
|
|
4897
|
-
|
|
5244
|
+
function has(collection: object, key: unknown): boolean;
|
|
4898
5245
|
|
|
4899
5246
|
/**
|
|
4900
5247
|
* Returns a copy of the collection with the value at key removed.
|
|
@@ -4905,7 +5252,7 @@ declare module Immutable {
|
|
|
4905
5252
|
*
|
|
4906
5253
|
* <!-- runkit:activate -->
|
|
4907
5254
|
* ```js
|
|
4908
|
-
* const { remove } = require('immutable
|
|
5255
|
+
* const { remove } = require('immutable')
|
|
4909
5256
|
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
4910
5257
|
* remove(originalArray, 1) // [ 'dog', 'cat' ]
|
|
4911
5258
|
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
@@ -4914,11 +5261,21 @@ declare module Immutable {
|
|
|
4914
5261
|
* console.log(originalObject) // { x: 123, y: 456 }
|
|
4915
5262
|
* ```
|
|
4916
5263
|
*/
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
5264
|
+
function remove<K, C extends Collection<K, unknown>>(
|
|
5265
|
+
collection: C,
|
|
5266
|
+
key: K
|
|
5267
|
+
): C;
|
|
5268
|
+
function remove<
|
|
5269
|
+
TProps extends object,
|
|
5270
|
+
C extends Record<TProps>,
|
|
5271
|
+
K extends keyof TProps
|
|
5272
|
+
>(collection: C, key: K): C;
|
|
5273
|
+
function remove<C extends Array<unknown>>(collection: C, key: number): C;
|
|
5274
|
+
function remove<C, K extends keyof C>(collection: C, key: K): C;
|
|
5275
|
+
function remove<C extends { [key: string]: unknown }, K extends keyof C>(
|
|
5276
|
+
collection: C,
|
|
5277
|
+
key: K
|
|
5278
|
+
): C;
|
|
4922
5279
|
|
|
4923
5280
|
/**
|
|
4924
5281
|
* Returns a copy of the collection with the value at key set to the provided
|
|
@@ -4930,7 +5287,7 @@ declare module Immutable {
|
|
|
4930
5287
|
*
|
|
4931
5288
|
* <!-- runkit:activate -->
|
|
4932
5289
|
* ```js
|
|
4933
|
-
* const { set } = require('immutable
|
|
5290
|
+
* const { set } = require('immutable')
|
|
4934
5291
|
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
4935
5292
|
* set(originalArray, 1, 'cow') // [ 'dog', 'cow', 'cat' ]
|
|
4936
5293
|
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
@@ -4939,11 +5296,23 @@ declare module Immutable {
|
|
|
4939
5296
|
* console.log(originalObject) // { x: 123, y: 456 }
|
|
4940
5297
|
* ```
|
|
4941
5298
|
*/
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
5299
|
+
function set<K, V, C extends Collection<K, V>>(
|
|
5300
|
+
collection: C,
|
|
5301
|
+
key: K,
|
|
5302
|
+
value: V
|
|
5303
|
+
): C;
|
|
5304
|
+
function set<
|
|
5305
|
+
TProps extends object,
|
|
5306
|
+
C extends Record<TProps>,
|
|
5307
|
+
K extends keyof TProps
|
|
5308
|
+
>(record: C, key: K, value: TProps[K]): C;
|
|
5309
|
+
function set<V, C extends Array<V>>(collection: C, key: number, value: V): C;
|
|
5310
|
+
function set<C, K extends keyof C>(object: C, key: K, value: C[K]): C;
|
|
5311
|
+
function set<V, C extends { [key: string]: V }>(
|
|
5312
|
+
collection: C,
|
|
5313
|
+
key: string,
|
|
5314
|
+
value: V
|
|
5315
|
+
): C;
|
|
4947
5316
|
|
|
4948
5317
|
/**
|
|
4949
5318
|
* Returns a copy of the collection with the value at key set to the result of
|
|
@@ -4955,25 +5324,75 @@ declare module Immutable {
|
|
|
4955
5324
|
*
|
|
4956
5325
|
* <!-- runkit:activate -->
|
|
4957
5326
|
* ```js
|
|
4958
|
-
* const { update } = require('immutable
|
|
5327
|
+
* const { update } = require('immutable')
|
|
4959
5328
|
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
4960
5329
|
* update(originalArray, 1, val => val.toUpperCase()) // [ 'dog', 'FROG', 'cat' ]
|
|
4961
5330
|
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
4962
5331
|
* const originalObject = { x: 123, y: 456 }
|
|
4963
|
-
*
|
|
5332
|
+
* update(originalObject, 'x', val => val * 6) // { x: 738, y: 456 }
|
|
4964
5333
|
* console.log(originalObject) // { x: 123, y: 456 }
|
|
4965
5334
|
* ```
|
|
4966
5335
|
*/
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
5336
|
+
function update<K, V, C extends Collection<K, V>>(
|
|
5337
|
+
collection: C,
|
|
5338
|
+
key: K,
|
|
5339
|
+
updater: (value: V | undefined) => V
|
|
5340
|
+
): C;
|
|
5341
|
+
function update<K, V, C extends Collection<K, V>, NSV>(
|
|
5342
|
+
collection: C,
|
|
5343
|
+
key: K,
|
|
5344
|
+
notSetValue: NSV,
|
|
5345
|
+
updater: (value: V | NSV) => V
|
|
5346
|
+
): C;
|
|
5347
|
+
function update<
|
|
5348
|
+
TProps extends object,
|
|
5349
|
+
C extends Record<TProps>,
|
|
5350
|
+
K extends keyof TProps
|
|
5351
|
+
>(record: C, key: K, updater: (value: TProps[K]) => TProps[K]): C;
|
|
5352
|
+
function update<
|
|
5353
|
+
TProps extends object,
|
|
5354
|
+
C extends Record<TProps>,
|
|
5355
|
+
K extends keyof TProps,
|
|
5356
|
+
NSV
|
|
5357
|
+
>(
|
|
5358
|
+
record: C,
|
|
5359
|
+
key: K,
|
|
5360
|
+
notSetValue: NSV,
|
|
5361
|
+
updater: (value: TProps[K] | NSV) => TProps[K]
|
|
5362
|
+
): C;
|
|
5363
|
+
function update<V>(
|
|
5364
|
+
collection: Array<V>,
|
|
5365
|
+
key: number,
|
|
5366
|
+
updater: (value: V) => V
|
|
5367
|
+
): Array<V>;
|
|
5368
|
+
function update<V, NSV>(
|
|
5369
|
+
collection: Array<V>,
|
|
5370
|
+
key: number,
|
|
5371
|
+
notSetValue: NSV,
|
|
5372
|
+
updater: (value: V | NSV) => V
|
|
5373
|
+
): Array<V>;
|
|
5374
|
+
function update<C, K extends keyof C>(
|
|
5375
|
+
object: C,
|
|
5376
|
+
key: K,
|
|
5377
|
+
updater: (value: C[K]) => C[K]
|
|
5378
|
+
): C;
|
|
5379
|
+
function update<C, K extends keyof C, NSV>(
|
|
5380
|
+
object: C,
|
|
5381
|
+
key: K,
|
|
5382
|
+
notSetValue: NSV,
|
|
5383
|
+
updater: (value: C[K] | NSV) => C[K]
|
|
5384
|
+
): C;
|
|
5385
|
+
function update<V, C extends { [key: string]: V }, K extends keyof C>(
|
|
5386
|
+
collection: C,
|
|
5387
|
+
key: K,
|
|
5388
|
+
updater: (value: V) => V
|
|
5389
|
+
): { [key: string]: V };
|
|
5390
|
+
function update<V, C extends { [key: string]: V }, K extends keyof C, NSV>(
|
|
5391
|
+
collection: C,
|
|
5392
|
+
key: K,
|
|
5393
|
+
notSetValue: NSV,
|
|
5394
|
+
updater: (value: V | NSV) => V
|
|
5395
|
+
): { [key: string]: V };
|
|
4977
5396
|
|
|
4978
5397
|
/**
|
|
4979
5398
|
* Returns the value at the provided key path starting at the provided
|
|
@@ -4984,12 +5403,16 @@ declare module Immutable {
|
|
|
4984
5403
|
*
|
|
4985
5404
|
* <!-- runkit:activate -->
|
|
4986
5405
|
* ```js
|
|
4987
|
-
* const { getIn } = require('immutable
|
|
5406
|
+
* const { getIn } = require('immutable')
|
|
4988
5407
|
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
|
|
4989
5408
|
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
|
|
4990
5409
|
* ```
|
|
4991
5410
|
*/
|
|
4992
|
-
|
|
5411
|
+
function getIn(
|
|
5412
|
+
collection: unknown,
|
|
5413
|
+
keyPath: Iterable<unknown>,
|
|
5414
|
+
notSetValue?: unknown
|
|
5415
|
+
): unknown;
|
|
4993
5416
|
|
|
4994
5417
|
/**
|
|
4995
5418
|
* Returns true if the key path is defined in the provided collection.
|
|
@@ -4999,12 +5422,12 @@ declare module Immutable {
|
|
|
4999
5422
|
*
|
|
5000
5423
|
* <!-- runkit:activate -->
|
|
5001
5424
|
* ```js
|
|
5002
|
-
* const { hasIn } = require('immutable
|
|
5425
|
+
* const { hasIn } = require('immutable')
|
|
5003
5426
|
* hasIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // true
|
|
5004
5427
|
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
|
|
5005
5428
|
* ```
|
|
5006
5429
|
*/
|
|
5007
|
-
|
|
5430
|
+
function hasIn(collection: unknown, keyPath: Iterable<unknown>): boolean;
|
|
5008
5431
|
|
|
5009
5432
|
/**
|
|
5010
5433
|
* Returns a copy of the collection with the value at the key path removed.
|
|
@@ -5014,13 +5437,13 @@ declare module Immutable {
|
|
|
5014
5437
|
*
|
|
5015
5438
|
* <!-- runkit:activate -->
|
|
5016
5439
|
* ```js
|
|
5017
|
-
* const { removeIn } = require('immutable
|
|
5440
|
+
* const { removeIn } = require('immutable')
|
|
5018
5441
|
* const original = { x: { y: { z: 123 }}}
|
|
5019
5442
|
* removeIn(original, ['x', 'y', 'z']) // { x: { y: {}}}
|
|
5020
5443
|
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5021
5444
|
* ```
|
|
5022
5445
|
*/
|
|
5023
|
-
|
|
5446
|
+
function removeIn<C>(collection: C, keyPath: Iterable<unknown>): C;
|
|
5024
5447
|
|
|
5025
5448
|
/**
|
|
5026
5449
|
* Returns a copy of the collection with the value at the key path set to the
|
|
@@ -5031,13 +5454,17 @@ declare module Immutable {
|
|
|
5031
5454
|
*
|
|
5032
5455
|
* <!-- runkit:activate -->
|
|
5033
5456
|
* ```js
|
|
5034
|
-
* const { setIn } = require('immutable
|
|
5457
|
+
* const { setIn } = require('immutable')
|
|
5035
5458
|
* const original = { x: { y: { z: 123 }}}
|
|
5036
5459
|
* setIn(original, ['x', 'y', 'z'], 456) // { x: { y: { z: 456 }}}
|
|
5037
5460
|
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5038
5461
|
* ```
|
|
5039
5462
|
*/
|
|
5040
|
-
|
|
5463
|
+
function setIn<C>(
|
|
5464
|
+
collection: C,
|
|
5465
|
+
keyPath: Iterable<unknown>,
|
|
5466
|
+
value: unknown
|
|
5467
|
+
): C;
|
|
5041
5468
|
|
|
5042
5469
|
/**
|
|
5043
5470
|
* Returns a copy of the collection with the value at key path set to the
|
|
@@ -5048,14 +5475,23 @@ declare module Immutable {
|
|
|
5048
5475
|
*
|
|
5049
5476
|
* <!-- runkit:activate -->
|
|
5050
5477
|
* ```js
|
|
5051
|
-
* const {
|
|
5478
|
+
* const { updateIn } = require('immutable')
|
|
5052
5479
|
* const original = { x: { y: { z: 123 }}}
|
|
5053
|
-
*
|
|
5480
|
+
* updateIn(original, ['x', 'y', 'z'], val => val * 6) // { x: { y: { z: 738 }}}
|
|
5054
5481
|
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5055
5482
|
* ```
|
|
5056
5483
|
*/
|
|
5057
|
-
|
|
5058
|
-
|
|
5484
|
+
function updateIn<C>(
|
|
5485
|
+
collection: C,
|
|
5486
|
+
keyPath: Iterable<unknown>,
|
|
5487
|
+
updater: (value: unknown) => unknown
|
|
5488
|
+
): C;
|
|
5489
|
+
function updateIn<C>(
|
|
5490
|
+
collection: C,
|
|
5491
|
+
keyPath: Iterable<unknown>,
|
|
5492
|
+
notSetValue: unknown,
|
|
5493
|
+
updater: (value: unknown) => unknown
|
|
5494
|
+
): C;
|
|
5059
5495
|
|
|
5060
5496
|
/**
|
|
5061
5497
|
* Returns a copy of the collection with the remaining collections merged in.
|
|
@@ -5065,15 +5501,19 @@ declare module Immutable {
|
|
|
5065
5501
|
*
|
|
5066
5502
|
* <!-- runkit:activate -->
|
|
5067
5503
|
* ```js
|
|
5068
|
-
* const { merge } = require('immutable
|
|
5504
|
+
* const { merge } = require('immutable')
|
|
5069
5505
|
* const original = { x: 123, y: 456 }
|
|
5070
5506
|
* merge(original, { y: 789, z: 'abc' }) // { x: 123, y: 789, z: 'abc' }
|
|
5071
|
-
* console.log(original) // { x:
|
|
5507
|
+
* console.log(original) // { x: 123, y: 456 }
|
|
5072
5508
|
* ```
|
|
5073
5509
|
*/
|
|
5074
|
-
|
|
5510
|
+
function merge<C>(
|
|
5075
5511
|
collection: C,
|
|
5076
|
-
...collections: Array<
|
|
5512
|
+
...collections: Array<
|
|
5513
|
+
| Iterable<unknown>
|
|
5514
|
+
| Iterable<[unknown, unknown]>
|
|
5515
|
+
| { [key: string]: unknown }
|
|
5516
|
+
>
|
|
5077
5517
|
): C;
|
|
5078
5518
|
|
|
5079
5519
|
/**
|
|
@@ -5085,53 +5525,72 @@ declare module Immutable {
|
|
|
5085
5525
|
*
|
|
5086
5526
|
* <!-- runkit:activate -->
|
|
5087
5527
|
* ```js
|
|
5088
|
-
* const { mergeWith } = require('immutable
|
|
5528
|
+
* const { mergeWith } = require('immutable')
|
|
5089
5529
|
* const original = { x: 123, y: 456 }
|
|
5090
5530
|
* mergeWith(
|
|
5091
5531
|
* (oldVal, newVal) => oldVal + newVal,
|
|
5092
5532
|
* original,
|
|
5093
5533
|
* { y: 789, z: 'abc' }
|
|
5094
5534
|
* ) // { x: 123, y: 1245, z: 'abc' }
|
|
5095
|
-
* console.log(original) // { x:
|
|
5535
|
+
* console.log(original) // { x: 123, y: 456 }
|
|
5096
5536
|
* ```
|
|
5097
5537
|
*/
|
|
5098
|
-
|
|
5099
|
-
merger: (oldVal:
|
|
5538
|
+
function mergeWith<C>(
|
|
5539
|
+
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
|
5100
5540
|
collection: C,
|
|
5101
|
-
...collections: Array<
|
|
5541
|
+
...collections: Array<
|
|
5542
|
+
| Iterable<unknown>
|
|
5543
|
+
| Iterable<[unknown, unknown]>
|
|
5544
|
+
| { [key: string]: unknown }
|
|
5545
|
+
>
|
|
5102
5546
|
): C;
|
|
5103
5547
|
|
|
5104
5548
|
/**
|
|
5105
|
-
*
|
|
5106
|
-
* deeply
|
|
5549
|
+
* Like `merge()`, but when two compatible collections are encountered with
|
|
5550
|
+
* the same key, it merges them as well, recursing deeply through the nested
|
|
5551
|
+
* data. Two collections are considered to be compatible (and thus will be
|
|
5552
|
+
* merged together) if they both fall into one of three categories: keyed
|
|
5553
|
+
* (e.g., `Map`s, `Record`s, and objects), indexed (e.g., `List`s and
|
|
5554
|
+
* arrays), or set-like (e.g., `Set`s). If they fall into separate
|
|
5555
|
+
* categories, `mergeDeep` will replace the existing collection with the
|
|
5556
|
+
* collection being merged in. This behavior can be customized by using
|
|
5557
|
+
* `mergeDeepWith()`.
|
|
5558
|
+
*
|
|
5559
|
+
* Note: Indexed and set-like collections are merged using
|
|
5560
|
+
* `concat()`/`union()` and therefore do not recurse.
|
|
5107
5561
|
*
|
|
5108
5562
|
* A functional alternative to `collection.mergeDeep()` which will also work
|
|
5109
5563
|
* with plain Objects and Arrays.
|
|
5110
5564
|
*
|
|
5111
5565
|
* <!-- runkit:activate -->
|
|
5112
5566
|
* ```js
|
|
5113
|
-
* const {
|
|
5567
|
+
* const { mergeDeep } = require('immutable')
|
|
5114
5568
|
* const original = { x: { y: 123 }}
|
|
5115
|
-
*
|
|
5569
|
+
* mergeDeep(original, { x: { z: 456 }}) // { x: { y: 123, z: 456 }}
|
|
5116
5570
|
* console.log(original) // { x: { y: 123 }}
|
|
5117
5571
|
* ```
|
|
5118
5572
|
*/
|
|
5119
|
-
|
|
5573
|
+
function mergeDeep<C>(
|
|
5120
5574
|
collection: C,
|
|
5121
|
-
...collections: Array<
|
|
5575
|
+
...collections: Array<
|
|
5576
|
+
| Iterable<unknown>
|
|
5577
|
+
| Iterable<[unknown, unknown]>
|
|
5578
|
+
| { [key: string]: unknown }
|
|
5579
|
+
>
|
|
5122
5580
|
): C;
|
|
5123
5581
|
|
|
5124
5582
|
/**
|
|
5125
|
-
*
|
|
5126
|
-
*
|
|
5127
|
-
* value
|
|
5583
|
+
* Like `mergeDeep()`, but when two non-collections or incompatible
|
|
5584
|
+
* collections are encountered at the same key, it uses the `merger` function
|
|
5585
|
+
* to determine the resulting value. Collections are considered incompatible
|
|
5586
|
+
* if they fall into separate categories between keyed, indexed, and set-like.
|
|
5128
5587
|
*
|
|
5129
5588
|
* A functional alternative to `collection.mergeDeepWith()` which will also
|
|
5130
5589
|
* work with plain Objects and Arrays.
|
|
5131
5590
|
*
|
|
5132
5591
|
* <!-- runkit:activate -->
|
|
5133
5592
|
* ```js
|
|
5134
|
-
* const {
|
|
5593
|
+
* const { mergeDeepWith } = require('immutable')
|
|
5135
5594
|
* const original = { x: { y: 123 }}
|
|
5136
5595
|
* mergeDeepWith(
|
|
5137
5596
|
* (oldVal, newVal) => oldVal + newVal,
|
|
@@ -5141,13 +5600,37 @@ declare module Immutable {
|
|
|
5141
5600
|
* console.log(original) // { x: { y: 123 }}
|
|
5142
5601
|
* ```
|
|
5143
5602
|
*/
|
|
5144
|
-
|
|
5145
|
-
merger: (oldVal:
|
|
5603
|
+
function mergeDeepWith<C>(
|
|
5604
|
+
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
|
5146
5605
|
collection: C,
|
|
5147
|
-
...collections: Array<
|
|
5606
|
+
...collections: Array<
|
|
5607
|
+
| Iterable<unknown>
|
|
5608
|
+
| Iterable<[unknown, unknown]>
|
|
5609
|
+
| { [key: string]: unknown }
|
|
5610
|
+
>
|
|
5148
5611
|
): C;
|
|
5149
5612
|
}
|
|
5150
5613
|
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5614
|
+
/**
|
|
5615
|
+
* Defines the main export of the immutable module to be the Immutable namespace
|
|
5616
|
+
* This supports many common module import patterns:
|
|
5617
|
+
*
|
|
5618
|
+
* const Immutable = require("immutable");
|
|
5619
|
+
* const { List } = require("immutable");
|
|
5620
|
+
* import Immutable from "immutable";
|
|
5621
|
+
* import * as Immutable from "immutable";
|
|
5622
|
+
* import { List } from "immutable";
|
|
5623
|
+
*
|
|
5624
|
+
*/
|
|
5625
|
+
export = Immutable;
|
|
5626
|
+
|
|
5627
|
+
/**
|
|
5628
|
+
* A global "Immutable" namespace used by UMD modules which allows the use of
|
|
5629
|
+
* the full Immutable API.
|
|
5630
|
+
*
|
|
5631
|
+
* If using Immutable as an imported module, prefer using:
|
|
5632
|
+
*
|
|
5633
|
+
* import Immutable from 'immutable'
|
|
5634
|
+
*
|
|
5635
|
+
*/
|
|
5636
|
+
export as namespace Immutable;
|