immutable 5.1.2 → 5.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -84
- package/dist/immutable.d.ts +16 -1139
- package/dist/immutable.es.js +1 -45
- package/dist/immutable.js +1 -45
- package/dist/immutable.min.js +1 -1
- package/package.json +1 -1
package/dist/immutable.d.ts
CHANGED
|
@@ -195,34 +195,13 @@ declare namespace Immutable {
|
|
|
195
195
|
namespace List {
|
|
196
196
|
/**
|
|
197
197
|
* True if the provided value is a List
|
|
198
|
-
*
|
|
199
|
-
* <!-- runkit:activate -->
|
|
200
|
-
* ```js
|
|
201
|
-
* const { List } = require('immutable');
|
|
202
|
-
* List.isList([]); // false
|
|
203
|
-
* List.isList(List()); // true
|
|
204
|
-
* ```
|
|
205
198
|
*/
|
|
206
199
|
function isList(maybeList: unknown): maybeList is List<unknown>;
|
|
207
200
|
|
|
208
201
|
/**
|
|
209
202
|
* Creates a new List containing `values`.
|
|
210
203
|
*
|
|
211
|
-
* <!-- runkit:activate -->
|
|
212
|
-
* ```js
|
|
213
|
-
* const { List } = require('immutable');
|
|
214
|
-
* List.of(1, 2, 3, 4)
|
|
215
|
-
* // List [ 1, 2, 3, 4 ]
|
|
216
|
-
* ```
|
|
217
|
-
*
|
|
218
204
|
* Note: Values are not altered or converted in any way.
|
|
219
|
-
*
|
|
220
|
-
* <!-- runkit:activate -->
|
|
221
|
-
* ```js
|
|
222
|
-
* const { List } = require('immutable');
|
|
223
|
-
* List.of({x:1}, 2, [3], 4)
|
|
224
|
-
* // List [ { x: 1 }, 2, [ 3 ], 4 ]
|
|
225
|
-
* ```
|
|
226
205
|
*/
|
|
227
206
|
function of<T>(...values: Array<T>): List<T>;
|
|
228
207
|
}
|
|
@@ -233,30 +212,6 @@ declare namespace Immutable {
|
|
|
233
212
|
*
|
|
234
213
|
* Note: `List` is a factory function and not a class, and does not use the
|
|
235
214
|
* `new` keyword during construction.
|
|
236
|
-
*
|
|
237
|
-
* <!-- runkit:activate -->
|
|
238
|
-
* ```js
|
|
239
|
-
* const { List, Set } = require('immutable')
|
|
240
|
-
*
|
|
241
|
-
* const emptyList = List()
|
|
242
|
-
* // List []
|
|
243
|
-
*
|
|
244
|
-
* const plainArray = [ 1, 2, 3, 4 ]
|
|
245
|
-
* const listFromPlainArray = List(plainArray)
|
|
246
|
-
* // List [ 1, 2, 3, 4 ]
|
|
247
|
-
*
|
|
248
|
-
* const plainSet = Set([ 1, 2, 3, 4 ])
|
|
249
|
-
* const listFromPlainSet = List(plainSet)
|
|
250
|
-
* // List [ 1, 2, 3, 4 ]
|
|
251
|
-
*
|
|
252
|
-
* const arrayIterator = plainArray[Symbol.iterator]()
|
|
253
|
-
* const listFromCollectionArray = List(arrayIterator)
|
|
254
|
-
* // List [ 1, 2, 3, 4 ]
|
|
255
|
-
*
|
|
256
|
-
* listFromPlainArray.equals(listFromCollectionArray) // true
|
|
257
|
-
* listFromPlainSet.equals(listFromCollectionArray) // true
|
|
258
|
-
* listFromPlainSet.equals(listFromPlainArray) // true
|
|
259
|
-
* ```
|
|
260
215
|
*/
|
|
261
216
|
function List<T>(collection?: Iterable<T> | ArrayLike<T>): List<T>;
|
|
262
217
|
|
|
@@ -278,23 +233,6 @@ declare namespace Immutable {
|
|
|
278
233
|
* If `index` larger than `size`, the returned List's `size` will be large
|
|
279
234
|
* enough to include the `index`.
|
|
280
235
|
*
|
|
281
|
-
* <!-- runkit:activate
|
|
282
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
283
|
-
* -->
|
|
284
|
-
* ```js
|
|
285
|
-
* const originalList = List([ 0 ]);
|
|
286
|
-
* // List [ 0 ]
|
|
287
|
-
* originalList.set(1, 1);
|
|
288
|
-
* // List [ 0, 1 ]
|
|
289
|
-
* originalList.set(0, 'overwritten');
|
|
290
|
-
* // List [ "overwritten" ]
|
|
291
|
-
* originalList.set(2, 2);
|
|
292
|
-
* // List [ 0, undefined, 2 ]
|
|
293
|
-
*
|
|
294
|
-
* List().set(50000, 'value').size;
|
|
295
|
-
* // 50001
|
|
296
|
-
* ```
|
|
297
|
-
*
|
|
298
236
|
* Note: `set` can be used in `withMutations`.
|
|
299
237
|
*/
|
|
300
238
|
set(index: number, value: T): List<T>;
|
|
@@ -311,14 +249,6 @@ declare namespace Immutable {
|
|
|
311
249
|
*
|
|
312
250
|
* Note: `delete` cannot be safely used in IE8
|
|
313
251
|
*
|
|
314
|
-
* <!-- runkit:activate
|
|
315
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
316
|
-
* -->
|
|
317
|
-
* ```js
|
|
318
|
-
* List([ 0, 1, 2, 3, 4 ]).delete(0);
|
|
319
|
-
* // List [ 1, 2, 3, 4 ]
|
|
320
|
-
* ```
|
|
321
|
-
*
|
|
322
252
|
* Since `delete()` re-indexes values, it produces a complete copy, which
|
|
323
253
|
* has `O(N)` complexity.
|
|
324
254
|
*
|
|
@@ -335,14 +265,6 @@ declare namespace Immutable {
|
|
|
335
265
|
*
|
|
336
266
|
* This is synonymous with `list.splice(index, 0, value)`.
|
|
337
267
|
*
|
|
338
|
-
* <!-- runkit:activate
|
|
339
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
340
|
-
* -->
|
|
341
|
-
* ```js
|
|
342
|
-
* List([ 0, 1, 2, 3, 4 ]).insert(6, 5)
|
|
343
|
-
* // List [ 0, 1, 2, 3, 4, 5 ]
|
|
344
|
-
* ```
|
|
345
|
-
*
|
|
346
268
|
* Since `insert()` re-indexes values, it produces a complete copy, which
|
|
347
269
|
* has `O(N)` complexity.
|
|
348
270
|
*
|
|
@@ -353,14 +275,6 @@ declare namespace Immutable {
|
|
|
353
275
|
/**
|
|
354
276
|
* Returns a new List with 0 size and no values in constant time.
|
|
355
277
|
*
|
|
356
|
-
* <!-- runkit:activate
|
|
357
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
358
|
-
* -->
|
|
359
|
-
* ```js
|
|
360
|
-
* List([ 1, 2, 3, 4 ]).clear()
|
|
361
|
-
* // List []
|
|
362
|
-
* ```
|
|
363
|
-
*
|
|
364
278
|
* Note: `clear` can be used in `withMutations`.
|
|
365
279
|
*/
|
|
366
280
|
clear(): List<T>;
|
|
@@ -369,14 +283,6 @@ declare namespace Immutable {
|
|
|
369
283
|
* Returns a new List with the provided `values` appended, starting at this
|
|
370
284
|
* List's `size`.
|
|
371
285
|
*
|
|
372
|
-
* <!-- runkit:activate
|
|
373
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
374
|
-
* -->
|
|
375
|
-
* ```js
|
|
376
|
-
* List([ 1, 2, 3, 4 ]).push(5)
|
|
377
|
-
* // List [ 1, 2, 3, 4, 5 ]
|
|
378
|
-
* ```
|
|
379
|
-
*
|
|
380
286
|
* Note: `push` can be used in `withMutations`.
|
|
381
287
|
*/
|
|
382
288
|
push(...values: Array<T>): List<T>;
|
|
@@ -402,14 +308,6 @@ declare namespace Immutable {
|
|
|
402
308
|
* Returns a new List with the provided `values` prepended, shifting other
|
|
403
309
|
* values ahead to higher indices.
|
|
404
310
|
*
|
|
405
|
-
* <!-- runkit:activate
|
|
406
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
407
|
-
* -->
|
|
408
|
-
* ```js
|
|
409
|
-
* List([ 2, 3, 4]).unshift(1);
|
|
410
|
-
* // List [ 1, 2, 3, 4 ]
|
|
411
|
-
* ```
|
|
412
|
-
*
|
|
413
311
|
* Note: `unshift` can be used in `withMutations`.
|
|
414
312
|
*/
|
|
415
313
|
unshift(...values: Array<T>): List<T>;
|
|
@@ -422,14 +320,6 @@ declare namespace Immutable {
|
|
|
422
320
|
* List rather than the removed value. Use `first()` to get the first
|
|
423
321
|
* value in this List.
|
|
424
322
|
*
|
|
425
|
-
* <!-- runkit:activate
|
|
426
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
427
|
-
* -->
|
|
428
|
-
* ```js
|
|
429
|
-
* List([ 0, 1, 2, 3, 4 ]).shift();
|
|
430
|
-
* // List [ 1, 2, 3, 4 ]
|
|
431
|
-
* ```
|
|
432
|
-
*
|
|
433
323
|
* Note: `shift` can be used in `withMutations`.
|
|
434
324
|
*/
|
|
435
325
|
shift(): List<T>;
|
|
@@ -443,35 +333,11 @@ declare namespace Immutable {
|
|
|
443
333
|
* `index` may be a negative number, which indexes back from the end of the
|
|
444
334
|
* List. `v.update(-1)` updates the last item in the List.
|
|
445
335
|
*
|
|
446
|
-
* <!-- runkit:activate
|
|
447
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
448
|
-
* -->
|
|
449
|
-
* ```js
|
|
450
|
-
* const list = List([ 'a', 'b', 'c' ])
|
|
451
|
-
* const result = list.update(2, val => val.toUpperCase())
|
|
452
|
-
* // List [ "a", "b", "C" ]
|
|
453
|
-
* ```
|
|
454
|
-
*
|
|
455
336
|
* This can be very useful as a way to "chain" a normal function into a
|
|
456
337
|
* sequence of methods. RxJS calls this "let" and lodash calls it "thru".
|
|
457
338
|
*
|
|
458
339
|
* For example, to sum a List after mapping and filtering:
|
|
459
340
|
*
|
|
460
|
-
* <!-- runkit:activate
|
|
461
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
462
|
-
* -->
|
|
463
|
-
* ```js
|
|
464
|
-
* function sum(collection) {
|
|
465
|
-
* return collection.reduce((sum, x) => sum + x, 0)
|
|
466
|
-
* }
|
|
467
|
-
*
|
|
468
|
-
* List([ 1, 2, 3 ])
|
|
469
|
-
* .map(x => x + 1)
|
|
470
|
-
* .filter(x => x % 2 === 0)
|
|
471
|
-
* .update(sum)
|
|
472
|
-
* // 6
|
|
473
|
-
* ```
|
|
474
|
-
*
|
|
475
341
|
* Note: `update(index)` can be used in `withMutations`.
|
|
476
342
|
*
|
|
477
343
|
* @see `Map#update`
|
|
@@ -504,26 +370,10 @@ declare namespace Immutable {
|
|
|
504
370
|
* Index numbers are used as keys to determine the path to follow in
|
|
505
371
|
* the List.
|
|
506
372
|
*
|
|
507
|
-
* <!-- runkit:activate -->
|
|
508
|
-
* ```js
|
|
509
|
-
* const { List } = require('immutable')
|
|
510
|
-
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
|
511
|
-
* list.setIn([3, 0], 999);
|
|
512
|
-
* // List [ 0, 1, 2, List [ 999, 4 ] ]
|
|
513
|
-
* ```
|
|
514
|
-
*
|
|
515
373
|
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
516
374
|
* Collection, and setIn() can update those values as well, treating them
|
|
517
375
|
* immutably by creating new copies of those values with the changes applied.
|
|
518
376
|
*
|
|
519
|
-
* <!-- runkit:activate -->
|
|
520
|
-
* ```js
|
|
521
|
-
* const { List } = require('immutable')
|
|
522
|
-
* const list = List([ 0, 1, 2, { plain: 'object' }])
|
|
523
|
-
* list.setIn([3, 'plain'], 'value');
|
|
524
|
-
* // List([ 0, 1, 2, { plain: 'value' }])
|
|
525
|
-
* ```
|
|
526
|
-
*
|
|
527
377
|
* Note: `setIn` can be used in `withMutations`.
|
|
528
378
|
*/
|
|
529
379
|
setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
|
@@ -532,26 +382,10 @@ declare namespace Immutable {
|
|
|
532
382
|
* Returns a new List having removed the value at this `keyPath`. If any
|
|
533
383
|
* keys in `keyPath` do not exist, no change will occur.
|
|
534
384
|
*
|
|
535
|
-
* <!-- runkit:activate -->
|
|
536
|
-
* ```js
|
|
537
|
-
* const { List } = require('immutable')
|
|
538
|
-
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
|
539
|
-
* list.deleteIn([3, 0]);
|
|
540
|
-
* // List [ 0, 1, 2, List [ 4 ] ]
|
|
541
|
-
* ```
|
|
542
|
-
*
|
|
543
385
|
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
544
386
|
* Collection, and removeIn() can update those values as well, treating them
|
|
545
387
|
* immutably by creating new copies of those values with the changes applied.
|
|
546
388
|
*
|
|
547
|
-
* <!-- runkit:activate -->
|
|
548
|
-
* ```js
|
|
549
|
-
* const { List } = require('immutable')
|
|
550
|
-
* const list = List([ 0, 1, 2, { plain: 'object' }])
|
|
551
|
-
* list.removeIn([3, 'plain']);
|
|
552
|
-
* // List([ 0, 1, 2, {}])
|
|
553
|
-
* ```
|
|
554
|
-
*
|
|
555
389
|
* Note: `deleteIn` *cannot* be safely used in `withMutations`.
|
|
556
390
|
*
|
|
557
391
|
* @alias removeIn
|
|
@@ -638,14 +472,6 @@ declare namespace Immutable {
|
|
|
638
472
|
/**
|
|
639
473
|
* Returns a new List with values passed through a
|
|
640
474
|
* `mapper` function.
|
|
641
|
-
*
|
|
642
|
-
* <!-- runkit:activate
|
|
643
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
644
|
-
* -->
|
|
645
|
-
* ```js
|
|
646
|
-
* List([ 1, 2 ]).map(x => 10 * x)
|
|
647
|
-
* // List [ 10, 20 ]
|
|
648
|
-
* ```
|
|
649
475
|
*/
|
|
650
476
|
map<M>(
|
|
651
477
|
mapper: (value: T, key: number, iter: this) => M,
|
|
@@ -695,15 +521,6 @@ declare namespace Immutable {
|
|
|
695
521
|
* Returns a List "zipped" with the provided collection.
|
|
696
522
|
*
|
|
697
523
|
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
|
698
|
-
*
|
|
699
|
-
* <!-- runkit:activate
|
|
700
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
701
|
-
* -->
|
|
702
|
-
* ```js
|
|
703
|
-
* const a = List([ 1, 2, 3 ]);
|
|
704
|
-
* const b = List([ 4, 5, 6 ]);
|
|
705
|
-
* const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
706
|
-
* ```
|
|
707
524
|
*/
|
|
708
525
|
zip<U>(other: Collection<unknown, U>): List<[T, U]>;
|
|
709
526
|
zip<U, V>(
|
|
@@ -718,15 +535,6 @@ declare namespace Immutable {
|
|
|
718
535
|
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
|
|
719
536
|
* exhausted. Missing values from shorter collections are filled with `undefined`.
|
|
720
537
|
*
|
|
721
|
-
* <!-- runkit:activate
|
|
722
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
723
|
-
* -->
|
|
724
|
-
* ```js
|
|
725
|
-
* const a = List([ 1, 2 ]);
|
|
726
|
-
* const b = List([ 3, 4, 5 ]);
|
|
727
|
-
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
|
|
728
|
-
* ```
|
|
729
|
-
*
|
|
730
538
|
* Note: Since zipAll will return a collection as large as the largest
|
|
731
539
|
* input, some results may contain undefined values. TypeScript cannot
|
|
732
540
|
* account for these without cases (as of v2.5).
|
|
@@ -741,16 +549,6 @@ declare namespace Immutable {
|
|
|
741
549
|
/**
|
|
742
550
|
* Returns a List "zipped" with the provided collections by using a
|
|
743
551
|
* custom `zipper` function.
|
|
744
|
-
*
|
|
745
|
-
* <!-- runkit:activate
|
|
746
|
-
* { "preamble": "const { List } = require('immutable');" }
|
|
747
|
-
* -->
|
|
748
|
-
* ```js
|
|
749
|
-
* const a = List([ 1, 2, 3 ]);
|
|
750
|
-
* const b = List([ 4, 5, 6 ]);
|
|
751
|
-
* const c = a.zipWith((a, b) => a + b, b);
|
|
752
|
-
* // List [ 5, 7, 9 ]
|
|
753
|
-
* ```
|
|
754
552
|
*/
|
|
755
553
|
zipWith<U, Z>(
|
|
756
554
|
zipper: (value: T, otherValue: U) => Z,
|
|
@@ -789,13 +587,6 @@ declare namespace Immutable {
|
|
|
789
587
|
* Immutable collections are treated as values, any Immutable collection may
|
|
790
588
|
* be used as a key.
|
|
791
589
|
*
|
|
792
|
-
* <!-- runkit:activate -->
|
|
793
|
-
* ```js
|
|
794
|
-
* const { Map, List } = require('immutable');
|
|
795
|
-
* Map().set(List([ 1 ]), 'listofone').get(List([ 1 ]));
|
|
796
|
-
* // 'listofone'
|
|
797
|
-
* ```
|
|
798
|
-
*
|
|
799
590
|
* Any JavaScript object may be used as a key, however strict identity is used
|
|
800
591
|
* to evaluate key equality. Two similar looking objects will represent two
|
|
801
592
|
* different keys.
|
|
@@ -805,13 +596,6 @@ declare namespace Immutable {
|
|
|
805
596
|
namespace Map {
|
|
806
597
|
/**
|
|
807
598
|
* True if the provided value is a Map
|
|
808
|
-
*
|
|
809
|
-
* <!-- runkit:activate -->
|
|
810
|
-
* ```js
|
|
811
|
-
* const { Map } = require('immutable')
|
|
812
|
-
* Map.isMap({}) // false
|
|
813
|
-
* Map.isMap(Map()) // true
|
|
814
|
-
* ```
|
|
815
599
|
*/
|
|
816
600
|
function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
|
|
817
601
|
}
|
|
@@ -825,34 +609,15 @@ declare namespace Immutable {
|
|
|
825
609
|
* Note: `Map` is a factory function and not a class, and does not use the
|
|
826
610
|
* `new` keyword during construction.
|
|
827
611
|
*
|
|
828
|
-
* <!-- runkit:activate -->
|
|
829
|
-
* ```js
|
|
830
|
-
* const { Map } = require('immutable')
|
|
831
|
-
* Map({ key: "value" })
|
|
832
|
-
* Map([ [ "key", "value" ] ])
|
|
833
|
-
* ```
|
|
834
|
-
*
|
|
835
612
|
* Keep in mind, when using JS objects to construct Immutable Maps, that
|
|
836
613
|
* JavaScript Object properties are always strings, even if written in a
|
|
837
614
|
* quote-less shorthand, while Immutable Maps accept keys of any type.
|
|
838
615
|
*
|
|
839
|
-
* <!-- runkit:activate
|
|
840
|
-
* { "preamble": "const { Map } = require('immutable');" }
|
|
841
|
-
* -->
|
|
842
|
-
* ```js
|
|
843
|
-
* let obj = { 1: "one" }
|
|
844
|
-
* Object.keys(obj) // [ "1" ]
|
|
845
|
-
* assert.equal(obj["1"], obj[1]) // "one" === "one"
|
|
846
|
-
*
|
|
847
|
-
* let map = Map(obj)
|
|
848
|
-
* assert.notEqual(map.get("1"), map.get(1)) // "one" !== undefined
|
|
849
|
-
* ```
|
|
850
|
-
*
|
|
851
616
|
* Property access for JavaScript Objects first converts the key to a string,
|
|
852
617
|
* but since Immutable Map keys can be of any type the argument to `get()` is
|
|
853
618
|
* not altered.
|
|
854
619
|
*/
|
|
855
|
-
function Map<K, V>(collection?: Iterable<[K, V]>): Map<K, V>;
|
|
620
|
+
function Map<K, V>(collection?: Iterable<readonly [K, V]>): Map<K, V>;
|
|
856
621
|
function Map<R extends { [key in PropertyKey]: unknown }>(obj: R): MapOf<R>;
|
|
857
622
|
function Map<V>(obj: { [key: string]: V }): Map<string, V>;
|
|
858
623
|
function Map<K extends string | symbol, V>(obj: { [P in K]?: V }): Map<K, V>;
|
|
@@ -965,21 +730,6 @@ declare namespace Immutable {
|
|
|
965
730
|
* Returns a new Map also containing the new key, value pair. If an equivalent
|
|
966
731
|
* key already exists in this Map, it will be replaced.
|
|
967
732
|
*
|
|
968
|
-
* <!-- runkit:activate -->
|
|
969
|
-
* ```js
|
|
970
|
-
* const { Map } = require('immutable')
|
|
971
|
-
* const originalMap = Map()
|
|
972
|
-
* const newerMap = originalMap.set('key', 'value')
|
|
973
|
-
* const newestMap = newerMap.set('key', 'newer value')
|
|
974
|
-
*
|
|
975
|
-
* originalMap
|
|
976
|
-
* // Map {}
|
|
977
|
-
* newerMap
|
|
978
|
-
* // Map { "key": "value" }
|
|
979
|
-
* newestMap
|
|
980
|
-
* // Map { "key": "newer value" }
|
|
981
|
-
* ```
|
|
982
|
-
*
|
|
983
733
|
* Note: `set` can be used in `withMutations`.
|
|
984
734
|
*/
|
|
985
735
|
set(key: K, value: V): this;
|
|
@@ -990,18 +740,6 @@ declare namespace Immutable {
|
|
|
990
740
|
* Note: `delete` cannot be safely used in IE8, but is provided to mirror
|
|
991
741
|
* the ES6 collection API.
|
|
992
742
|
*
|
|
993
|
-
* <!-- runkit:activate -->
|
|
994
|
-
* ```js
|
|
995
|
-
* const { Map } = require('immutable')
|
|
996
|
-
* const originalMap = Map({
|
|
997
|
-
* key: 'value',
|
|
998
|
-
* otherKey: 'other value'
|
|
999
|
-
* })
|
|
1000
|
-
* // Map { "key": "value", "otherKey": "other value" }
|
|
1001
|
-
* originalMap.delete('otherKey')
|
|
1002
|
-
* // Map { "key": "value" }
|
|
1003
|
-
* ```
|
|
1004
|
-
*
|
|
1005
743
|
* Note: `delete` can be used in `withMutations`.
|
|
1006
744
|
*
|
|
1007
745
|
* @alias remove
|
|
@@ -1012,14 +750,6 @@ declare namespace Immutable {
|
|
|
1012
750
|
/**
|
|
1013
751
|
* Returns a new Map which excludes the provided `keys`.
|
|
1014
752
|
*
|
|
1015
|
-
* <!-- runkit:activate -->
|
|
1016
|
-
* ```js
|
|
1017
|
-
* const { Map } = require('immutable')
|
|
1018
|
-
* const names = Map({ a: "Aaron", b: "Barry", c: "Connor" })
|
|
1019
|
-
* names.deleteAll([ 'a', 'c' ])
|
|
1020
|
-
* // Map { "b": "Barry" }
|
|
1021
|
-
* ```
|
|
1022
|
-
*
|
|
1023
753
|
* Note: `deleteAll` can be used in `withMutations`.
|
|
1024
754
|
*
|
|
1025
755
|
* @alias removeAll
|
|
@@ -1030,13 +760,6 @@ declare namespace Immutable {
|
|
|
1030
760
|
/**
|
|
1031
761
|
* Returns a new Map containing no keys or values.
|
|
1032
762
|
*
|
|
1033
|
-
* <!-- runkit:activate -->
|
|
1034
|
-
* ```js
|
|
1035
|
-
* const { Map } = require('immutable')
|
|
1036
|
-
* Map({ key: 'value' }).clear()
|
|
1037
|
-
* // Map {}
|
|
1038
|
-
* ```
|
|
1039
|
-
*
|
|
1040
763
|
* Note: `clear` can be used in `withMutations`.
|
|
1041
764
|
*/
|
|
1042
765
|
clear(): this;
|
|
@@ -1047,100 +770,31 @@ declare namespace Immutable {
|
|
|
1047
770
|
*
|
|
1048
771
|
* Similar to: `map.set(key, updater(map.get(key)))`.
|
|
1049
772
|
*
|
|
1050
|
-
* <!-- runkit:activate -->
|
|
1051
|
-
* ```js
|
|
1052
|
-
* const { Map } = require('immutable')
|
|
1053
|
-
* const aMap = Map({ key: 'value' })
|
|
1054
|
-
* const newMap = aMap.update('key', value => value + value)
|
|
1055
|
-
* // Map { "key": "valuevalue" }
|
|
1056
|
-
* ```
|
|
1057
|
-
*
|
|
1058
773
|
* This is most commonly used to call methods on collections within a
|
|
1059
774
|
* structure of data. For example, in order to `.push()` onto a nested `List`,
|
|
1060
775
|
* `update` and `push` can be used together:
|
|
1061
776
|
*
|
|
1062
|
-
* <!-- runkit:activate
|
|
1063
|
-
* { "preamble": "const { Map, List } = require('immutable');" }
|
|
1064
|
-
* -->
|
|
1065
|
-
* ```js
|
|
1066
|
-
* const aMap = Map({ nestedList: List([ 1, 2, 3 ]) })
|
|
1067
|
-
* const newMap = aMap.update('nestedList', list => list.push(4))
|
|
1068
|
-
* // Map { "nestedList": List [ 1, 2, 3, 4 ] }
|
|
1069
|
-
* ```
|
|
1070
|
-
*
|
|
1071
777
|
* When a `notSetValue` is provided, it is provided to the `updater`
|
|
1072
778
|
* function when the value at the key does not exist in the Map.
|
|
1073
779
|
*
|
|
1074
|
-
* <!-- runkit:activate
|
|
1075
|
-
* { "preamble": "const { Map } = require('immutable');" }
|
|
1076
|
-
* -->
|
|
1077
|
-
* ```js
|
|
1078
|
-
* const aMap = Map({ key: 'value' })
|
|
1079
|
-
* const newMap = aMap.update('noKey', 'no value', value => value + value)
|
|
1080
|
-
* // Map { "key": "value", "noKey": "no valueno value" }
|
|
1081
|
-
* ```
|
|
1082
|
-
*
|
|
1083
780
|
* However, if the `updater` function returns the same value it was called
|
|
1084
781
|
* with, then no change will occur. This is still true if `notSetValue`
|
|
1085
782
|
* is provided.
|
|
1086
783
|
*
|
|
1087
|
-
* <!-- runkit:activate
|
|
1088
|
-
* { "preamble": "const { Map } = require('immutable');" }
|
|
1089
|
-
* -->
|
|
1090
|
-
* ```js
|
|
1091
|
-
* const aMap = Map({ apples: 10 })
|
|
1092
|
-
* const newMap = aMap.update('oranges', 0, val => val)
|
|
1093
|
-
* // Map { "apples": 10 }
|
|
1094
|
-
* assert.strictEqual(newMap, map);
|
|
1095
|
-
* ```
|
|
1096
|
-
*
|
|
1097
784
|
* For code using ES2015 or later, using `notSetValue` is discourged in
|
|
1098
785
|
* favor of function parameter default values. This helps to avoid any
|
|
1099
786
|
* potential confusion with identify functions as described above.
|
|
1100
787
|
*
|
|
1101
788
|
* The previous example behaves differently when written with default values:
|
|
1102
789
|
*
|
|
1103
|
-
* <!-- runkit:activate
|
|
1104
|
-
* { "preamble": "const { Map } = require('immutable');" }
|
|
1105
|
-
* -->
|
|
1106
|
-
* ```js
|
|
1107
|
-
* const aMap = Map({ apples: 10 })
|
|
1108
|
-
* const newMap = aMap.update('oranges', (val = 0) => val)
|
|
1109
|
-
* // Map { "apples": 10, "oranges": 0 }
|
|
1110
|
-
* ```
|
|
1111
|
-
*
|
|
1112
790
|
* If no key is provided, then the `updater` function return value is
|
|
1113
791
|
* returned as well.
|
|
1114
792
|
*
|
|
1115
|
-
* <!-- runkit:activate
|
|
1116
|
-
* { "preamble": "const { Map } = require('immutable');" }
|
|
1117
|
-
* -->
|
|
1118
|
-
* ```js
|
|
1119
|
-
* const aMap = Map({ key: 'value' })
|
|
1120
|
-
* const result = aMap.update(aMap => aMap.get('key'))
|
|
1121
|
-
* // "value"
|
|
1122
|
-
* ```
|
|
1123
|
-
*
|
|
1124
793
|
* This can be very useful as a way to "chain" a normal function into a
|
|
1125
794
|
* sequence of methods. RxJS calls this "let" and lodash calls it "thru".
|
|
1126
795
|
*
|
|
1127
796
|
* For example, to sum the values in a Map
|
|
1128
797
|
*
|
|
1129
|
-
* <!-- runkit:activate
|
|
1130
|
-
* { "preamble": "const { Map } = require('immutable');" }
|
|
1131
|
-
* -->
|
|
1132
|
-
* ```js
|
|
1133
|
-
* function sum(collection) {
|
|
1134
|
-
* return collection.reduce((sum, x) => sum + x, 0)
|
|
1135
|
-
* }
|
|
1136
|
-
*
|
|
1137
|
-
* Map({ x: 1, y: 2, z: 3 })
|
|
1138
|
-
* .map(x => x + 1)
|
|
1139
|
-
* .filter(x => x % 2 === 0)
|
|
1140
|
-
* .update(sum)
|
|
1141
|
-
* // 6
|
|
1142
|
-
* ```
|
|
1143
|
-
*
|
|
1144
798
|
* Note: `update(key)` can be used in `withMutations`.
|
|
1145
799
|
*/
|
|
1146
800
|
update(key: K, notSetValue: V, updater: (value: V) => V): this;
|
|
@@ -1154,14 +808,6 @@ declare namespace Immutable {
|
|
|
1154
808
|
*
|
|
1155
809
|
* Note: Values provided to `merge` are shallowly converted before being
|
|
1156
810
|
* merged. No nested values are altered.
|
|
1157
|
-
*
|
|
1158
|
-
* <!-- runkit:activate -->
|
|
1159
|
-
* ```js
|
|
1160
|
-
* const { Map } = require('immutable')
|
|
1161
|
-
* const one = Map({ a: 10, b: 20, c: 30 })
|
|
1162
|
-
* const two = Map({ b: 40, a: 50, d: 60 })
|
|
1163
|
-
* one.merge(two) // Map { "a": 50, "b": 40, "c": 30, "d": 60 }
|
|
1164
|
-
* two.merge(one) // Map { "b": 20, "a": 10, "d": 60, "c": 30 }
|
|
1165
811
|
* ```
|
|
1166
812
|
*
|
|
1167
813
|
* Note: `merge` can be used in `withMutations`.
|
|
@@ -1187,17 +833,6 @@ declare namespace Immutable {
|
|
|
1187
833
|
* the provided Collections (or JS objects) into this Map, but uses the
|
|
1188
834
|
* `merger` function for dealing with conflicts.
|
|
1189
835
|
*
|
|
1190
|
-
* <!-- runkit:activate -->
|
|
1191
|
-
* ```js
|
|
1192
|
-
* const { Map } = require('immutable')
|
|
1193
|
-
* const one = Map({ a: 10, b: 20, c: 30 })
|
|
1194
|
-
* const two = Map({ b: 40, a: 50, d: 60 })
|
|
1195
|
-
* one.mergeWith((oldVal, newVal) => oldVal / newVal, two)
|
|
1196
|
-
* // { "a": 0.2, "b": 0.5, "c": 30, "d": 60 }
|
|
1197
|
-
* two.mergeWith((oldVal, newVal) => oldVal / newVal, one)
|
|
1198
|
-
* // { "b": 2, "a": 5, "d": 60, "c": 30 }
|
|
1199
|
-
* ```
|
|
1200
|
-
*
|
|
1201
836
|
* Note: `mergeWith` can be used in `withMutations`.
|
|
1202
837
|
*/
|
|
1203
838
|
mergeWith<KC, VC, VCC>(
|
|
@@ -1223,19 +858,6 @@ declare namespace Immutable {
|
|
|
1223
858
|
* Note: Indexed and set-like collections are merged using
|
|
1224
859
|
* `concat()`/`union()` and therefore do not recurse.
|
|
1225
860
|
*
|
|
1226
|
-
* <!-- runkit:activate -->
|
|
1227
|
-
* ```js
|
|
1228
|
-
* const { Map } = require('immutable')
|
|
1229
|
-
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
|
1230
|
-
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
|
1231
|
-
* one.mergeDeep(two)
|
|
1232
|
-
* // Map {
|
|
1233
|
-
* // "a": Map { "x": 2, "y": 10 },
|
|
1234
|
-
* // "b": Map { "x": 20, "y": 5 },
|
|
1235
|
-
* // "c": Map { "z": 3 }
|
|
1236
|
-
* // }
|
|
1237
|
-
* ```
|
|
1238
|
-
*
|
|
1239
861
|
* Note: `mergeDeep` can be used in `withMutations`.
|
|
1240
862
|
*/
|
|
1241
863
|
mergeDeep<KC, VC>(
|
|
@@ -1252,19 +874,6 @@ declare namespace Immutable {
|
|
|
1252
874
|
* incompatible if they fall into separate categories between keyed,
|
|
1253
875
|
* indexed, and set-like.
|
|
1254
876
|
*
|
|
1255
|
-
* <!-- runkit:activate -->
|
|
1256
|
-
* ```js
|
|
1257
|
-
* const { Map } = require('immutable')
|
|
1258
|
-
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
|
1259
|
-
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
|
1260
|
-
* one.mergeDeepWith((oldVal, newVal) => oldVal / newVal, two)
|
|
1261
|
-
* // Map {
|
|
1262
|
-
* // "a": Map { "x": 5, "y": 10 },
|
|
1263
|
-
* // "b": Map { "x": 20, "y": 10 },
|
|
1264
|
-
* // "c": Map { "z": 3 }
|
|
1265
|
-
* // }
|
|
1266
|
-
* ```
|
|
1267
|
-
*
|
|
1268
877
|
* Note: `mergeDeepWith` can be used in `withMutations`.
|
|
1269
878
|
*/
|
|
1270
879
|
mergeDeepWith(
|
|
@@ -1278,63 +887,10 @@ declare namespace Immutable {
|
|
|
1278
887
|
* Returns a new Map having set `value` at this `keyPath`. If any keys in
|
|
1279
888
|
* `keyPath` do not exist, a new immutable Map will be created at that key.
|
|
1280
889
|
*
|
|
1281
|
-
* <!-- runkit:activate -->
|
|
1282
|
-
* ```js
|
|
1283
|
-
* const { Map } = require('immutable')
|
|
1284
|
-
* const originalMap = Map({
|
|
1285
|
-
* subObject: Map({
|
|
1286
|
-
* subKey: 'subvalue',
|
|
1287
|
-
* subSubObject: Map({
|
|
1288
|
-
* subSubKey: 'subSubValue'
|
|
1289
|
-
* })
|
|
1290
|
-
* })
|
|
1291
|
-
* })
|
|
1292
|
-
*
|
|
1293
|
-
* const newMap = originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
|
|
1294
|
-
* // Map {
|
|
1295
|
-
* // "subObject": Map {
|
|
1296
|
-
* // "subKey": "ha ha!",
|
|
1297
|
-
* // "subSubObject": Map { "subSubKey": "subSubValue" }
|
|
1298
|
-
* // }
|
|
1299
|
-
* // }
|
|
1300
|
-
*
|
|
1301
|
-
* const newerMap = originalMap.setIn(
|
|
1302
|
-
* ['subObject', 'subSubObject', 'subSubKey'],
|
|
1303
|
-
* 'ha ha ha!'
|
|
1304
|
-
* )
|
|
1305
|
-
* // Map {
|
|
1306
|
-
* // "subObject": Map {
|
|
1307
|
-
* // "subKey": "subvalue",
|
|
1308
|
-
* // "subSubObject": Map { "subSubKey": "ha ha ha!" }
|
|
1309
|
-
* // }
|
|
1310
|
-
* // }
|
|
1311
|
-
* ```
|
|
1312
|
-
*
|
|
1313
890
|
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
1314
891
|
* Collection, and setIn() can update those values as well, treating them
|
|
1315
892
|
* immutably by creating new copies of those values with the changes applied.
|
|
1316
893
|
*
|
|
1317
|
-
* <!-- runkit:activate -->
|
|
1318
|
-
* ```js
|
|
1319
|
-
* const { Map } = require('immutable')
|
|
1320
|
-
* const originalMap = Map({
|
|
1321
|
-
* subObject: {
|
|
1322
|
-
* subKey: 'subvalue',
|
|
1323
|
-
* subSubObject: {
|
|
1324
|
-
* subSubKey: 'subSubValue'
|
|
1325
|
-
* }
|
|
1326
|
-
* }
|
|
1327
|
-
* })
|
|
1328
|
-
*
|
|
1329
|
-
* originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
|
|
1330
|
-
* // Map {
|
|
1331
|
-
* // "subObject": {
|
|
1332
|
-
* // subKey: "ha ha!",
|
|
1333
|
-
* // subSubObject: { subSubKey: "subSubValue" }
|
|
1334
|
-
* // }
|
|
1335
|
-
* // }
|
|
1336
|
-
* ```
|
|
1337
|
-
*
|
|
1338
894
|
* If any key in the path exists but cannot be updated (such as a primitive
|
|
1339
895
|
* like number or a custom Object like Date), an error will be thrown.
|
|
1340
896
|
*
|
|
@@ -1360,70 +916,26 @@ declare namespace Immutable {
|
|
|
1360
916
|
* This is most commonly used to call methods on collections nested within a
|
|
1361
917
|
* structure of data. For example, in order to `.push()` onto a nested `List`,
|
|
1362
918
|
* `updateIn` and `push` can be used together:
|
|
1363
|
-
|
|
1364
|
-
* <!-- runkit:activate -->
|
|
1365
|
-
* ```js
|
|
1366
|
-
* const { Map, List } = require('immutable')
|
|
1367
|
-
* const map = Map({ inMap: Map({ inList: List([ 1, 2, 3 ]) }) })
|
|
1368
|
-
* const newMap = map.updateIn(['inMap', 'inList'], list => list.push(4))
|
|
1369
|
-
* // Map { "inMap": Map { "inList": List [ 1, 2, 3, 4 ] } }
|
|
1370
|
-
* ```
|
|
919
|
+
|
|
1371
920
|
*
|
|
1372
921
|
* If any keys in `keyPath` do not exist, new Immutable `Map`s will
|
|
1373
922
|
* be created at those keys. If the `keyPath` does not already contain a
|
|
1374
923
|
* value, the `updater` function will be called with `notSetValue`, if
|
|
1375
924
|
* provided, otherwise `undefined`.
|
|
1376
925
|
*
|
|
1377
|
-
* <!-- runkit:activate
|
|
1378
|
-
* { "preamble": "const { Map } = require('immutable')" }
|
|
1379
|
-
* -->
|
|
1380
|
-
* ```js
|
|
1381
|
-
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
1382
|
-
* const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
|
|
1383
|
-
* // Map { "a": Map { "b": Map { "c": 20 } } }
|
|
1384
|
-
* ```
|
|
1385
|
-
*
|
|
1386
926
|
* If the `updater` function returns the same value it was called with, then
|
|
1387
927
|
* no change will occur. This is still true if `notSetValue` is provided.
|
|
1388
928
|
*
|
|
1389
|
-
* <!-- runkit:activate
|
|
1390
|
-
* { "preamble": "const { Map } = require('immutable')" }
|
|
1391
|
-
* -->
|
|
1392
|
-
* ```js
|
|
1393
|
-
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
1394
|
-
* const newMap = map.updateIn(['a', 'b', 'x'], 100, val => val)
|
|
1395
|
-
* // Map { "a": Map { "b": Map { "c": 10 } } }
|
|
1396
|
-
* assert.strictEqual(newMap, aMap)
|
|
1397
|
-
* ```
|
|
1398
|
-
*
|
|
1399
929
|
* For code using ES2015 or later, using `notSetValue` is discourged in
|
|
1400
930
|
* favor of function parameter default values. This helps to avoid any
|
|
1401
931
|
* potential confusion with identify functions as described above.
|
|
1402
932
|
*
|
|
1403
933
|
* The previous example behaves differently when written with default values:
|
|
1404
934
|
*
|
|
1405
|
-
* <!-- runkit:activate
|
|
1406
|
-
* { "preamble": "const { Map } = require('immutable')" }
|
|
1407
|
-
* -->
|
|
1408
|
-
* ```js
|
|
1409
|
-
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
1410
|
-
* const newMap = map.updateIn(['a', 'b', 'x'], (val = 100) => val)
|
|
1411
|
-
* // Map { "a": Map { "b": Map { "c": 10, "x": 100 } } }
|
|
1412
|
-
* ```
|
|
1413
|
-
*
|
|
1414
935
|
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
1415
936
|
* Collection, and updateIn() can update those values as well, treating them
|
|
1416
937
|
* immutably by creating new copies of those values with the changes applied.
|
|
1417
938
|
*
|
|
1418
|
-
* <!-- runkit:activate
|
|
1419
|
-
* { "preamble": "const { Map } = require('immutable')" }
|
|
1420
|
-
* -->
|
|
1421
|
-
* ```js
|
|
1422
|
-
* const map = Map({ a: { b: { c: 10 } } })
|
|
1423
|
-
* const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
|
|
1424
|
-
* // Map { "a": { b: { c: 20 } } }
|
|
1425
|
-
* ```
|
|
1426
|
-
*
|
|
1427
939
|
* If any key in the path exists but cannot be updated (such as a primitive
|
|
1428
940
|
* like number or a custom Object like Date), an error will be thrown.
|
|
1429
941
|
*
|
|
@@ -1485,17 +997,6 @@ declare namespace Immutable {
|
|
|
1485
997
|
*
|
|
1486
998
|
* As an example, this results in the creation of 2, not 4, new Maps:
|
|
1487
999
|
*
|
|
1488
|
-
* <!-- runkit:activate -->
|
|
1489
|
-
* ```js
|
|
1490
|
-
* const { Map } = require('immutable')
|
|
1491
|
-
* const map1 = Map()
|
|
1492
|
-
* const map2 = map1.withMutations(map => {
|
|
1493
|
-
* map.set('a', 1).set('b', 2).set('c', 3)
|
|
1494
|
-
* })
|
|
1495
|
-
* assert.equal(map1.size, 0)
|
|
1496
|
-
* assert.equal(map2.size, 3)
|
|
1497
|
-
* ```
|
|
1498
|
-
*
|
|
1499
1000
|
* Note: Not all methods can be used on a mutable collection or within
|
|
1500
1001
|
* `withMutations`! Read the documentation for each method to see if it
|
|
1501
1002
|
* is safe to use in `withMutations`.
|
|
@@ -1637,17 +1138,6 @@ declare namespace Immutable {
|
|
|
1637
1138
|
* * Is pure, i.e. it must always return the same value for the same pair
|
|
1638
1139
|
* of values.
|
|
1639
1140
|
*
|
|
1640
|
-
* <!-- runkit:activate -->
|
|
1641
|
-
* ```js
|
|
1642
|
-
* const { Map } = require('immutable')
|
|
1643
|
-
* Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
|
|
1644
|
-
* if (a < b) { return -1; }
|
|
1645
|
-
* if (a > b) { return 1; }
|
|
1646
|
-
* if (a === b) { return 0; }
|
|
1647
|
-
* });
|
|
1648
|
-
* // OrderedMap { "a": 1, "b": 2, "c": 3 }
|
|
1649
|
-
* ```
|
|
1650
|
-
*
|
|
1651
1141
|
* Note: `sort()` Always returns a new instance, even if the original was
|
|
1652
1142
|
* already sorted.
|
|
1653
1143
|
*
|
|
@@ -1659,18 +1149,6 @@ declare namespace Immutable {
|
|
|
1659
1149
|
* Like `sort`, but also accepts a `comparatorValueMapper` which allows for
|
|
1660
1150
|
* sorting by more sophisticated means:
|
|
1661
1151
|
*
|
|
1662
|
-
* <!-- runkit:activate -->
|
|
1663
|
-
* ```js
|
|
1664
|
-
* const { Map } = require('immutable')
|
|
1665
|
-
* const beattles = Map({
|
|
1666
|
-
* John: { name: "Lennon" },
|
|
1667
|
-
* Paul: { name: "McCartney" },
|
|
1668
|
-
* George: { name: "Harrison" },
|
|
1669
|
-
* Ringo: { name: "Starr" },
|
|
1670
|
-
* });
|
|
1671
|
-
* beattles.sortBy(member => member.name);
|
|
1672
|
-
* ```
|
|
1673
|
-
*
|
|
1674
1152
|
* Note: `sortBy()` Always returns a new instance, even if the original was
|
|
1675
1153
|
* already sorted.
|
|
1676
1154
|
*
|
|
@@ -1731,18 +1209,6 @@ declare namespace Immutable {
|
|
|
1731
1209
|
* equivalent key already exists in this OrderedMap, it will be replaced
|
|
1732
1210
|
* while maintaining the existing order.
|
|
1733
1211
|
*
|
|
1734
|
-
* <!-- runkit:activate -->
|
|
1735
|
-
* ```js
|
|
1736
|
-
* const { OrderedMap } = require('immutable')
|
|
1737
|
-
* const originalMap = OrderedMap({a:1, b:1, c:1})
|
|
1738
|
-
* const updatedMap = originalMap.set('b', 2)
|
|
1739
|
-
*
|
|
1740
|
-
* originalMap
|
|
1741
|
-
* // OrderedMap {a: 1, b: 1, c: 1}
|
|
1742
|
-
* updatedMap
|
|
1743
|
-
* // OrderedMap {a: 1, b: 2, c: 1}
|
|
1744
|
-
* ```
|
|
1745
|
-
*
|
|
1746
1212
|
* Note: `set` can be used in `withMutations`.
|
|
1747
1213
|
*/
|
|
1748
1214
|
set(key: K, value: V): this;
|
|
@@ -1755,15 +1221,6 @@ declare namespace Immutable {
|
|
|
1755
1221
|
* Note: Values provided to `merge` are shallowly converted before being
|
|
1756
1222
|
* merged. No nested values are altered.
|
|
1757
1223
|
*
|
|
1758
|
-
* <!-- runkit:activate -->
|
|
1759
|
-
* ```js
|
|
1760
|
-
* const { OrderedMap } = require('immutable')
|
|
1761
|
-
* const one = OrderedMap({ a: 10, b: 20, c: 30 })
|
|
1762
|
-
* const two = OrderedMap({ b: 40, a: 50, d: 60 })
|
|
1763
|
-
* one.merge(two) // OrderedMap { "a": 50, "b": 40, "c": 30, "d": 60 }
|
|
1764
|
-
* two.merge(one) // OrderedMap { "b": 20, "a": 10, "d": 60, "c": 30 }
|
|
1765
|
-
* ```
|
|
1766
|
-
*
|
|
1767
1224
|
* Note: `merge` can be used in `withMutations`.
|
|
1768
1225
|
*
|
|
1769
1226
|
* @alias concat
|
|
@@ -1915,7 +1372,7 @@ declare namespace Immutable {
|
|
|
1915
1372
|
* a collection of other sets.
|
|
1916
1373
|
*
|
|
1917
1374
|
* ```js
|
|
1918
|
-
*
|
|
1375
|
+
* import { Set } from 'immutable'
|
|
1919
1376
|
* const intersected = Set.intersect([
|
|
1920
1377
|
* Set([ 'a', 'b', 'c' ])
|
|
1921
1378
|
* Set([ 'c', 'a', 't' ])
|
|
@@ -1930,7 +1387,7 @@ declare namespace Immutable {
|
|
|
1930
1387
|
* collection of other sets.
|
|
1931
1388
|
*
|
|
1932
1389
|
* ```js
|
|
1933
|
-
*
|
|
1390
|
+
* import { Set } from 'immutable'
|
|
1934
1391
|
* const unioned = Set.union([
|
|
1935
1392
|
* Set([ 'a', 'b', 'c' ])
|
|
1936
1393
|
* Set([ 'c', 'a', 't' ])
|
|
@@ -2008,13 +1465,6 @@ declare namespace Immutable {
|
|
|
2008
1465
|
/**
|
|
2009
1466
|
* Returns a Set excluding any values contained within `collections`.
|
|
2010
1467
|
*
|
|
2011
|
-
* <!-- runkit:activate -->
|
|
2012
|
-
* ```js
|
|
2013
|
-
* const { OrderedSet } = require('immutable')
|
|
2014
|
-
* OrderedSet([ 1, 2, 3 ]).subtract([1, 3])
|
|
2015
|
-
* // OrderedSet [2]
|
|
2016
|
-
* ```
|
|
2017
|
-
*
|
|
2018
1468
|
* Note: `subtract` can be used in `withMutations`.
|
|
2019
1469
|
*/
|
|
2020
1470
|
subtract(...collections: Array<Iterable<T>>): this;
|
|
@@ -2117,17 +1567,6 @@ declare namespace Immutable {
|
|
|
2117
1567
|
* * Is pure, i.e. it must always return the same value for the same pair
|
|
2118
1568
|
* of values.
|
|
2119
1569
|
*
|
|
2120
|
-
* <!-- runkit:activate -->
|
|
2121
|
-
* ```js
|
|
2122
|
-
* const { Set } = require('immutable')
|
|
2123
|
-
* Set(['b', 'a', 'c']).sort((a, b) => {
|
|
2124
|
-
* if (a < b) { return -1; }
|
|
2125
|
-
* if (a > b) { return 1; }
|
|
2126
|
-
* if (a === b) { return 0; }
|
|
2127
|
-
* });
|
|
2128
|
-
* // OrderedSet { "a":, "b", "c" }
|
|
2129
|
-
* ```
|
|
2130
|
-
*
|
|
2131
1570
|
* Note: `sort()` Always returns a new instance, even if the original was
|
|
2132
1571
|
* already sorted.
|
|
2133
1572
|
*
|
|
@@ -2139,18 +1578,6 @@ declare namespace Immutable {
|
|
|
2139
1578
|
* Like `sort`, but also accepts a `comparatorValueMapper` which allows for
|
|
2140
1579
|
* sorting by more sophisticated means:
|
|
2141
1580
|
*
|
|
2142
|
-
* <!-- runkit:activate -->
|
|
2143
|
-
* ```js
|
|
2144
|
-
* const { Set } = require('immutable')
|
|
2145
|
-
* const beattles = Set([
|
|
2146
|
-
* { name: "Lennon" },
|
|
2147
|
-
* { name: "McCartney" },
|
|
2148
|
-
* { name: "Harrison" },
|
|
2149
|
-
* { name: "Starr" },
|
|
2150
|
-
* ]);
|
|
2151
|
-
* beattles.sortBy(member => member.name);
|
|
2152
|
-
* ```
|
|
2153
|
-
*
|
|
2154
1581
|
* Note: `sortBy()` Always returns a new instance, even if the original was
|
|
2155
1582
|
* already sorted.
|
|
2156
1583
|
*
|
|
@@ -2602,9 +2029,7 @@ declare namespace Immutable {
|
|
|
2602
2029
|
* `new` keyword during construction.
|
|
2603
2030
|
*
|
|
2604
2031
|
* ```js
|
|
2605
|
-
*
|
|
2606
|
-
* Range() // [ 0, 1, 2, 3, ... ]
|
|
2607
|
-
* Range(10) // [ 10, 11, 12, 13, ... ]
|
|
2032
|
+
* import { Range } from 'immutable'
|
|
2608
2033
|
* Range(10, 15) // [ 10, 11, 12, 13, 14 ]
|
|
2609
2034
|
* Range(10, 30, 5) // [ 10, 15, 20, 25 ]
|
|
2610
2035
|
* Range(30, 10, 5) // [ 30, 25, 20, 15 ]
|
|
@@ -2625,7 +2050,7 @@ declare namespace Immutable {
|
|
|
2625
2050
|
* `new` keyword during construction.
|
|
2626
2051
|
*
|
|
2627
2052
|
* ```js
|
|
2628
|
-
*
|
|
2053
|
+
* import { Repeat } from 'immutable'
|
|
2629
2054
|
* Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
|
|
2630
2055
|
* Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
|
|
2631
2056
|
* ```
|
|
@@ -2640,7 +2065,7 @@ declare namespace Immutable {
|
|
|
2640
2065
|
* create Record instances.
|
|
2641
2066
|
*
|
|
2642
2067
|
* ```js
|
|
2643
|
-
*
|
|
2068
|
+
* import { Record } from 'immutable'
|
|
2644
2069
|
* const ABRecord = Record({ a: 1, b: 2 })
|
|
2645
2070
|
* const myRecord = ABRecord({ b: 3 })
|
|
2646
2071
|
* ```
|
|
@@ -2804,7 +2229,7 @@ declare namespace Immutable {
|
|
|
2804
2229
|
* method. If one was not provided, the string "Record" is returned.
|
|
2805
2230
|
*
|
|
2806
2231
|
* ```js
|
|
2807
|
-
*
|
|
2232
|
+
* import { Record } from 'immutable'
|
|
2808
2233
|
* const Person = Record({
|
|
2809
2234
|
* name: null
|
|
2810
2235
|
* }, 'Person')
|
|
@@ -2823,48 +2248,9 @@ declare namespace Immutable {
|
|
|
2823
2248
|
* are created by passing it some of the accepted values for that Record
|
|
2824
2249
|
* type:
|
|
2825
2250
|
*
|
|
2826
|
-
* <!-- runkit:activate
|
|
2827
|
-
* { "preamble": "const { Record } = require('immutable')" }
|
|
2828
|
-
* -->
|
|
2829
|
-
* ```js
|
|
2830
|
-
* // makePerson is a Record Factory function
|
|
2831
|
-
* const makePerson = Record({ name: null, favoriteColor: 'unknown' });
|
|
2832
|
-
*
|
|
2833
|
-
* // alan is a Record instance
|
|
2834
|
-
* const alan = makePerson({ name: 'Alan' });
|
|
2835
|
-
* ```
|
|
2836
|
-
*
|
|
2837
2251
|
* Note that Record Factories return `Record<TProps> & Readonly<TProps>`,
|
|
2838
2252
|
* this allows use of both the Record instance API, and direct property
|
|
2839
2253
|
* access on the resulting instances:
|
|
2840
|
-
*
|
|
2841
|
-
* <!-- runkit:activate
|
|
2842
|
-
* { "preamble": "const { Record } = require('immutable');const makePerson = Record({ name: null, favoriteColor: 'unknown' });const alan = makePerson({ name: 'Alan' });" }
|
|
2843
|
-
* -->
|
|
2844
|
-
* ```js
|
|
2845
|
-
* // Use the Record API
|
|
2846
|
-
* console.log('Record API: ' + alan.get('name'))
|
|
2847
|
-
*
|
|
2848
|
-
* // Or direct property access (Readonly)
|
|
2849
|
-
* console.log('property access: ' + alan.name)
|
|
2850
|
-
* ```
|
|
2851
|
-
*
|
|
2852
|
-
* **Flow Typing Records:**
|
|
2853
|
-
*
|
|
2854
|
-
* Use the `RecordFactory<TProps>` Flow type to get high quality type checking of
|
|
2855
|
-
* Records:
|
|
2856
|
-
*
|
|
2857
|
-
* ```js
|
|
2858
|
-
* import type { RecordFactory, RecordOf } from 'immutable';
|
|
2859
|
-
*
|
|
2860
|
-
* // Use RecordFactory<TProps> for defining new Record factory functions.
|
|
2861
|
-
* type PersonProps = { name: ?string, favoriteColor: string };
|
|
2862
|
-
* const makePerson: RecordFactory<PersonProps> = Record({ name: null, favoriteColor: 'unknown' });
|
|
2863
|
-
*
|
|
2864
|
-
* // Use RecordOf<T> for defining new instances of that Record.
|
|
2865
|
-
* type Person = RecordOf<PersonProps>;
|
|
2866
|
-
* const alan: Person = makePerson({ name: 'Alan' });
|
|
2867
|
-
* ```
|
|
2868
2254
|
*/
|
|
2869
2255
|
namespace Factory {}
|
|
2870
2256
|
|
|
@@ -3063,7 +2449,7 @@ declare namespace Immutable {
|
|
|
3063
2449
|
* `Seq`'s values are never iterated:
|
|
3064
2450
|
*
|
|
3065
2451
|
* ```js
|
|
3066
|
-
*
|
|
2452
|
+
* import { Seq } from 'immutable'
|
|
3067
2453
|
* const oddSquares = Seq([ 1, 2, 3, 4, 5, 6, 7, 8 ])
|
|
3068
2454
|
* .filter(x => x % 2 !== 0)
|
|
3069
2455
|
* .map(x => x * x)
|
|
@@ -3079,13 +2465,6 @@ declare namespace Immutable {
|
|
|
3079
2465
|
*
|
|
3080
2466
|
* Any collection can be converted to a lazy Seq with `Seq()`.
|
|
3081
2467
|
*
|
|
3082
|
-
* <!-- runkit:activate -->
|
|
3083
|
-
* ```js
|
|
3084
|
-
* const { Map } = require('immutable')
|
|
3085
|
-
* const map = Map({ a: 1, b: 2, c: 3 })
|
|
3086
|
-
* const lazySeq = Seq(map)
|
|
3087
|
-
* ```
|
|
3088
|
-
*
|
|
3089
2468
|
* `Seq` allows for the efficient chaining of operations, allowing for the
|
|
3090
2469
|
* expression of logic that can otherwise be very tedious:
|
|
3091
2470
|
*
|
|
@@ -3100,18 +2479,6 @@ declare namespace Immutable {
|
|
|
3100
2479
|
* As well as expressing logic that would otherwise seem memory or time
|
|
3101
2480
|
* limited, for example `Range` is a special kind of Lazy sequence.
|
|
3102
2481
|
*
|
|
3103
|
-
* <!-- runkit:activate -->
|
|
3104
|
-
* ```js
|
|
3105
|
-
* const { Range } = require('immutable')
|
|
3106
|
-
* Range(1, Infinity)
|
|
3107
|
-
* .skip(1000)
|
|
3108
|
-
* .map(n => -n)
|
|
3109
|
-
* .filter(n => n % 2 === 0)
|
|
3110
|
-
* .take(2)
|
|
3111
|
-
* .reduce((r, n) => r * n, 1)
|
|
3112
|
-
* // 1006008
|
|
3113
|
-
* ```
|
|
3114
|
-
*
|
|
3115
2482
|
* Seq is often used to provide a rich collection API to JavaScript Object.
|
|
3116
2483
|
*
|
|
3117
2484
|
* ```js
|
|
@@ -3190,7 +2557,7 @@ declare namespace Immutable {
|
|
|
3190
2557
|
* `mapper` function.
|
|
3191
2558
|
*
|
|
3192
2559
|
* ```js
|
|
3193
|
-
*
|
|
2560
|
+
* import { Seq } from 'immutable'
|
|
3194
2561
|
* Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
|
|
3195
2562
|
* // Seq { "a": 10, "b": 20 }
|
|
3196
2563
|
* ```
|
|
@@ -3324,7 +2691,7 @@ declare namespace Immutable {
|
|
|
3324
2691
|
* `mapper` function.
|
|
3325
2692
|
*
|
|
3326
2693
|
* ```js
|
|
3327
|
-
*
|
|
2694
|
+
* import { Seq } from 'immutable'
|
|
3328
2695
|
* Seq.Indexed([ 1, 2 ]).map(x => 10 * x)
|
|
3329
2696
|
* // Seq [ 10, 20 ]
|
|
3330
2697
|
* ```
|
|
@@ -3627,7 +2994,7 @@ declare namespace Immutable {
|
|
|
3627
2994
|
* `mapper` function.
|
|
3628
2995
|
*
|
|
3629
2996
|
* ```js
|
|
3630
|
-
*
|
|
2997
|
+
* import { Seq } from 'immutable'
|
|
3631
2998
|
* Seq([ 1, 2 ]).map(x => 10 * x)
|
|
3632
2999
|
* // Seq [ 10, 20 ]
|
|
3633
3000
|
* ```
|
|
@@ -3645,7 +3012,7 @@ declare namespace Immutable {
|
|
|
3645
3012
|
* `mapper` function.
|
|
3646
3013
|
*
|
|
3647
3014
|
* ```js
|
|
3648
|
-
*
|
|
3015
|
+
* import { Seq } from 'immutable'
|
|
3649
3016
|
* Seq([ 1, 2 ]).map(x => 10 * x)
|
|
3650
3017
|
* // Seq [ 10, 20 ]
|
|
3651
3018
|
* ```
|
|
@@ -3786,13 +3153,6 @@ declare namespace Immutable {
|
|
|
3786
3153
|
/**
|
|
3787
3154
|
* Returns a new Collection.Keyed of the same type where the keys and values
|
|
3788
3155
|
* have been flipped.
|
|
3789
|
-
*
|
|
3790
|
-
* <!-- runkit:activate -->
|
|
3791
|
-
* ```js
|
|
3792
|
-
* const { Map } = require('immutable')
|
|
3793
|
-
* Map({ a: 'z', b: 'y' }).flip()
|
|
3794
|
-
* // Map { "z": "a", "y": "b" }
|
|
3795
|
-
* ```
|
|
3796
3156
|
*/
|
|
3797
3157
|
flip(): Collection.Keyed<V, K>;
|
|
3798
3158
|
|
|
@@ -3811,7 +3171,7 @@ declare namespace Immutable {
|
|
|
3811
3171
|
* `mapper` function.
|
|
3812
3172
|
*
|
|
3813
3173
|
* ```js
|
|
3814
|
-
*
|
|
3174
|
+
* import { Collection } from 'immutable'
|
|
3815
3175
|
* Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
|
|
3816
3176
|
* // Seq { "a": 10, "b": 20 }
|
|
3817
3177
|
* ```
|
|
@@ -3828,13 +3188,6 @@ declare namespace Immutable {
|
|
|
3828
3188
|
* Returns a new Collection.Keyed of the same type with keys passed through
|
|
3829
3189
|
* a `mapper` function.
|
|
3830
3190
|
*
|
|
3831
|
-
* <!-- runkit:activate -->
|
|
3832
|
-
* ```js
|
|
3833
|
-
* const { Map } = require('immutable')
|
|
3834
|
-
* Map({ a: 1, b: 2 }).mapKeys(x => x.toUpperCase())
|
|
3835
|
-
* // Map { "A": 1, "B": 2 }
|
|
3836
|
-
* ```
|
|
3837
|
-
*
|
|
3838
3191
|
* Note: `mapKeys()` always returns a new instance, even if it produced
|
|
3839
3192
|
* the same key at every step.
|
|
3840
3193
|
*/
|
|
@@ -3847,14 +3200,6 @@ declare namespace Immutable {
|
|
|
3847
3200
|
* Returns a new Collection.Keyed of the same type with entries
|
|
3848
3201
|
* ([key, value] tuples) passed through a `mapper` function.
|
|
3849
3202
|
*
|
|
3850
|
-
* <!-- runkit:activate -->
|
|
3851
|
-
* ```js
|
|
3852
|
-
* const { Map } = require('immutable')
|
|
3853
|
-
* Map({ a: 1, b: 2 })
|
|
3854
|
-
* .mapEntries(([ k, v ]) => [ k.toUpperCase(), v * 2 ])
|
|
3855
|
-
* // Map { "A": 2, "B": 4 }
|
|
3856
|
-
* ```
|
|
3857
|
-
*
|
|
3858
3203
|
* Note: `mapEntries()` always returns a new instance, even if it produced
|
|
3859
3204
|
* the same entry at every step.
|
|
3860
3205
|
*
|
|
@@ -3996,28 +3341,8 @@ declare namespace Immutable {
|
|
|
3996
3341
|
* The resulting Collection includes the first item from each, then the
|
|
3997
3342
|
* second from each, etc.
|
|
3998
3343
|
*
|
|
3999
|
-
* <!-- runkit:activate
|
|
4000
|
-
* { "preamble": "require('immutable')"}
|
|
4001
|
-
* -->
|
|
4002
|
-
* ```js
|
|
4003
|
-
* const { List } = require('immutable')
|
|
4004
|
-
* List([ 1, 2, 3 ]).interleave(List([ 'A', 'B', 'C' ]))
|
|
4005
|
-
* // List [ 1, "A", 2, "B", 3, "C" ]
|
|
4006
|
-
* ```
|
|
4007
|
-
*
|
|
4008
3344
|
* The shortest Collection stops interleave.
|
|
4009
3345
|
*
|
|
4010
|
-
* <!-- runkit:activate
|
|
4011
|
-
* { "preamble": "const { List } = require('immutable')" }
|
|
4012
|
-
* -->
|
|
4013
|
-
* ```js
|
|
4014
|
-
* List([ 1, 2, 3 ]).interleave(
|
|
4015
|
-
* List([ 'A', 'B' ]),
|
|
4016
|
-
* List([ 'X', 'Y', 'Z' ])
|
|
4017
|
-
* )
|
|
4018
|
-
* // List [ 1, "A", "X", 2, "B", "Y" ]
|
|
4019
|
-
* ```
|
|
4020
|
-
*
|
|
4021
3346
|
* Since `interleave()` re-indexes values, it produces a complete copy,
|
|
4022
3347
|
* which has `O(N)` complexity.
|
|
4023
3348
|
*
|
|
@@ -4033,13 +3358,6 @@ declare namespace Immutable {
|
|
|
4033
3358
|
* `index` may be a negative number, which indexes back from the end of the
|
|
4034
3359
|
* Collection. `s.splice(-2)` splices after the second to last item.
|
|
4035
3360
|
*
|
|
4036
|
-
* <!-- runkit:activate -->
|
|
4037
|
-
* ```js
|
|
4038
|
-
* const { List } = require('immutable')
|
|
4039
|
-
* List([ 'a', 'b', 'c', 'd' ]).splice(1, 2, 'q', 'r', 's')
|
|
4040
|
-
* // List [ "a", "q", "r", "s", "d" ]
|
|
4041
|
-
* ```
|
|
4042
|
-
*
|
|
4043
3361
|
* Since `splice()` re-indexes values, it produces a complete copy, which
|
|
4044
3362
|
* has `O(N)` complexity.
|
|
4045
3363
|
*
|
|
@@ -4052,16 +3370,6 @@ declare namespace Immutable {
|
|
|
4052
3370
|
* collections.
|
|
4053
3371
|
*
|
|
4054
3372
|
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
|
4055
|
-
*
|
|
4056
|
-
*
|
|
4057
|
-
* <!-- runkit:activate
|
|
4058
|
-
* { "preamble": "const { List } = require('immutable')" }
|
|
4059
|
-
* -->
|
|
4060
|
-
* ```js
|
|
4061
|
-
* const a = List([ 1, 2, 3 ]);
|
|
4062
|
-
* const b = List([ 4, 5, 6 ]);
|
|
4063
|
-
* const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
|
4064
|
-
* ```
|
|
4065
3373
|
*/
|
|
4066
3374
|
zip<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
|
|
4067
3375
|
zip<U, V>(
|
|
@@ -4096,16 +3404,6 @@ declare namespace Immutable {
|
|
|
4096
3404
|
/**
|
|
4097
3405
|
* Returns a Collection of the same type "zipped" with the provided
|
|
4098
3406
|
* collections by using a custom `zipper` function.
|
|
4099
|
-
*
|
|
4100
|
-
* <!-- runkit:activate
|
|
4101
|
-
* { "preamble": "const { List } = require('immutable')" }
|
|
4102
|
-
* -->
|
|
4103
|
-
* ```js
|
|
4104
|
-
* const a = List([ 1, 2, 3 ]);
|
|
4105
|
-
* const b = List([ 4, 5, 6 ]);
|
|
4106
|
-
* const c = a.zipWith((a, b) => a + b, b);
|
|
4107
|
-
* // List [ 5, 7, 9 ]
|
|
4108
|
-
* ```
|
|
4109
3407
|
*/
|
|
4110
3408
|
zipWith<U, Z>(
|
|
4111
3409
|
zipper: (value: T, otherValue: U) => Z,
|
|
@@ -4167,7 +3465,7 @@ declare namespace Immutable {
|
|
|
4167
3465
|
* `mapper` function.
|
|
4168
3466
|
*
|
|
4169
3467
|
* ```js
|
|
4170
|
-
*
|
|
3468
|
+
* import { Collection } from 'immutable'
|
|
4171
3469
|
* Collection.Indexed([1,2]).map(x => 10 * x)
|
|
4172
3470
|
* // Seq [ 1, 2 ]
|
|
4173
3471
|
* ```
|
|
@@ -4232,7 +3530,7 @@ declare namespace Immutable {
|
|
|
4232
3530
|
* the value as both the first and second arguments to the provided function.
|
|
4233
3531
|
*
|
|
4234
3532
|
* ```js
|
|
4235
|
-
*
|
|
3533
|
+
* import { Collection } from 'immutable'
|
|
4236
3534
|
* const seq = Collection.Set([ 'A', 'B', 'C' ])
|
|
4237
3535
|
* // Seq { "A", "B", "C" }
|
|
4238
3536
|
* seq.forEach((v, k) =>
|
|
@@ -4390,17 +3688,6 @@ declare namespace Immutable {
|
|
|
4390
3688
|
* and is used when adding this to a `Set` or as a key in a `Map`, enabling
|
|
4391
3689
|
* lookup via a different instance.
|
|
4392
3690
|
*
|
|
4393
|
-
* <!-- runkit:activate
|
|
4394
|
-
* { "preamble": "const { Set, List } = require('immutable')" }
|
|
4395
|
-
* -->
|
|
4396
|
-
* ```js
|
|
4397
|
-
* const a = List([ 1, 2, 3 ]);
|
|
4398
|
-
* const b = List([ 1, 2, 3 ]);
|
|
4399
|
-
* assert.notStrictEqual(a, b); // different instances
|
|
4400
|
-
* const set = Set([ a ]);
|
|
4401
|
-
* assert.equal(set.has(b), true);
|
|
4402
|
-
* ```
|
|
4403
|
-
*
|
|
4404
3691
|
* If two values have the same `hashCode`, they are [not guaranteed
|
|
4405
3692
|
* to be equal][Hash Collision]. If two values have different `hashCode`s,
|
|
4406
3693
|
* they must not be equal.
|
|
@@ -4460,22 +3747,8 @@ declare namespace Immutable {
|
|
|
4460
3747
|
* Returns the value found by following a path of keys or indices through
|
|
4461
3748
|
* nested Collections.
|
|
4462
3749
|
*
|
|
4463
|
-
* <!-- runkit:activate -->
|
|
4464
|
-
* ```js
|
|
4465
|
-
* const { Map, List } = require('immutable')
|
|
4466
|
-
* const deepData = Map({ x: List([ Map({ y: 123 }) ]) });
|
|
4467
|
-
* deepData.getIn(['x', 0, 'y']) // 123
|
|
4468
|
-
* ```
|
|
4469
|
-
*
|
|
4470
3750
|
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
4471
3751
|
* Collection, and getIn() can access those values as well:
|
|
4472
|
-
*
|
|
4473
|
-
* <!-- runkit:activate -->
|
|
4474
|
-
* ```js
|
|
4475
|
-
* const { Map, List } = require('immutable')
|
|
4476
|
-
* const deepData = Map({ x: [ { y: 123 } ] });
|
|
4477
|
-
* deepData.getIn(['x', 0, 'y']) // 123
|
|
4478
|
-
* ```
|
|
4479
3752
|
*/
|
|
4480
3753
|
getIn(searchKeyPath: Iterable<unknown>, notSetValue?: unknown): unknown;
|
|
4481
3754
|
|
|
@@ -4492,21 +3765,6 @@ declare namespace Immutable {
|
|
|
4492
3765
|
* sequence of methods. RxJS calls this "let" and lodash calls it "thru".
|
|
4493
3766
|
*
|
|
4494
3767
|
* For example, to sum a Seq after mapping and filtering:
|
|
4495
|
-
*
|
|
4496
|
-
* <!-- runkit:activate -->
|
|
4497
|
-
* ```js
|
|
4498
|
-
* const { Seq } = require('immutable')
|
|
4499
|
-
*
|
|
4500
|
-
* function sum(collection) {
|
|
4501
|
-
* return collection.reduce((sum, x) => sum + x, 0)
|
|
4502
|
-
* }
|
|
4503
|
-
*
|
|
4504
|
-
* Seq([ 1, 2, 3 ])
|
|
4505
|
-
* .map(x => x + 1)
|
|
4506
|
-
* .filter(x => x % 2 === 0)
|
|
4507
|
-
* .update(sum)
|
|
4508
|
-
* // 6
|
|
4509
|
-
* ```
|
|
4510
3768
|
*/
|
|
4511
3769
|
update<R>(updater: (value: this) => R): R;
|
|
4512
3770
|
|
|
@@ -4586,14 +3844,6 @@ declare namespace Immutable {
|
|
|
4586
3844
|
* expressions. However, when called on `Map` or other keyed collections,
|
|
4587
3845
|
* `collection.toList()` discards the keys and creates a list of only the
|
|
4588
3846
|
* values, whereas `List(collection)` creates a list of entry tuples.
|
|
4589
|
-
*
|
|
4590
|
-
* <!-- runkit:activate -->
|
|
4591
|
-
* ```js
|
|
4592
|
-
* const { Map, List } = require('immutable')
|
|
4593
|
-
* var myMap = Map({ a: 'Apple', b: 'Banana' })
|
|
4594
|
-
* List(myMap) // List [ [ "a", "Apple" ], [ "b", "Banana" ] ]
|
|
4595
|
-
* myMap.toList() // List [ "Apple", "Banana" ]
|
|
4596
|
-
* ```
|
|
4597
3847
|
*/
|
|
4598
3848
|
toList(): List<V>;
|
|
4599
3849
|
|
|
@@ -4622,19 +3872,6 @@ declare namespace Immutable {
|
|
|
4622
3872
|
*
|
|
4623
3873
|
* The returned Seq will have identical iteration order as
|
|
4624
3874
|
* this Collection.
|
|
4625
|
-
*
|
|
4626
|
-
* <!-- runkit:activate -->
|
|
4627
|
-
* ```js
|
|
4628
|
-
* const { Seq } = require('immutable')
|
|
4629
|
-
* const indexedSeq = Seq([ 'A', 'B', 'C' ])
|
|
4630
|
-
* // Seq [ "A", "B", "C" ]
|
|
4631
|
-
* indexedSeq.filter(v => v === 'B')
|
|
4632
|
-
* // Seq [ "B" ]
|
|
4633
|
-
* const keyedSeq = indexedSeq.toKeyedSeq()
|
|
4634
|
-
* // Seq { 0: "A", 1: "B", 2: "C" }
|
|
4635
|
-
* keyedSeq.filter(v => v === 'B')
|
|
4636
|
-
* // Seq { 1: "B" }
|
|
4637
|
-
* ```
|
|
4638
3875
|
*/
|
|
4639
3876
|
toKeyedSeq(): Seq.Keyed<K, V>;
|
|
4640
3877
|
|
|
@@ -4703,13 +3940,6 @@ declare namespace Immutable {
|
|
|
4703
3940
|
* Returns a new Collection of the same type with values passed through a
|
|
4704
3941
|
* `mapper` function.
|
|
4705
3942
|
*
|
|
4706
|
-
* <!-- runkit:activate -->
|
|
4707
|
-
* ```js
|
|
4708
|
-
* const { Collection } = require('immutable')
|
|
4709
|
-
* Collection({ a: 1, b: 2 }).map(x => 10 * x)
|
|
4710
|
-
* // Seq { "a": 10, "b": 20 }
|
|
4711
|
-
* ```
|
|
4712
|
-
*
|
|
4713
3943
|
* Note: `map()` always returns a new instance, even if it produced the same
|
|
4714
3944
|
* value at every step.
|
|
4715
3945
|
*/
|
|
@@ -4730,13 +3960,6 @@ declare namespace Immutable {
|
|
|
4730
3960
|
* Returns a new Collection of the same type with only the entries for which
|
|
4731
3961
|
* the `predicate` function returns true.
|
|
4732
3962
|
*
|
|
4733
|
-
* <!-- runkit:activate -->
|
|
4734
|
-
* ```js
|
|
4735
|
-
* const { Map } = require('immutable')
|
|
4736
|
-
* Map({ a: 1, b: 2, c: 3, d: 4}).filter(x => x % 2 === 0)
|
|
4737
|
-
* // Map { "b": 2, "d": 4 }
|
|
4738
|
-
* ```
|
|
4739
|
-
*
|
|
4740
3963
|
* Note: `filter()` always returns a new instance, even if it results in
|
|
4741
3964
|
* not filtering out any values.
|
|
4742
3965
|
*/
|
|
@@ -4753,13 +3976,6 @@ declare namespace Immutable {
|
|
|
4753
3976
|
* Returns a new Collection of the same type with only the entries for which
|
|
4754
3977
|
* the `predicate` function returns false.
|
|
4755
3978
|
*
|
|
4756
|
-
* <!-- runkit:activate -->
|
|
4757
|
-
* ```js
|
|
4758
|
-
* const { Map } = require('immutable')
|
|
4759
|
-
* Map({ a: 1, b: 2, c: 3, d: 4}).filterNot(x => x % 2 === 0)
|
|
4760
|
-
* // Map { "a": 1, "c": 3 }
|
|
4761
|
-
* ```
|
|
4762
|
-
*
|
|
4763
3979
|
* Note: `filterNot()` always returns a new instance, even if it results in
|
|
4764
3980
|
* not filtering out any values.
|
|
4765
3981
|
*/
|
|
@@ -4804,17 +4020,6 @@ declare namespace Immutable {
|
|
|
4804
4020
|
* When sorting collections which have no defined order, their ordered
|
|
4805
4021
|
* equivalents will be returned. e.g. `map.sort()` returns OrderedMap.
|
|
4806
4022
|
*
|
|
4807
|
-
* <!-- runkit:activate -->
|
|
4808
|
-
* ```js
|
|
4809
|
-
* const { Map } = require('immutable')
|
|
4810
|
-
* Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
|
|
4811
|
-
* if (a < b) { return -1; }
|
|
4812
|
-
* if (a > b) { return 1; }
|
|
4813
|
-
* if (a === b) { return 0; }
|
|
4814
|
-
* });
|
|
4815
|
-
* // OrderedMap { "a": 1, "b": 2, "c": 3 }
|
|
4816
|
-
* ```
|
|
4817
|
-
*
|
|
4818
4023
|
* Note: `sort()` Always returns a new instance, even if the original was
|
|
4819
4024
|
* already sorted.
|
|
4820
4025
|
*
|
|
@@ -4826,18 +4031,6 @@ declare namespace Immutable {
|
|
|
4826
4031
|
* Like `sort`, but also accepts a `comparatorValueMapper` which allows for
|
|
4827
4032
|
* sorting by more sophisticated means:
|
|
4828
4033
|
*
|
|
4829
|
-
* <!-- runkit:activate -->
|
|
4830
|
-
* ```js
|
|
4831
|
-
* const { Map } = require('immutable')
|
|
4832
|
-
* const beattles = Map({
|
|
4833
|
-
* John: { name: "Lennon" },
|
|
4834
|
-
* Paul: { name: "McCartney" },
|
|
4835
|
-
* George: { name: "Harrison" },
|
|
4836
|
-
* Ringo: { name: "Starr" },
|
|
4837
|
-
* });
|
|
4838
|
-
* beattles.sortBy(member => member.name);
|
|
4839
|
-
* ```
|
|
4840
|
-
*
|
|
4841
4034
|
* Note: `sortBy()` Always returns a new instance, even if the original was
|
|
4842
4035
|
* already sorted.
|
|
4843
4036
|
*
|
|
@@ -4853,24 +4046,6 @@ declare namespace Immutable {
|
|
|
4853
4046
|
* value of the `grouper` function.
|
|
4854
4047
|
*
|
|
4855
4048
|
* Note: This is always an eager operation.
|
|
4856
|
-
*
|
|
4857
|
-
* <!-- runkit:activate -->
|
|
4858
|
-
* ```js
|
|
4859
|
-
* const { List, Map } = require('immutable')
|
|
4860
|
-
* const listOfMaps = List([
|
|
4861
|
-
* Map({ v: 0 }),
|
|
4862
|
-
* Map({ v: 1 }),
|
|
4863
|
-
* Map({ v: 1 }),
|
|
4864
|
-
* Map({ v: 0 }),
|
|
4865
|
-
* Map({ v: 2 })
|
|
4866
|
-
* ])
|
|
4867
|
-
* const groupsOfMaps = listOfMaps.groupBy(x => x.get('v'))
|
|
4868
|
-
* // Map {
|
|
4869
|
-
* // 0: List [ Map{ "v": 0 }, Map { "v": 0 } ],
|
|
4870
|
-
* // 1: List [ Map{ "v": 1 }, Map { "v": 1 } ],
|
|
4871
|
-
* // 2: List [ Map{ "v": 2 } ],
|
|
4872
|
-
* // }
|
|
4873
|
-
* ```
|
|
4874
4049
|
*/
|
|
4875
4050
|
groupBy<G>(
|
|
4876
4051
|
grouper: (value: V, key: K, iter: this) => G,
|
|
@@ -4938,14 +4113,6 @@ declare namespace Immutable {
|
|
|
4938
4113
|
/**
|
|
4939
4114
|
* Returns a new Collection of the same type which includes entries starting
|
|
4940
4115
|
* from when `predicate` first returns false.
|
|
4941
|
-
*
|
|
4942
|
-
* <!-- runkit:activate -->
|
|
4943
|
-
* ```js
|
|
4944
|
-
* const { List } = require('immutable')
|
|
4945
|
-
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4946
|
-
* .skipWhile(x => x.match(/g/))
|
|
4947
|
-
* // List [ "cat", "hat", "god" ]
|
|
4948
|
-
* ```
|
|
4949
4116
|
*/
|
|
4950
4117
|
skipWhile(
|
|
4951
4118
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
@@ -4955,14 +4122,6 @@ declare namespace Immutable {
|
|
|
4955
4122
|
/**
|
|
4956
4123
|
* Returns a new Collection of the same type which includes entries starting
|
|
4957
4124
|
* from when `predicate` first returns true.
|
|
4958
|
-
*
|
|
4959
|
-
* <!-- runkit:activate -->
|
|
4960
|
-
* ```js
|
|
4961
|
-
* const { List } = require('immutable')
|
|
4962
|
-
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4963
|
-
* .skipUntil(x => x.match(/hat/))
|
|
4964
|
-
* // List [ "hat", "god" ]
|
|
4965
|
-
* ```
|
|
4966
4125
|
*/
|
|
4967
4126
|
skipUntil(
|
|
4968
4127
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
@@ -4984,14 +4143,6 @@ declare namespace Immutable {
|
|
|
4984
4143
|
/**
|
|
4985
4144
|
* Returns a new Collection of the same type which includes entries from this
|
|
4986
4145
|
* Collection as long as the `predicate` returns true.
|
|
4987
|
-
*
|
|
4988
|
-
* <!-- runkit:activate -->
|
|
4989
|
-
* ```js
|
|
4990
|
-
* const { List } = require('immutable')
|
|
4991
|
-
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4992
|
-
* .takeWhile(x => x.match(/o/))
|
|
4993
|
-
* // List [ "dog", "frog" ]
|
|
4994
|
-
* ```
|
|
4995
4146
|
*/
|
|
4996
4147
|
takeWhile(
|
|
4997
4148
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
@@ -5001,14 +4152,6 @@ declare namespace Immutable {
|
|
|
5001
4152
|
/**
|
|
5002
4153
|
* Returns a new Collection of the same type which includes entries from this
|
|
5003
4154
|
* Collection as long as the `predicate` returns false.
|
|
5004
|
-
*
|
|
5005
|
-
* <!-- runkit:activate -->
|
|
5006
|
-
* ```js
|
|
5007
|
-
* const { List } = require('immutable')
|
|
5008
|
-
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
5009
|
-
* .takeUntil(x => x.match(/at/))
|
|
5010
|
-
* // List [ "dog", "frog" ]
|
|
5011
|
-
* ```
|
|
5012
4155
|
*/
|
|
5013
4156
|
takeUntil(
|
|
5014
4157
|
predicate: (value: V, key: K, iter: this) => boolean,
|
|
@@ -5248,17 +4391,6 @@ declare namespace Immutable {
|
|
|
5248
4391
|
/**
|
|
5249
4392
|
* Like `max`, but also accepts a `comparatorValueMapper` which allows for
|
|
5250
4393
|
* comparing by more sophisticated means:
|
|
5251
|
-
*
|
|
5252
|
-
* <!-- runkit:activate -->
|
|
5253
|
-
* ```js
|
|
5254
|
-
* const { List, } = require('immutable');
|
|
5255
|
-
* const l = List([
|
|
5256
|
-
* { name: 'Bob', avgHit: 1 },
|
|
5257
|
-
* { name: 'Max', avgHit: 3 },
|
|
5258
|
-
* { name: 'Lili', avgHit: 2 } ,
|
|
5259
|
-
* ]);
|
|
5260
|
-
* l.maxBy(i => i.avgHit); // will output { name: 'Max', avgHit: 3 }
|
|
5261
|
-
* ```
|
|
5262
4394
|
*/
|
|
5263
4395
|
maxBy<C>(
|
|
5264
4396
|
comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
|
@@ -5285,17 +4417,6 @@ declare namespace Immutable {
|
|
|
5285
4417
|
/**
|
|
5286
4418
|
* Like `min`, but also accepts a `comparatorValueMapper` which allows for
|
|
5287
4419
|
* comparing by more sophisticated means:
|
|
5288
|
-
*
|
|
5289
|
-
* <!-- runkit:activate -->
|
|
5290
|
-
* ```js
|
|
5291
|
-
* const { List, } = require('immutable');
|
|
5292
|
-
* const l = List([
|
|
5293
|
-
* { name: 'Bob', avgHit: 1 },
|
|
5294
|
-
* { name: 'Max', avgHit: 3 },
|
|
5295
|
-
* { name: 'Lili', avgHit: 2 } ,
|
|
5296
|
-
* ]);
|
|
5297
|
-
* l.minBy(i => i.avgHit); // will output { name: 'Bob', avgHit: 1 }
|
|
5298
|
-
* ```
|
|
5299
4420
|
*/
|
|
5300
4421
|
minBy<C>(
|
|
5301
4422
|
comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
|
@@ -5335,16 +4456,6 @@ declare namespace Immutable {
|
|
|
5335
4456
|
* and is used when adding this to a `Set` or as a key in a `Map`, enabling
|
|
5336
4457
|
* lookup via a different instance.
|
|
5337
4458
|
*
|
|
5338
|
-
* <!-- runkit:activate -->
|
|
5339
|
-
* ```js
|
|
5340
|
-
* const { List, Set } = require('immutable');
|
|
5341
|
-
* const a = List([ 1, 2, 3 ]);
|
|
5342
|
-
* const b = List([ 1, 2, 3 ]);
|
|
5343
|
-
* assert.notStrictEqual(a, b); // different instances
|
|
5344
|
-
* const set = Set([ a ]);
|
|
5345
|
-
* assert.equal(set.has(b), true);
|
|
5346
|
-
* ```
|
|
5347
|
-
*
|
|
5348
4459
|
* Note: hashCode() MUST return a Uint32 number. The easiest way to
|
|
5349
4460
|
* guarantee this is to return `myHash | 0` from a custom implementation.
|
|
5350
4461
|
*
|
|
@@ -5397,44 +4508,12 @@ declare namespace Immutable {
|
|
|
5397
4508
|
* If `reviver` is not provided, the default behavior will convert Objects
|
|
5398
4509
|
* into Maps and Arrays into Lists like so:
|
|
5399
4510
|
*
|
|
5400
|
-
* <!-- runkit:activate -->
|
|
5401
|
-
* ```js
|
|
5402
|
-
* const { fromJS, isKeyed } = require('immutable')
|
|
5403
|
-
* function (key, value) {
|
|
5404
|
-
* return isKeyed(value) ? value.toMap() : value.toList()
|
|
5405
|
-
* }
|
|
5406
|
-
* ```
|
|
5407
|
-
*
|
|
5408
4511
|
* Accordingly, this example converts native JS data to OrderedMap and List:
|
|
5409
4512
|
*
|
|
5410
|
-
* <!-- runkit:activate -->
|
|
5411
|
-
* ```js
|
|
5412
|
-
* const { fromJS, isKeyed } = require('immutable')
|
|
5413
|
-
* fromJS({ a: {b: [10, 20, 30]}, c: 40}, function (key, value, path) {
|
|
5414
|
-
* console.log(key, value, path)
|
|
5415
|
-
* return isKeyed(value) ? value.toOrderedMap() : value.toList()
|
|
5416
|
-
* })
|
|
5417
|
-
*
|
|
5418
|
-
* > "b", [ 10, 20, 30 ], [ "a", "b" ]
|
|
5419
|
-
* > "a", {b: [10, 20, 30]}, [ "a" ]
|
|
5420
|
-
* > "", {a: {b: [10, 20, 30]}, c: 40}, []
|
|
5421
|
-
* ```
|
|
5422
|
-
*
|
|
5423
4513
|
* Keep in mind, when using JS objects to construct Immutable Maps, that
|
|
5424
4514
|
* JavaScript Object properties are always strings, even if written in a
|
|
5425
4515
|
* quote-less shorthand, while Immutable Maps accept keys of any type.
|
|
5426
4516
|
*
|
|
5427
|
-
* <!-- runkit:activate -->
|
|
5428
|
-
* ```js
|
|
5429
|
-
* const { Map } = require('immutable')
|
|
5430
|
-
* let obj = { 1: "one" };
|
|
5431
|
-
* Object.keys(obj); // [ "1" ]
|
|
5432
|
-
* assert.equal(obj["1"], obj[1]); // "one" === "one"
|
|
5433
|
-
*
|
|
5434
|
-
* let map = Map(obj);
|
|
5435
|
-
* assert.notEqual(map.get("1"), map.get(1)); // "one" !== undefined
|
|
5436
|
-
* ```
|
|
5437
|
-
*
|
|
5438
4517
|
* Property access for JavaScript Objects first converts the key to a string,
|
|
5439
4518
|
* but since Immutable Map keys can be of any type the argument to `get()` is
|
|
5440
4519
|
* not altered.
|
|
@@ -5489,16 +4568,6 @@ declare namespace Immutable {
|
|
|
5489
4568
|
* It's used throughout Immutable when checking for equality, including `Map`
|
|
5490
4569
|
* key equality and `Set` membership.
|
|
5491
4570
|
*
|
|
5492
|
-
* <!-- runkit:activate -->
|
|
5493
|
-
* ```js
|
|
5494
|
-
* const { Map, is } = require('immutable')
|
|
5495
|
-
* const map1 = Map({ a: 1, b: 1, c: 1 })
|
|
5496
|
-
* const map2 = Map({ a: 1, b: 1, c: 1 })
|
|
5497
|
-
* assert.equal(map1 !== map2, true)
|
|
5498
|
-
* assert.equal(Object.is(map1, map2), false)
|
|
5499
|
-
* assert.equal(is(map1, map2), true)
|
|
5500
|
-
* ```
|
|
5501
|
-
*
|
|
5502
4571
|
* `is()` compares primitive types like strings and numbers, Immutable.js
|
|
5503
4572
|
* collections like `Map` and `List`, but also any custom object which
|
|
5504
4573
|
* implements `ValueObject` by providing `equals()` and `hashCode()` methods.
|
|
@@ -5536,17 +4605,6 @@ declare namespace Immutable {
|
|
|
5536
4605
|
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
5537
4606
|
*
|
|
5538
4607
|
* Note: Still returns true even if the collections is within a `withMutations()`.
|
|
5539
|
-
*
|
|
5540
|
-
* <!-- runkit:activate -->
|
|
5541
|
-
* ```js
|
|
5542
|
-
* const { isImmutable, Map, List, Stack } = require('immutable');
|
|
5543
|
-
* isImmutable([]); // false
|
|
5544
|
-
* isImmutable({}); // false
|
|
5545
|
-
* isImmutable(Map()); // true
|
|
5546
|
-
* isImmutable(List()); // true
|
|
5547
|
-
* isImmutable(Stack()); // true
|
|
5548
|
-
* isImmutable(Map().asMutable()); // true
|
|
5549
|
-
* ```
|
|
5550
4608
|
*/
|
|
5551
4609
|
function isImmutable(
|
|
5552
4610
|
maybeImmutable: unknown
|
|
@@ -5554,16 +4612,6 @@ declare namespace Immutable {
|
|
|
5554
4612
|
|
|
5555
4613
|
/**
|
|
5556
4614
|
* True if `maybeCollection` is a Collection, or any of its subclasses.
|
|
5557
|
-
*
|
|
5558
|
-
* <!-- runkit:activate -->
|
|
5559
|
-
* ```js
|
|
5560
|
-
* const { isCollection, Map, List, Stack } = require('immutable');
|
|
5561
|
-
* isCollection([]); // false
|
|
5562
|
-
* isCollection({}); // false
|
|
5563
|
-
* isCollection(Map()); // true
|
|
5564
|
-
* isCollection(List()); // true
|
|
5565
|
-
* isCollection(Stack()); // true
|
|
5566
|
-
* ```
|
|
5567
4615
|
*/
|
|
5568
4616
|
function isCollection(
|
|
5569
4617
|
maybeCollection: unknown
|
|
@@ -5571,16 +4619,6 @@ declare namespace Immutable {
|
|
|
5571
4619
|
|
|
5572
4620
|
/**
|
|
5573
4621
|
* True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
|
|
5574
|
-
*
|
|
5575
|
-
* <!-- runkit:activate -->
|
|
5576
|
-
* ```js
|
|
5577
|
-
* const { isKeyed, Map, List, Stack } = require('immutable');
|
|
5578
|
-
* isKeyed([]); // false
|
|
5579
|
-
* isKeyed({}); // false
|
|
5580
|
-
* isKeyed(Map()); // true
|
|
5581
|
-
* isKeyed(List()); // false
|
|
5582
|
-
* isKeyed(Stack()); // false
|
|
5583
|
-
* ```
|
|
5584
4622
|
*/
|
|
5585
4623
|
function isKeyed(
|
|
5586
4624
|
maybeKeyed: unknown
|
|
@@ -5588,17 +4626,6 @@ declare namespace Immutable {
|
|
|
5588
4626
|
|
|
5589
4627
|
/**
|
|
5590
4628
|
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
|
|
5591
|
-
*
|
|
5592
|
-
* <!-- runkit:activate -->
|
|
5593
|
-
* ```js
|
|
5594
|
-
* const { isIndexed, Map, List, Stack, Set } = require('immutable');
|
|
5595
|
-
* isIndexed([]); // false
|
|
5596
|
-
* isIndexed({}); // false
|
|
5597
|
-
* isIndexed(Map()); // false
|
|
5598
|
-
* isIndexed(List()); // true
|
|
5599
|
-
* isIndexed(Stack()); // true
|
|
5600
|
-
* isIndexed(Set()); // false
|
|
5601
|
-
* ```
|
|
5602
4629
|
*/
|
|
5603
4630
|
function isIndexed(
|
|
5604
4631
|
maybeIndexed: unknown
|
|
@@ -5606,17 +4633,6 @@ declare namespace Immutable {
|
|
|
5606
4633
|
|
|
5607
4634
|
/**
|
|
5608
4635
|
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
|
|
5609
|
-
*
|
|
5610
|
-
* <!-- runkit:activate -->
|
|
5611
|
-
* ```js
|
|
5612
|
-
* const { isAssociative, Map, List, Stack, Set } = require('immutable');
|
|
5613
|
-
* isAssociative([]); // false
|
|
5614
|
-
* isAssociative({}); // false
|
|
5615
|
-
* isAssociative(Map()); // true
|
|
5616
|
-
* isAssociative(List()); // true
|
|
5617
|
-
* isAssociative(Stack()); // true
|
|
5618
|
-
* isAssociative(Set()); // false
|
|
5619
|
-
* ```
|
|
5620
4636
|
*/
|
|
5621
4637
|
function isAssociative(
|
|
5622
4638
|
maybeAssociative: unknown
|
|
@@ -5627,17 +4643,6 @@ declare namespace Immutable {
|
|
|
5627
4643
|
/**
|
|
5628
4644
|
* True if `maybeOrdered` is a Collection where iteration order is well
|
|
5629
4645
|
* defined. True for Collection.Indexed as well as OrderedMap and OrderedSet.
|
|
5630
|
-
*
|
|
5631
|
-
* <!-- runkit:activate -->
|
|
5632
|
-
* ```js
|
|
5633
|
-
* const { isOrdered, Map, OrderedMap, List, Set } = require('immutable');
|
|
5634
|
-
* isOrdered([]); // false
|
|
5635
|
-
* isOrdered({}); // false
|
|
5636
|
-
* isOrdered(Map()); // false
|
|
5637
|
-
* isOrdered(OrderedMap()); // true
|
|
5638
|
-
* isOrdered(List()); // true
|
|
5639
|
-
* isOrdered(Set()); // false
|
|
5640
|
-
* ```
|
|
5641
4646
|
*/
|
|
5642
4647
|
function isOrdered<T>(
|
|
5643
4648
|
maybeOrdered: Iterable<T>
|
|
@@ -5714,14 +4719,6 @@ declare namespace Immutable {
|
|
|
5714
4719
|
*
|
|
5715
4720
|
* A functional alternative to `collection.get(key)` which will also work on
|
|
5716
4721
|
* plain Objects and Arrays as an alternative for `collection[key]`.
|
|
5717
|
-
*
|
|
5718
|
-
* <!-- runkit:activate -->
|
|
5719
|
-
* ```js
|
|
5720
|
-
* const { get } = require('immutable')
|
|
5721
|
-
* get([ 'dog', 'frog', 'cat' ], 2) // 'frog'
|
|
5722
|
-
* get({ x: 123, y: 456 }, 'x') // 123
|
|
5723
|
-
* get({ x: 123, y: 456 }, 'z', 'ifNotSet') // 'ifNotSet'
|
|
5724
|
-
* ```
|
|
5725
4722
|
*/
|
|
5726
4723
|
function get<K, V>(collection: Collection<K, V>, key: K): V | undefined;
|
|
5727
4724
|
function get<K, V, NSV>(
|
|
@@ -5761,15 +4758,6 @@ declare namespace Immutable {
|
|
|
5761
4758
|
* A functional alternative to `collection.has(key)` which will also work with
|
|
5762
4759
|
* plain Objects and Arrays as an alternative for
|
|
5763
4760
|
* `collection.hasOwnProperty(key)`.
|
|
5764
|
-
*
|
|
5765
|
-
* <!-- runkit:activate -->
|
|
5766
|
-
* ```js
|
|
5767
|
-
* const { has } = require('immutable')
|
|
5768
|
-
* has([ 'dog', 'frog', 'cat' ], 2) // true
|
|
5769
|
-
* has([ 'dog', 'frog', 'cat' ], 5) // false
|
|
5770
|
-
* has({ x: 123, y: 456 }, 'x') // true
|
|
5771
|
-
* has({ x: 123, y: 456 }, 'z') // false
|
|
5772
|
-
* ```
|
|
5773
4761
|
*/
|
|
5774
4762
|
function has(collection: object, key: unknown): boolean;
|
|
5775
4763
|
|
|
@@ -5779,17 +4767,6 @@ declare namespace Immutable {
|
|
|
5779
4767
|
* A functional alternative to `collection.remove(key)` which will also work
|
|
5780
4768
|
* with plain Objects and Arrays as an alternative for
|
|
5781
4769
|
* `delete collectionCopy[key]`.
|
|
5782
|
-
*
|
|
5783
|
-
* <!-- runkit:activate -->
|
|
5784
|
-
* ```js
|
|
5785
|
-
* const { remove } = require('immutable')
|
|
5786
|
-
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
5787
|
-
* remove(originalArray, 1) // [ 'dog', 'cat' ]
|
|
5788
|
-
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
5789
|
-
* const originalObject = { x: 123, y: 456 }
|
|
5790
|
-
* remove(originalObject, 'x') // { y: 456 }
|
|
5791
|
-
* console.log(originalObject) // { x: 123, y: 456 }
|
|
5792
|
-
* ```
|
|
5793
4770
|
*/
|
|
5794
4771
|
function remove<K, C extends Collection<K, unknown>>(
|
|
5795
4772
|
collection: C,
|
|
@@ -5814,17 +4791,6 @@ declare namespace Immutable {
|
|
|
5814
4791
|
* A functional alternative to `collection.set(key, value)` which will also
|
|
5815
4792
|
* work with plain Objects and Arrays as an alternative for
|
|
5816
4793
|
* `collectionCopy[key] = value`.
|
|
5817
|
-
*
|
|
5818
|
-
* <!-- runkit:activate -->
|
|
5819
|
-
* ```js
|
|
5820
|
-
* const { set } = require('immutable')
|
|
5821
|
-
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
5822
|
-
* set(originalArray, 1, 'cow') // [ 'dog', 'cow', 'cat' ]
|
|
5823
|
-
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
5824
|
-
* const originalObject = { x: 123, y: 456 }
|
|
5825
|
-
* set(originalObject, 'x', 789) // { x: 789, y: 456 }
|
|
5826
|
-
* console.log(originalObject) // { x: 123, y: 456 }
|
|
5827
|
-
* ```
|
|
5828
4794
|
*/
|
|
5829
4795
|
function set<K, V, C extends Collection<K, V>>(
|
|
5830
4796
|
collection: C,
|
|
@@ -5851,17 +4817,6 @@ declare namespace Immutable {
|
|
|
5851
4817
|
* A functional alternative to `collection.update(key, fn)` which will also
|
|
5852
4818
|
* work with plain Objects and Arrays as an alternative for
|
|
5853
4819
|
* `collectionCopy[key] = fn(collection[key])`.
|
|
5854
|
-
*
|
|
5855
|
-
* <!-- runkit:activate -->
|
|
5856
|
-
* ```js
|
|
5857
|
-
* const { update } = require('immutable')
|
|
5858
|
-
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
5859
|
-
* update(originalArray, 1, val => val.toUpperCase()) // [ 'dog', 'FROG', 'cat' ]
|
|
5860
|
-
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
5861
|
-
* const originalObject = { x: 123, y: 456 }
|
|
5862
|
-
* update(originalObject, 'x', val => val * 6) // { x: 738, y: 456 }
|
|
5863
|
-
* console.log(originalObject) // { x: 123, y: 456 }
|
|
5864
|
-
* ```
|
|
5865
4820
|
*/
|
|
5866
4821
|
function update<K, V, C extends Collection<K, V>>(
|
|
5867
4822
|
collection: C,
|
|
@@ -5933,13 +4888,6 @@ declare namespace Immutable {
|
|
|
5933
4888
|
*
|
|
5934
4889
|
* A functional alternative to `collection.getIn(keypath)` which will also
|
|
5935
4890
|
* work with plain Objects and Arrays.
|
|
5936
|
-
*
|
|
5937
|
-
* <!-- runkit:activate -->
|
|
5938
|
-
* ```js
|
|
5939
|
-
* const { getIn } = require('immutable')
|
|
5940
|
-
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
|
|
5941
|
-
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
|
|
5942
|
-
* ```
|
|
5943
4891
|
*/
|
|
5944
4892
|
function getIn<C, P extends ReadonlyArray<PropertyKey>>(
|
|
5945
4893
|
object: C,
|
|
@@ -5962,13 +4910,6 @@ declare namespace Immutable {
|
|
|
5962
4910
|
*
|
|
5963
4911
|
* A functional alternative to `collection.hasIn(keypath)` which will also
|
|
5964
4912
|
* work with plain Objects and Arrays.
|
|
5965
|
-
*
|
|
5966
|
-
* <!-- runkit:activate -->
|
|
5967
|
-
* ```js
|
|
5968
|
-
* const { hasIn } = require('immutable')
|
|
5969
|
-
* hasIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // true
|
|
5970
|
-
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
|
|
5971
|
-
* ```
|
|
5972
4913
|
*/
|
|
5973
4914
|
function hasIn(
|
|
5974
4915
|
collection: string | boolean | number,
|
|
@@ -5981,14 +4922,6 @@ declare namespace Immutable {
|
|
|
5981
4922
|
*
|
|
5982
4923
|
* A functional alternative to `collection.removeIn(keypath)` which will also
|
|
5983
4924
|
* work with plain Objects and Arrays.
|
|
5984
|
-
*
|
|
5985
|
-
* <!-- runkit:activate -->
|
|
5986
|
-
* ```js
|
|
5987
|
-
* const { removeIn } = require('immutable')
|
|
5988
|
-
* const original = { x: { y: { z: 123 }}}
|
|
5989
|
-
* removeIn(original, ['x', 'y', 'z']) // { x: { y: {}}}
|
|
5990
|
-
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5991
|
-
* ```
|
|
5992
4925
|
*/
|
|
5993
4926
|
function removeIn<C>(collection: C, keyPath: Iterable<unknown>): C;
|
|
5994
4927
|
|
|
@@ -5998,14 +4931,6 @@ declare namespace Immutable {
|
|
|
5998
4931
|
*
|
|
5999
4932
|
* A functional alternative to `collection.setIn(keypath)` which will also
|
|
6000
4933
|
* work with plain Objects and Arrays.
|
|
6001
|
-
*
|
|
6002
|
-
* <!-- runkit:activate -->
|
|
6003
|
-
* ```js
|
|
6004
|
-
* const { setIn } = require('immutable')
|
|
6005
|
-
* const original = { x: { y: { z: 123 }}}
|
|
6006
|
-
* setIn(original, ['x', 'y', 'z'], 456) // { x: { y: { z: 456 }}}
|
|
6007
|
-
* console.log(original) // { x: { y: { z: 123 }}}
|
|
6008
|
-
* ```
|
|
6009
4934
|
*/
|
|
6010
4935
|
function setIn<C>(
|
|
6011
4936
|
collection: C,
|
|
@@ -6019,14 +4944,6 @@ declare namespace Immutable {
|
|
|
6019
4944
|
*
|
|
6020
4945
|
* A functional alternative to `collection.updateIn(keypath)` which will also
|
|
6021
4946
|
* work with plain Objects and Arrays.
|
|
6022
|
-
*
|
|
6023
|
-
* <!-- runkit:activate -->
|
|
6024
|
-
* ```js
|
|
6025
|
-
* const { updateIn } = require('immutable')
|
|
6026
|
-
* const original = { x: { y: { z: 123 }}}
|
|
6027
|
-
* updateIn(original, ['x', 'y', 'z'], val => val * 6) // { x: { y: { z: 738 }}}
|
|
6028
|
-
* console.log(original) // { x: { y: { z: 123 }}}
|
|
6029
|
-
* ```
|
|
6030
4947
|
*/
|
|
6031
4948
|
function updateIn<K extends PropertyKey, V, C extends Collection<K, V>>(
|
|
6032
4949
|
collection: C,
|
|
@@ -6111,14 +5028,6 @@ declare namespace Immutable {
|
|
|
6111
5028
|
*
|
|
6112
5029
|
* A functional alternative to `collection.merge()` which will also work with
|
|
6113
5030
|
* plain Objects and Arrays.
|
|
6114
|
-
*
|
|
6115
|
-
* <!-- runkit:activate -->
|
|
6116
|
-
* ```js
|
|
6117
|
-
* const { merge } = require('immutable')
|
|
6118
|
-
* const original = { x: 123, y: 456 }
|
|
6119
|
-
* merge(original, { y: 789, z: 'abc' }) // { x: 123, y: 789, z: 'abc' }
|
|
6120
|
-
* console.log(original) // { x: 123, y: 456 }
|
|
6121
|
-
* ```
|
|
6122
5031
|
*/
|
|
6123
5032
|
function merge<C>(
|
|
6124
5033
|
collection: C,
|
|
@@ -6135,18 +5044,6 @@ declare namespace Immutable {
|
|
|
6135
5044
|
*
|
|
6136
5045
|
* A functional alternative to `collection.mergeWith()` which will also work
|
|
6137
5046
|
* with plain Objects and Arrays.
|
|
6138
|
-
*
|
|
6139
|
-
* <!-- runkit:activate -->
|
|
6140
|
-
* ```js
|
|
6141
|
-
* const { mergeWith } = require('immutable')
|
|
6142
|
-
* const original = { x: 123, y: 456 }
|
|
6143
|
-
* mergeWith(
|
|
6144
|
-
* (oldVal, newVal) => oldVal + newVal,
|
|
6145
|
-
* original,
|
|
6146
|
-
* { y: 789, z: 'abc' }
|
|
6147
|
-
* ) // { x: 123, y: 1245, z: 'abc' }
|
|
6148
|
-
* console.log(original) // { x: 123, y: 456 }
|
|
6149
|
-
* ```
|
|
6150
5047
|
*/
|
|
6151
5048
|
function mergeWith<C>(
|
|
6152
5049
|
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
|
@@ -6174,14 +5071,6 @@ declare namespace Immutable {
|
|
|
6174
5071
|
*
|
|
6175
5072
|
* A functional alternative to `collection.mergeDeep()` which will also work
|
|
6176
5073
|
* with plain Objects and Arrays.
|
|
6177
|
-
*
|
|
6178
|
-
* <!-- runkit:activate -->
|
|
6179
|
-
* ```js
|
|
6180
|
-
* const { mergeDeep } = require('immutable')
|
|
6181
|
-
* const original = { x: { y: 123 }}
|
|
6182
|
-
* mergeDeep(original, { x: { z: 456 }}) // { x: { y: 123, z: 456 }}
|
|
6183
|
-
* console.log(original) // { x: { y: 123 }}
|
|
6184
|
-
* ```
|
|
6185
5074
|
*/
|
|
6186
5075
|
function mergeDeep<C>(
|
|
6187
5076
|
collection: C,
|
|
@@ -6200,18 +5089,6 @@ declare namespace Immutable {
|
|
|
6200
5089
|
*
|
|
6201
5090
|
* A functional alternative to `collection.mergeDeepWith()` which will also
|
|
6202
5091
|
* work with plain Objects and Arrays.
|
|
6203
|
-
*
|
|
6204
|
-
* <!-- runkit:activate -->
|
|
6205
|
-
* ```js
|
|
6206
|
-
* const { mergeDeepWith } = require('immutable')
|
|
6207
|
-
* const original = { x: { y: 123 }}
|
|
6208
|
-
* mergeDeepWith(
|
|
6209
|
-
* (oldVal, newVal) => oldVal + newVal,
|
|
6210
|
-
* original,
|
|
6211
|
-
* { x: { y: 456 }}
|
|
6212
|
-
* ) // { x: { y: 579 }}
|
|
6213
|
-
* console.log(original) // { x: { y: 123 }}
|
|
6214
|
-
* ```
|
|
6215
5092
|
*/
|
|
6216
5093
|
function mergeDeepWith<C>(
|
|
6217
5094
|
merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|