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