-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
4033 lines (3524 loc) · 128 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Facebook's Immutable 3.8.1
// Project: https://github.com/facebook/immutable-js
// Definitions by: tht13 <https://github.com/tht13>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Core of typings are from repository itself
/**
* Copyright (c) 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/**
* Immutable data encourages pure functions (data-in, data-out) and lends itself
* to much simpler application development and enabling techniques from
* functional programming such as lazy evaluation.
*
* While designed to bring these powerful functional concepts to JavaScript, it
* presents an Object-Oriented API familiar to Javascript engineers and closely
* mirroring that of Array, Map, and Set. It is easy and efficient to convert to
* and from plain Javascript types.
* Note: all examples are presented in [ES6][]. To run in all browsers, they
* need to be translated to ES3. For example:
*
* // ES6
* foo.map(x => x * x);
* // ES3
* foo.map(function (x) { return x * x; });
*
* [ES6]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
*/
declare namespace Immutable {
/**
* Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
*
* If a `reviver` is optionally provided, it will be called with every
* collection as a Seq (beginning with the most nested collections
* and proceeding to the top-level collection itself), along with the key
* refering to each collection and the parent JS object provided as `this`.
* For the top level, object, the key will be `""`. This `reviver` is expected
* to return a new Immutable Iterable, allowing for custom conversions from
* deep JS objects.
*
* This example converts JSON to List and OrderedMap:
*
* Immutable.fromJS({a: {b: [10, 20, 30]}, c: 40}, function (key, value) {
* var isIndexed = Immutable.Iterable.isIndexed(value);
* return isIndexed ? value.toList() : value.toOrderedMap();
* });
*
* // true, "b", {b: [10, 20, 30]}
* // false, "a", {a: {b: [10, 20, 30]}, c: 40}
* // false, "", {"": {a: {b: [10, 20, 30]}, c: 40}}
*
* If `reviver` is not provided, the default behavior will convert Arrays into
* Lists and Objects into Maps.
*
* `reviver` acts similarly to the [same parameter in `JSON.parse`][1].
*
* `Immutable.fromJS` is conservative in its conversion. It will only convert
* arrays which pass `Array.isArray` to Lists, and only raw objects (no custom
* prototype) to Map.
*
* Keep in mind, when using JS objects to construct Immutable Maps, that
* JavaScript Object properties are always strings, even if written in a
* quote-less shorthand, while Immutable Maps accept keys of any type.
*
* ```js
* var obj = { 1: "one" };
* Object.keys(obj); // [ "1" ]
* obj["1"]; // "one"
* obj[1]; // "one"
*
* var map = Map(obj);
* map.get("1"); // "one"
* map.get(1); // undefined
* ```
*
* Property access for JavaScript Objects first converts the key to a string,
* but since Immutable Map keys can be of any type the argument to `get()` is
* not altered.
*
* [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter
* "Using the reviver parameter"
*/
export function fromJS(
json: any,
reviver?: (k: any, v: Iterable<any, any>) => any
): any;
/**
* Value equality check with semantics similar to `Object.is`, but treats
* Immutable `Iterable`s as values, equal if the second `Iterable` includes
* equivalent values.
*
* It's used throughout Immutable when checking for equality, including `Map`
* key equality and `Set` membership.
*
* var map1 = Immutable.Map({a:1, b:1, c:1});
* var map2 = Immutable.Map({a:1, b:1, c:1});
* assert(map1 !== map2);
* assert(Object.is(map1, map2) === false);
* assert(Immutable.is(map1, map2) === true);
*
* Note: Unlike `Object.is`, `Immutable.is` assumes `0` and `-0` are the same
* value, matching the behavior of ES6 Map key equality.
*/
export function is(first: any, second: any): boolean;
/**
* Lists are ordered indexed dense collections, much like a JavaScript
* Array.
*
* Lists are immutable and fully persistent with O(log32 N) gets and sets,
* and O(1) push and pop.
*
* Lists implement Deque, with efficient addition and removal from both the
* end (`push`, `pop`) and beginning (`unshift`, `shift`).
*
* Unlike a JavaScript Array, there is no distinction between an
* "unset" index and an index set to `undefined`. `List#forEach` visits all
* indices from 0 to size, regardless of whether they were explicitly defined.
*/
export module List {
/**
* True if the provided value is a List
*/
function isList(maybeList: any): boolean;
/**
* Creates a new List containing `values`.
*/
function of<T>(...values: T[]): List<T>;
}
/**
* Create a new immutable List containing the values of the provided
* iterable-like.
*/
export function List<T>(): List<T>;
export function List<T>(iter: Iterable.Indexed<T>): List<T>;
export function List<T>(iter: Iterable.Set<T>): List<T>;
export function List<K, V>(iter: Iterable.Keyed<K, V>): List<[K, V]>;
export function List<T>(array: Array<T>): List<T>;
export function List<T>(iterator: Iterator<T>): List<T>;
export function List<T>(iterable: Iterable<any, T>): List<T>;
export interface List<T> extends Collection.Indexed<T> {
// Persistent changes
/**
* Returns a new List which includes `value` at `index`. If `index` already
* exists in this List, it will be replaced.
*
* `index` may be a negative number, which indexes back from the end of the
* List. `v.set(-1, "value")` sets the last item in the List.
*
* If `index` larger than `size`, the returned List's `size` will be large
* enough to include the `index`.
*/
set(index: number, value: T): List<T>;
/**
* Returns a new List which excludes this `index` and with a size 1 less
* than this List. Values at indices above `index` are shifted down by 1 to
* fill the position.
*
* This is synonymous with `list.splice(index, 1)`.
*
* `index` may be a negative number, which indexes back from the end of the
* List. `v.delete(-1)` deletes the last item in the List.
*
* Note: `delete` cannot be safely used in IE8
* @alias remove
*/
delete(index: number): List<T>;
remove(index: number): List<T>;
/**
* Returns a new List with `value` at `index` with a size 1 more than this
* List. Values at indices above `index` are shifted over by 1.
*
* This is synonymous with `list.splice(index, 0, value)
*/
insert(index: number, value: T): List<T>;
/**
* Returns a new List with 0 size and no values.
*/
clear(): List<T>;
/**
* Returns a new List with the provided `values` appended, starting at this
* List's `size`.
*/
push(...values: T[]): List<T>;
/**
* Returns a new List with a size ones less than this List, excluding
* the last index in this List.
*
* Note: this differs from `Array#pop` because it returns a new
* List rather than the removed value. Use `last()` to get the last value
* in this List.
*/
pop(): List<T>;
/**
* Returns a new List with the provided `values` prepended, shifting other
* values ahead to higher indices.
*/
unshift(...values: T[]): List<T>;
/**
* Returns a new List with a size ones less than this List, excluding
* the first index in this List, shifting all other values to a lower index.
*
* Note: this differs from `Array#shift` because it returns a new
* List rather than the removed value. Use `first()` to get the first
* value in this List.
*/
shift(): List<T>;
/**
* Returns a new List with an updated value at `index` with the return
* value of calling `updater` with the existing value, or `notSetValue` if
* `index` was not set. If called with a single argument, `updater` is
* called with the List itself.
*
* `index` may be a negative number, which indexes back from the end of the
* List. `v.update(-1)` updates the last item in the List.
*
* @see `Map#update`
*/
update(updater: (value: List<T>) => List<T>): List<T>;
update(index: number, updater: (value: T) => T): List<T>;
update(index: number, notSetValue: T, updater: (value: T) => T): List<T>;
/**
* @see `Map#merge`
*/
merge(...iterables: Iterable.Indexed<T>[]): List<T>;
merge(...iterables: Array<T>[]): List<T>;
/**
* @see `Map#mergeWith`
*/
mergeWith(
merger: (previous: T, next: T, key: number) => T,
...iterables: Iterable.Indexed<T>[]
): List<T>;
mergeWith(
merger: (previous: T, next: T, key: number) => T,
...iterables: Array<T>[]
): List<T>;
/**
* @see `Map#mergeDeep`
*/
mergeDeep(...iterables: Iterable.Indexed<T>[]): List<T>;
mergeDeep(...iterables: Array<T>[]): List<T>;
/**
* @see `Map#mergeDeepWith`
*/
mergeDeepWith(
merger: (previous: T, next: T, key: number) => T,
...iterables: Iterable.Indexed<T>[]
): List<T>;
mergeDeepWith(
merger: (previous: T, next: T, key: number) => T,
...iterables: Array<T>[]
): List<T>;
/**
* Returns a new List with size `size`. If `size` is less than this
* List's size, the new List will exclude values at the higher indices.
* If `size` is greater than this List's size, the new List will have
* undefined values for the newly available indices.
*
* When building a new List and the final size is known up front, `setSize`
* used in conjunction with `withMutations` may result in the more
* performant construction.
*/
setSize(size: number): List<T>;
// Deep persistent changes
/**
* Returns a new List having set `value` at this `keyPath`. If any keys in
* `keyPath` do not exist, a new immutable Map will be created at that key.
*
* Index numbers are used as keys to determine the path to follow in
* the List.
*/
setIn(keyPath: Array<any>, value: any): List<T>;
setIn(keyPath: Iterable<any, any>, value: any): List<T>;
/**
* Returns a new List having removed the value at this `keyPath`. If any
* keys in `keyPath` do not exist, no change will occur.
*
* @alias removeIn
*/
deleteIn(keyPath: Array<any>): List<T>;
deleteIn(keyPath: Iterable<any, any>): List<T>;
removeIn(keyPath: Array<any>): List<T>;
removeIn(keyPath: Iterable<any, any>): List<T>;
/**
* @see `Map#updateIn`
*/
updateIn(
keyPath: Array<any>,
updater: (value: any) => any
): List<T>;
updateIn(
keyPath: Array<any>,
notSetValue: any,
updater: (value: any) => any
): List<T>;
updateIn(
keyPath: Iterable<any, any>,
updater: (value: any) => any
): List<T>;
updateIn(
keyPath: Iterable<any, any>,
notSetValue: any,
updater: (value: any) => any
): List<T>;
/**
* @see `Map#mergeIn`
*/
mergeIn(
keyPath: Iterable<any, any>,
...iterables: Iterable.Indexed<T>[]
): List<T>;
mergeIn(
keyPath: Array<any>,
...iterables: Iterable.Indexed<T>[]
): List<T>;
mergeIn(
keyPath: Array<any>,
...iterables: Array<T>[]
): List<T>;
/**
* @see `Map#mergeDeepIn`
*/
mergeDeepIn(
keyPath: Iterable<any, any>,
...iterables: Iterable.Indexed<T>[]
): List<T>;
mergeDeepIn(
keyPath: Array<any>,
...iterables: Iterable.Indexed<T>[]
): List<T>;
mergeDeepIn(
keyPath: Array<any>,
...iterables: Array<T>[]
): List<T>;
// Transient changes
/**
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Only `set`, `push`, `pop`, `shift`, `unshift` and
* `merge` may be used mutatively.
*
* @see `Map#withMutations`
*/
withMutations(mutator: (mutable: List<T>) => any): List<T>;
/**
* @see `Map#asMutable`
*/
asMutable(): List<T>;
/**
* @see `Map#asImmutable`
*/
asImmutable(): List<T>;
}
/**
* Immutable Map is an unordered Iterable.Keyed of (key, value) pairs with
* `O(log32 N)` gets and `O(log32 N)` persistent sets.
*
* Iteration order of a Map is undefined, however is stable. Multiple
* iterations of the same Map will iterate in the same order.
*
* Map's keys can be of any type, and use `Immutable.is` to determine key
* equality. This allows the use of any value (including NaN) as a key.
*
* Because `Immutable.is` returns equality based on value semantics, and
* Immutable collections are treated as values, any Immutable collection may
* be used as a key.
*
* Map().set(List.of(1), 'listofone').get(List.of(1));
* // 'listofone'
*
* Any JavaScript object may be used as a key, however strict identity is used
* to evaluate key equality. Two similar looking objects will represent two
* different keys.
*
* Implemented by a hash-array mapped trie.
*/
export module Map {
/**
* True if the provided value is a Map
*/
function isMap(maybeMap: any): boolean;
/**
* Creates a new Map from alternating keys and values
*/
function of<K, V>(...keyValues: (K | V)[]): Map<K, V>;
}
/**
* Creates a new Immutable Map.
*
* Created with the same key value pairs as the provided Iterable.Keyed or
* JavaScript Object or expects an Iterable of [K, V] tuple entries.
*
* var newMap = Map({key: "value"});
* var newMap = Map([["key", "value"]]);
*
* Keep in mind, when using JS objects to construct Immutable Maps, that
* JavaScript Object properties are always strings, even if written in a
* quote-less shorthand, while Immutable Maps accept keys of any type.
*
* ```js
* var obj = { 1: "one" };
* Object.keys(obj); // [ "1" ]
* obj["1"]; // "one"
* obj[1]; // "one"
*
* var map = Map(obj);
* map.get("1"); // "one"
* map.get(1); // undefined
* ```
*
* Property access for JavaScript Objects first converts the key to a string,
* but since Immutable Map keys can be of any type the argument to `get()` is
* not altered.
*/
export function Map<K, V>(): Map<K, V>;
export function Map<K, V>(iter: Iterable.Keyed<K, V>): Map<K, V>;
export function Map<K, V>(iter: Iterable<any, [K, V]>): Map<K, V>;
export function Map<K, V>(array: Array<[K, V]>): Map<K, V>;
export function Map<V>(obj: { [key: string]: V }): Map<string, V>;
export function Map<K, V>(iterator: Iterator<[K, V]>): Map<K, V>;
export function Map<K, V>(iterable: Iterable<any, [K, V]>): Map<K, V>;
export interface Map<K, V> extends Collection.Keyed<K, V> {
// Persistent changes
/**
* Returns a new Map also containing the new key, value pair. If an equivalent
* key already exists in this Map, it will be replaced.
*/
set(key: K, value: V): Map<K, V>;
/**
* Returns a new Map which excludes this `key`.
*
* Note: `delete` cannot be safely used in IE8, but is provided to mirror
* the ES6 collection API.
* @alias remove
*/
delete(key: K): Map<K, V>;
remove(key: K): Map<K, V>;
/**
* Returns a new Map containing no keys or values.
*/
clear(): Map<K, V>;
/**
* Returns a new Map having updated the value at this `key` with the return
* value of calling `updater` with the existing value, or `notSetValue` if
* the key was not set. If called with only a single argument, `updater` is
* called with the Map itself.
*
* Equivalent to: `map.set(key, updater(map.get(key, notSetValue)))`.
*/
update(updater: (value: Map<K, V>) => Map<K, V>): Map<K, V>;
update(key: K, updater: (value: V) => V): Map<K, V>;
update(key: K, notSetValue: V, updater: (value: V) => V): Map<K, V>;
/**
* Returns a new Map resulting from merging the provided Iterables
* (or JS objects) into this Map. In other words, this takes each entry of
* each iterable and sets it on this Map.
*
* If any of the values provided to `merge` are not Iterable (would return
* false for `Immutable.Iterable.isIterable`) then they are deeply converted
* via `Immutable.fromJS` before being merged. However, if the value is an
* Iterable but includes non-iterable JS objects or arrays, those nested
* values will be preserved.
*
* var x = Immutable.Map({a: 10, b: 20, c: 30});
* var y = Immutable.Map({b: 40, a: 50, d: 60});
* x.merge(y) // { a: 50, b: 40, c: 30, d: 60 }
* y.merge(x) // { b: 20, a: 10, d: 60, c: 30 }
*
*/
merge(...iterables: Iterable<K, V>[]): Map<K, V>;
merge(...iterables: { [key: string]: V }[]): Map<string, V>;
/**
* Like `merge()`, `mergeWith()` returns a new Map resulting from merging
* the provided Iterables (or JS objects) into this Map, but uses the
* `merger` function for dealing with conflicts.
*
* var x = Immutable.Map({a: 10, b: 20, c: 30});
* var y = Immutable.Map({b: 40, a: 50, d: 60});
* x.mergeWith((prev, next) => prev / next, y) // { a: 0.2, b: 0.5, c: 30, d: 60 }
* y.mergeWith((prev, next) => prev / next, x) // { b: 2, a: 5, d: 60, c: 30 }
*
*/
mergeWith(
merger: (previous: V, next: V, key: K) => V,
...iterables: Iterable<K, V>[]
): Map<K, V>;
mergeWith(
merger: (previous: V, next: V, key: K) => V,
...iterables: { [key: string]: V }[]
): Map<string, V>;
/**
* Like `merge()`, but when two Iterables conflict, it merges them as well,
* recursing deeply through the nested data.
*
* var x = Immutable.fromJS({a: { x: 10, y: 10 }, b: { x: 20, y: 50 } });
* var y = Immutable.fromJS({a: { x: 2 }, b: { y: 5 }, c: { z: 3 } });
* x.mergeDeep(y) // {a: { x: 2, y: 10 }, b: { x: 20, y: 5 }, c: { z: 3 } }
*
*/
mergeDeep(...iterables: Iterable<K, V>[]): Map<K, V>;
mergeDeep(...iterables: { [key: string]: V }[]): Map<string, V>;
/**
* Like `mergeDeep()`, but when two non-Iterables conflict, it uses the
* `merger` function to determine the resulting value.
*
* var x = Immutable.fromJS({a: { x: 10, y: 10 }, b: { x: 20, y: 50 } });
* var y = Immutable.fromJS({a: { x: 2 }, b: { y: 5 }, c: { z: 3 } });
* x.mergeDeepWith((prev, next) => prev / next, y)
* // {a: { x: 5, y: 10 }, b: { x: 20, y: 10 }, c: { z: 3 } }
*
*/
mergeDeepWith(
merger: (previous: V, next: V, key: K) => V,
...iterables: Iterable<K, V>[]
): Map<K, V>;
mergeDeepWith(
merger: (previous: V, next: V, key: K) => V,
...iterables: { [key: string]: V }[]
): Map<string, V>;
// Deep persistent changes
/**
* Returns a new Map having set `value` at this `keyPath`. If any keys in
* `keyPath` do not exist, a new immutable Map will be created at that key.
*/
setIn(keyPath: Array<any>, value: any): Map<K, V>;
setIn(KeyPath: Iterable<any, any>, value: any): Map<K, V>;
/**
* Returns a new Map having removed the value at this `keyPath`. If any keys
* in `keyPath` do not exist, no change will occur.
*
* @alias removeIn
*/
deleteIn(keyPath: Array<any>): Map<K, V>;
deleteIn(keyPath: Iterable<any, any>): Map<K, V>;
removeIn(keyPath: Array<any>): Map<K, V>;
removeIn(keyPath: Iterable<any, any>): Map<K, V>;
/**
* Returns a new Map having applied the `updater` to the entry found at the
* keyPath.
*
* If any keys in `keyPath` do not exist, new Immutable `Map`s will
* be created at those keys. If the `keyPath` does not already contain a
* value, the `updater` function will be called with `notSetValue`, if
* provided, otherwise `undefined`.
*
* var data = Immutable.fromJS({ a: { b: { c: 10 } } });
* data = data.updateIn(['a', 'b', 'c'], val => val * 2);
* // { a: { b: { c: 20 } } }
*
* If the `updater` function returns the same value it was called with, then
* no change will occur. This is still true if `notSetValue` is provided.
*
* var data1 = Immutable.fromJS({ a: { b: { c: 10 } } });
* data2 = data1.updateIn(['x', 'y', 'z'], 100, val => val);
* assert(data2 === data1);
*
*/
updateIn(
keyPath: Array<any>,
updater: (value: any) => any
): Map<K, V>;
updateIn(
keyPath: Array<any>,
notSetValue: any,
updater: (value: any) => any
): Map<K, V>;
updateIn(
keyPath: Iterable<any, any>,
updater: (value: any) => any
): Map<K, V>;
updateIn(
keyPath: Iterable<any, any>,
notSetValue: any,
updater: (value: any) => any
): Map<K, V>;
/**
* A combination of `updateIn` and `merge`, returning a new Map, but
* performing the merge at a point arrived at by following the keyPath.
* In other words, these two lines are equivalent:
*
* x.updateIn(['a', 'b', 'c'], abc => abc.merge(y));
* x.mergeIn(['a', 'b', 'c'], y);
*
*/
mergeIn(
keyPath: Iterable<any, any>,
...iterables: Iterable<K, V>[]
): Map<K, V>;
mergeIn(
keyPath: Array<any>,
...iterables: Iterable<K, V>[]
): Map<K, V>;
mergeIn(
keyPath: Array<any>,
...iterables: { [key: string]: V }[]
): Map<string, V>;
/**
* A combination of `updateIn` and `mergeDeep`, returning a new Map, but
* performing the deep merge at a point arrived at by following the keyPath.
* In other words, these two lines are equivalent:
*
* x.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y));
* x.mergeDeepIn(['a', 'b', 'c'], y);
*
*/
mergeDeepIn(
keyPath: Iterable<any, any>,
...iterables: Iterable<K, V>[]
): Map<K, V>;
mergeDeepIn(
keyPath: Array<any>,
...iterables: Iterable<K, V>[]
): Map<K, V>;
mergeDeepIn(
keyPath: Array<any>,
...iterables: { [key: string]: V }[]
): Map<string, V>;
// Transient changes
/**
* Every time you call one of the above functions, a new immutable Map is
* created. If a pure function calls a number of these to produce a final
* return value, then a penalty on performance and memory has been paid by
* creating all of the intermediate immutable Maps.
*
* If you need to apply a series of mutations to produce a new immutable
* Map, `withMutations()` creates a temporary mutable copy of the Map which
* can apply mutations in a highly performant manner. In fact, this is
* exactly how complex mutations like `merge` are done.
*
* As an example, this results in the creation of 2, not 4, new Maps:
*
* var map1 = Immutable.Map();
* var map2 = map1.withMutations(map => {
* map.set('a', 1).set('b', 2).set('c', 3);
* });
* assert(map1.size === 0);
* assert(map2.size === 3);
*
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Only `set` and `merge` may be used mutatively.
*
*/
withMutations(mutator: (mutable: Map<K, V>) => any): Map<K, V>;
/**
* Another way to avoid creation of intermediate Immutable maps is to create
* a mutable copy of this collection. Mutable copies *always* return `this`,
* and thus shouldn't be used for equality. Your function should never return
* a mutable copy of a collection, only use it internally to create a new
* collection. If possible, use `withMutations` as it provides an easier to
* use API.
*
* Note: if the collection is already mutable, `asMutable` returns itself.
*
* Note: Not all methods can be used on a mutable collection or within
* `withMutations`! Only `set` and `merge` may be used mutatively.
*/
asMutable(): Map<K, V>;
/**
* The yin to `asMutable`'s yang. Because it applies to mutable collections,
* this operation is *mutable* and returns itself. Once performed, the mutable
* copy has become immutable and can be safely returned from a function.
*/
asImmutable(): Map<K, V>;
}
export function Map<T>(): TypedMap<T>;
export function Map<T>(iter: Iterable.TypedKeyed<T>): TypedMap<T>;
export interface TypedMap<T> extends Collection.TypedKeyed<T> {
// Persistent changes
/**
* Returns a new Map also containing the new key, value pair. If an equivalent
* key already exists in this Map, it will be replaced.
*/
set<K extends keyof T>(key: K, value: T[K]): this;
/**
* Returns a new Map which excludes this `key`.
*
* Note: `delete` cannot be safely used in IE8, but is provided to mirror
* the ES6 collection API.
* @alias remove
*/
delete<K extends keyof T>(key: K): this;
remove<K extends keyof T>(key: K): this;
/**
* Returns a new Map containing no keys or values.
*/
clear<K extends keyof T>(): this;
/**
* Returns a new Map having updated the value at this `key` with the return
* value of calling `updater` with the existing value, or `notSetValue` if
* the key was not set. If called with only a single argument, `updater` is
* called with the Map itself.
*
* Equivalent to: `map.set(key, updater(map.get(key, notSetValue)))`.
*/
update<K extends keyof T>(updater: (value: TypedMap<T>) => TypedMap<T>): this;
update<K extends keyof T>(key: K, updater: (value: T[K]) => T[K]): this;
update<K extends keyof T>(key: K, notSetValue: T[K], updater: (value: T[K]) => T[K]): this;
/**
* Returns a new Map resulting from merging the provided Iterables
* (or JS objects) into this Map. In other words, this takes each entry of
* each iterable and sets it on this Map.
*
* If any of the values provided to `merge` are not Iterable (would return
* false for `Immutable.Iterable.isIterable`) then they are deeply converted
* via `Immutable.fromJS` before being merged. However, if the value is an
* Iterable but includes non-iterable JS objects or arrays, those nested
* values will be preserved.
*
* var x = Immutable.Map({a: 10, b: 20, c: 30});
* var y = Immutable.Map({b: 40, a: 50, d: 60});
* x.merge(y) // { a: 50, b: 40, c: 30, d: 60 }
* y.merge(x) // { b: 20, a: 10, d: 60, c: 30 }
*
*/
merge<K extends keyof T>(...iterables: Iterable<K, T[K]>[]): this;
merge(...iterables: TypedIterable<T>[]): this;
merge<K extends keyof T>(...iterables: Partial<T>[]): this;
/**
* Like `merge()`, `mergeWith()` returns a new Map resulting from merging
* the provided Iterables (or JS objects) into this Map, but uses the
* `merger` function for dealing with conflicts.
*
* var x = Immutable.Map({a: 10, b: 20, c: 30});
* var y = Immutable.Map({b: 40, a: 50, d: 60});
* x.mergeWith((prev, next) => prev / next, y) // { a: 0.2, b: 0.5, c: 30, d: 60 }
* y.mergeWith((prev, next) => prev / next, x) // { b: 2, a: 5, d: 60, c: 30 }
*
*/
mergeWith<K extends keyof T>(
merger: (previous: T[K], next: T[K], key: K) => T[K],
...iterables: Iterable<K, T[K]>[]
): this;
mergeWith<K extends keyof T>(
merger: (previous: T[K], next: T[K], key: K) => T[K],
...iterables: TypedIterable<T>[]
): this;
mergeWith<K extends keyof T>(
merger: (previous: T[K], next: T[K], key: K) => T[K],
...iterables: Partial<T>[]
): this;
/**
* Like `merge()`, but when two Iterables conflict, it merges them as well,
* recursing deeply through the nested data.
*
* var x = Immutable.fromJS({a: { x: 10, y: 10 }, b: { x: 20, y: 50 } });
* var y = Immutable.fromJS({a: { x: 2 }, b: { y: 5 }, c: { z: 3 } });
* x.mergeDeep(y) // {a: { x: 2, y: 10 }, b: { x: 20, y: 5 }, c: { z: 3 } }
*
*/
mergeDeep<K extends keyof T>(...iterables: Iterable<K, T[K]>[]): this;
mergeDeep(...iterables: TypedIterable<T>[]): this;
mergeDeep<K extends keyof T>(...iterables: Partial<T>[]): this;
/**
* Like `mergeDeep()`, but when two non-Iterables conflict, it uses the
* `merger` function to determine the resulting value.
*
* var x = Immutable.fromJS({a: { x: 10, y: 10 }, b: { x: 20, y: 50 } });
* var y = Immutable.fromJS({a: { x: 2 }, b: { y: 5 }, c: { z: 3 } });
* x.mergeDeepWith((prev, next) => prev / next, y)
* // {a: { x: 5, y: 10 }, b: { x: 20, y: 10 }, c: { z: 3 } }
*
*/
mergeDeepWith<K extends keyof T>(
merger: (previous: T[K], next: T[K], key: K) => T[K],
...iterables: Iterable<K, T[K]>[]
): this;
mergeDeepWith<K extends keyof T>(
merger: (previous: T[K], next: T[K], key: K) => T[K],
...iterables: TypedIterable<T>[]
): this;
mergeDeepWith<K extends keyof T>(
merger: (previous: T[K], next: T[K], key: K) => T[K],
...iterables: Partial<T>[]
): this;
// Deep persistent changes
/**
* Returns a new Map having set `value` at this `keyPath`. If any keys in
* `keyPath` do not exist, a new immutable Map will be created at that key.
*/
setIn(keyPath: Array<any>, value: any): this;
setIn(KeyPath: Iterable<any, any>, value: any): this;
/**
* Returns a new Map having removed the value at this `keyPath`. If any keys
* in `keyPath` do not exist, no change will occur.
*
* @alias removeIn
*/
deleteIn(keyPath: Array<any>): this;
deleteIn(keyPath: Iterable<any, any>): this;
removeIn(keyPath: Array<any>): this;
removeIn(keyPath: Iterable<any, any>): this;
/**
* Returns a new Map having applied the `updater` to the entry found at the
* keyPath.
*
* If any keys in `keyPath` do not exist, new Immutable `Map`s will
* be created at those keys. If the `keyPath` does not already contain a
* value, the `updater` function will be called with `notSetValue`, if
* provided, otherwise `undefined`.
*
* var data = Immutable.fromJS({ a: { b: { c: 10 } } });
* data = data.updateIn(['a', 'b', 'c'], val => val * 2);
* // { a: { b: { c: 20 } } }
*
* If the `updater` function returns the same value it was called with, then
* no change will occur. This is still true if `notSetValue` is provided.
*
* var data1 = Immutable.fromJS({ a: { b: { c: 10 } } });
* data2 = data1.updateIn(['x', 'y', 'z'], 100, val => val);
* assert(data2 === data1);
*
*/
updateIn(
keyPath: Array<any>,
updater: (value: any) => any
): this;
updateIn(
keyPath: Array<any>,
notSetValue: any,
updater: (value: any) => any
): this;
updateIn(
keyPath: Iterable<any, any>,
updater: (value: any) => any
): this;
updateIn(
keyPath: Iterable<any, any>,
notSetValue: any,
updater: (value: any) => any
): this;
/**
* A combination of `updateIn` and `merge`, returning a new Map, but
* performing the merge at a point arrived at by following the keyPath.
* In other words, these two lines are equivalent:
*
* x.updateIn(['a', 'b', 'c'], abc => abc.merge(y));
* x.mergeIn(['a', 'b', 'c'], y);
*
*/
mergeIn<K extends keyof T>(
keyPath: Iterable<any, any>,
...iterables: Iterable<K, T[K]>[]
): this;
mergeIn<K extends keyof T>(
keyPath: Array<any>,
...iterables: Iterable<K, T[K]>[]
): this;
mergeIn(
keyPath: Iterable<any, any>,
...iterables: TypedIterable<T>[]
): this;
mergeIn(
keyPath: Array<any>,
...iterables: TypedIterable<T>[]
): this;
mergeIn<K extends keyof T>(
keyPath: Array<any>,
...iterables: Partial<T>[]
): this;
/**
* A combination of `updateIn` and `mergeDeep`, returning a new Map, but
* performing the deep merge at a point arrived at by following the keyPath.
* In other words, these two lines are equivalent:
*
* x.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y));
* x.mergeDeepIn(['a', 'b', 'c'], y);
*
*/
mergeDeepIn<K extends keyof T>(
keyPath: Iterable<any, any>,
...iterables: Iterable<K, T[K]>[]
): this;
mergeDeepIn<K extends keyof T>(
keyPath: Array<any>,
...iterables: Iterable<K, T[K]>[]
): this;
mergeDeepIn(
keyPath: Iterable<any, any>,
...iterables: TypedIterable<T>[]
): this;
mergeDeepIn(
keyPath: Array<any>,
...iterables: TypedIterable<T>[]
): this;
mergeDeepIn<K extends keyof T>(
keyPath: Array<any>,
...iterables: Partial<T>[]
): this;
// Transient changes
/**
* Every time you call one of the above functions, a new immutable Map is
* created. If a pure function calls a number of these to produce a final
* return value, then a penalty on performance and memory has been paid by
* creating all of the intermediate immutable Maps.
*
* If you need to apply a series of mutations to produce a new immutable
* Map, `withMutations()` creates a temporary mutable copy of the Map which
* can apply mutations in a highly performant manner. In fact, this is
* exactly how complex mutations like `merge` are done.
*
* As an example, this results in the creation of 2, not 4, new Maps:
*
* var map1 = Immutable.Map();
* var map2 = map1.withMutations(map => {
* map.set('a', 1).set('b', 2).set('c', 3);
* });