immutable 4.0.0-rc.5 → 4.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -83
- package/dist/immutable-nonambient.d.ts +951 -479
- package/dist/immutable.d.ts +951 -479
- package/dist/immutable.es.js +542 -339
- package/dist/immutable.js +555 -338
- package/dist/immutable.js.flow +331 -111
- package/dist/immutable.min.js +32 -31
- package/package.json +2 -2
package/dist/immutable.d.ts
CHANGED
|
@@ -100,374 +100,95 @@
|
|
|
100
100
|
declare module Immutable {
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
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.5')
|
|
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.5')
|
|
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.5')
|
|
153
|
-
* let obj = { 1: "one" };
|
|
154
|
-
* Object.keys(obj); // [ "1" ]
|
|
155
|
-
* assert.equal(obj["1"], obj[1]); // "one" === "one"
|
|
103
|
+
* Lists are ordered indexed dense collections, much like a JavaScript
|
|
104
|
+
* Array.
|
|
156
105
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* ```
|
|
106
|
+
* Lists are immutable and fully persistent with O(log32 N) gets and sets,
|
|
107
|
+
* and O(1) push and pop.
|
|
160
108
|
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* not altered.
|
|
109
|
+
* Lists implement Deque, with efficient addition and removal from both the
|
|
110
|
+
* end (`push`, `pop`) and beginning (`unshift`, `shift`).
|
|
164
111
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
112
|
+
* Unlike a JavaScript Array, there is no distinction between an
|
|
113
|
+
* "unset" index and an index set to `undefined`. `List#forEach` visits all
|
|
114
|
+
* indices from 0 to size, regardless of whether they were explicitly defined.
|
|
167
115
|
*/
|
|
168
|
-
export
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
116
|
+
export module List {
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* True if the provided value is a List
|
|
120
|
+
*
|
|
121
|
+
* <!-- runkit:activate -->
|
|
122
|
+
* ```js
|
|
123
|
+
* const { List } = require('immutable@4.0.0-rc.9');
|
|
124
|
+
* List.isList([]); // false
|
|
125
|
+
* List.isList(List()); // true
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function isList(maybeList: any): maybeList is List<any>;
|
|
176
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Creates a new List containing `values`.
|
|
132
|
+
*
|
|
133
|
+
* <!-- runkit:activate -->
|
|
134
|
+
* ```js
|
|
135
|
+
* const { List } = require('immutable@4.0.0-rc.9');
|
|
136
|
+
* List.of(1, 2, 3, 4)
|
|
137
|
+
* // List [ 1, 2, 3, 4 ]
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* Note: Values are not altered or converted in any way.
|
|
141
|
+
*
|
|
142
|
+
* <!-- runkit:activate -->
|
|
143
|
+
* ```js
|
|
144
|
+
* const { List } = require('immutable@4.0.0-rc.9');
|
|
145
|
+
* List.of({x:1}, 2, [3], 4)
|
|
146
|
+
* // List [ { x: 1 }, 2, [ 3 ], 4 ]
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
function of<T>(...values: Array<T>): List<T>;
|
|
150
|
+
}
|
|
177
151
|
|
|
178
152
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* equivalent values.
|
|
182
|
-
*
|
|
183
|
-
* It's used throughout Immutable when checking for equality, including `Map`
|
|
184
|
-
* key equality and `Set` membership.
|
|
153
|
+
* Create a new immutable List containing the values of the provided
|
|
154
|
+
* collection-like.
|
|
185
155
|
*
|
|
186
156
|
* <!-- runkit:activate -->
|
|
187
157
|
* ```js
|
|
188
|
-
* const {
|
|
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.
|
|
158
|
+
* const { List, Set } = require('immutable@4.0.0-rc.9')
|
|
222
159
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
160
|
+
* const emptyList = List()
|
|
161
|
+
* // List []
|
|
225
162
|
*
|
|
226
|
-
*
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
163
|
+
* const plainArray = [ 1, 2, 3, 4 ]
|
|
164
|
+
* const listFromPlainArray = List(plainArray)
|
|
165
|
+
* // List [ 1, 2, 3, 4 ]
|
|
232
166
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
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.
|
|
167
|
+
* const plainSet = Set([ 1, 2, 3, 4 ])
|
|
168
|
+
* const listFromPlainSet = List(plainSet)
|
|
169
|
+
* // List [ 1, 2, 3, 4 ]
|
|
248
170
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
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.
|
|
171
|
+
* const arrayIterator = plainArray[Symbol.iterator]()
|
|
172
|
+
* const listFromCollectionArray = List(arrayIterator)
|
|
173
|
+
* // List [ 1, 2, 3, 4 ]
|
|
263
174
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* isKeyed([]); // false
|
|
268
|
-
* isKeyed({}); // false
|
|
269
|
-
* isKeyed(Map()); // true
|
|
270
|
-
* isKeyed(List()); // false
|
|
271
|
-
* isKeyed(Stack()); // false
|
|
175
|
+
* listFromPlainArray.equals(listFromCollectionArray) // true
|
|
176
|
+
* listFromPlainSet.equals(listFromCollectionArray) // true
|
|
177
|
+
* listFromPlainSet.equals(listFromPlainArray) // true
|
|
272
178
|
* ```
|
|
273
179
|
*/
|
|
274
|
-
export function
|
|
180
|
+
export function List(): List<any>;
|
|
181
|
+
export function List<T>(): List<T>;
|
|
182
|
+
export function List<T>(collection: Iterable<T>): List<T>;
|
|
275
183
|
|
|
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.5');
|
|
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>;
|
|
184
|
+
export interface List<T> extends Collection.Indexed<T> {
|
|
291
185
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
* ```js
|
|
297
|
-
* const { isAssociative, Map, List, Stack, Set } = require('immutable@4.0.0-rc.5');
|
|
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>;
|
|
186
|
+
/**
|
|
187
|
+
* The number of items in this List.
|
|
188
|
+
*/
|
|
189
|
+
readonly size: number;
|
|
307
190
|
|
|
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.5');
|
|
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.5');
|
|
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
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Lists are ordered indexed dense collections, much like a JavaScript
|
|
383
|
-
* Array.
|
|
384
|
-
*
|
|
385
|
-
* Lists are immutable and fully persistent with O(log32 N) gets and sets,
|
|
386
|
-
* and O(1) push and pop.
|
|
387
|
-
*
|
|
388
|
-
* Lists implement Deque, with efficient addition and removal from both the
|
|
389
|
-
* end (`push`, `pop`) and beginning (`unshift`, `shift`).
|
|
390
|
-
*
|
|
391
|
-
* Unlike a JavaScript Array, there is no distinction between an
|
|
392
|
-
* "unset" index and an index set to `undefined`. `List#forEach` visits all
|
|
393
|
-
* indices from 0 to size, regardless of whether they were explicitly defined.
|
|
394
|
-
*/
|
|
395
|
-
export module List {
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* True if the provided value is a List
|
|
399
|
-
*
|
|
400
|
-
* <!-- runkit:activate -->
|
|
401
|
-
* ```js
|
|
402
|
-
* const { List } = require('immutable@4.0.0-rc.5');
|
|
403
|
-
* List.isList([]); // false
|
|
404
|
-
* List.isList(List()); // true
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
function isList(maybeList: any): maybeList is List<any>;
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Creates a new List containing `values`.
|
|
411
|
-
*
|
|
412
|
-
* <!-- runkit:activate -->
|
|
413
|
-
* ```js
|
|
414
|
-
* const { List } = require('immutable@4.0.0-rc.5');
|
|
415
|
-
* List.of(1, 2, 3, 4)
|
|
416
|
-
* // List [ 1, 2, 3, 4 ]
|
|
417
|
-
* ```
|
|
418
|
-
*
|
|
419
|
-
* Note: Values are not altered or converted in any way.
|
|
420
|
-
*
|
|
421
|
-
* <!-- runkit:activate -->
|
|
422
|
-
* ```js
|
|
423
|
-
* const { List } = require('immutable@4.0.0-rc.5');
|
|
424
|
-
* List.of({x:1}, 2, [3], 4)
|
|
425
|
-
* // List [ { x: 1 }, 2, [ 3 ], 4 ]
|
|
426
|
-
* ```
|
|
427
|
-
*/
|
|
428
|
-
function of<T>(...values: Array<T>): List<T>;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Create a new immutable List containing the values of the provided
|
|
433
|
-
* collection-like.
|
|
434
|
-
*
|
|
435
|
-
* <!-- runkit:activate -->
|
|
436
|
-
* ```js
|
|
437
|
-
* const { List, Set } = require('immutable@4.0.0-rc.5')
|
|
438
|
-
*
|
|
439
|
-
* const emptyList = List()
|
|
440
|
-
* // List []
|
|
441
|
-
*
|
|
442
|
-
* const plainArray = [ 1, 2, 3, 4 ]
|
|
443
|
-
* const listFromPlainArray = List(plainArray)
|
|
444
|
-
* // List [ 1, 2, 3, 4 ]
|
|
445
|
-
*
|
|
446
|
-
* const plainSet = Set([ 1, 2, 3, 4 ])
|
|
447
|
-
* const listFromPlainSet = List(plainSet)
|
|
448
|
-
* // List [ 1, 2, 3, 4 ]
|
|
449
|
-
*
|
|
450
|
-
* const arrayIterator = plainArray[Symbol.iterator]()
|
|
451
|
-
* const listFromCollectionArray = List(arrayIterator)
|
|
452
|
-
* // List [ 1, 2, 3, 4 ]
|
|
453
|
-
*
|
|
454
|
-
* listFromPlainArray.equals(listFromCollectionArray) // true
|
|
455
|
-
* listFromPlainSet.equals(listFromCollectionArray) // true
|
|
456
|
-
* listFromPlainSet.equals(listFromPlainArray) // true
|
|
457
|
-
* ```
|
|
458
|
-
*/
|
|
459
|
-
export function List(): List<any>;
|
|
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> {
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* The number of items in this List.
|
|
467
|
-
*/
|
|
468
|
-
readonly size: number;
|
|
469
|
-
|
|
470
|
-
// Persistent changes
|
|
191
|
+
// Persistent changes
|
|
471
192
|
|
|
472
193
|
/**
|
|
473
194
|
* Returns a new List which includes `value` at `index`. If `index` already
|
|
@@ -480,7 +201,7 @@ declare module Immutable {
|
|
|
480
201
|
* enough to include the `index`.
|
|
481
202
|
*
|
|
482
203
|
* <!-- runkit:activate
|
|
483
|
-
* { "preamble": "const { List } = require(
|
|
204
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
484
205
|
* -->
|
|
485
206
|
* ```js
|
|
486
207
|
* const originalList = List([ 0 ]);
|
|
@@ -513,13 +234,16 @@ declare module Immutable {
|
|
|
513
234
|
* Note: `delete` cannot be safely used in IE8
|
|
514
235
|
*
|
|
515
236
|
* <!-- runkit:activate
|
|
516
|
-
* { "preamble": "const { List } = require(
|
|
237
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
517
238
|
* -->
|
|
518
239
|
* ```js
|
|
519
240
|
* List([ 0, 1, 2, 3, 4 ]).delete(0);
|
|
520
241
|
* // List [ 1, 2, 3, 4 ]
|
|
521
242
|
* ```
|
|
522
243
|
*
|
|
244
|
+
* Since `delete()` re-indexes values, it produces a complete copy, which
|
|
245
|
+
* has `O(N)` complexity.
|
|
246
|
+
*
|
|
523
247
|
* Note: `delete` *cannot* be used in `withMutations`.
|
|
524
248
|
*
|
|
525
249
|
* @alias remove
|
|
@@ -534,22 +258,25 @@ declare module Immutable {
|
|
|
534
258
|
* This is synonymous with `list.splice(index, 0, value)`.
|
|
535
259
|
*
|
|
536
260
|
* <!-- runkit:activate
|
|
537
|
-
* { "preamble": "const { List } = require(
|
|
261
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
538
262
|
* -->
|
|
539
263
|
* ```js
|
|
540
264
|
* List([ 0, 1, 2, 3, 4 ]).insert(6, 5)
|
|
541
265
|
* // List [ 0, 1, 2, 3, 4, 5 ]
|
|
542
266
|
* ```
|
|
543
267
|
*
|
|
268
|
+
* Since `insert()` re-indexes values, it produces a complete copy, which
|
|
269
|
+
* has `O(N)` complexity.
|
|
270
|
+
*
|
|
544
271
|
* Note: `insert` *cannot* be used in `withMutations`.
|
|
545
272
|
*/
|
|
546
273
|
insert(index: number, value: T): List<T>;
|
|
547
274
|
|
|
548
275
|
/**
|
|
549
|
-
* Returns a new List with 0 size and no values.
|
|
276
|
+
* Returns a new List with 0 size and no values in constant time.
|
|
550
277
|
*
|
|
551
278
|
* <!-- runkit:activate
|
|
552
|
-
* { "preamble": "const { List } = require(
|
|
279
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
553
280
|
* -->
|
|
554
281
|
* ```js
|
|
555
282
|
* List([ 1, 2, 3, 4 ]).clear()
|
|
@@ -565,7 +292,7 @@ declare module Immutable {
|
|
|
565
292
|
* List's `size`.
|
|
566
293
|
*
|
|
567
294
|
* <!-- runkit:activate
|
|
568
|
-
* { "preamble": "const { List } = require(
|
|
295
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
569
296
|
* -->
|
|
570
297
|
* ```js
|
|
571
298
|
* List([ 1, 2, 3, 4 ]).push(5)
|
|
@@ -598,7 +325,7 @@ declare module Immutable {
|
|
|
598
325
|
* values ahead to higher indices.
|
|
599
326
|
*
|
|
600
327
|
* <!-- runkit:activate
|
|
601
|
-
* { "preamble": "const { List } = require(
|
|
328
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
602
329
|
* -->
|
|
603
330
|
* ```js
|
|
604
331
|
* List([ 2, 3, 4]).unshift(1);
|
|
@@ -618,7 +345,7 @@ declare module Immutable {
|
|
|
618
345
|
* value in this List.
|
|
619
346
|
*
|
|
620
347
|
* <!-- runkit:activate
|
|
621
|
-
* { "preamble": "const { List } = require(
|
|
348
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
622
349
|
* -->
|
|
623
350
|
* ```js
|
|
624
351
|
* List([ 0, 1, 2, 3, 4 ]).shift();
|
|
@@ -639,7 +366,7 @@ declare module Immutable {
|
|
|
639
366
|
* List. `v.update(-1)` updates the last item in the List.
|
|
640
367
|
*
|
|
641
368
|
* <!-- runkit:activate
|
|
642
|
-
* { "preamble": "const { List } = require(
|
|
369
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
643
370
|
* -->
|
|
644
371
|
* ```js
|
|
645
372
|
* const list = List([ 'a', 'b', 'c' ])
|
|
@@ -653,7 +380,7 @@ declare module Immutable {
|
|
|
653
380
|
* For example, to sum a List after mapping and filtering:
|
|
654
381
|
*
|
|
655
382
|
* <!-- runkit:activate
|
|
656
|
-
* { "preamble": "const { List } = require(
|
|
383
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
657
384
|
* -->
|
|
658
385
|
* ```js
|
|
659
386
|
* function sum(collection) {
|
|
@@ -699,12 +426,24 @@ declare module Immutable {
|
|
|
699
426
|
*
|
|
700
427
|
* <!-- runkit:activate -->
|
|
701
428
|
* ```js
|
|
702
|
-
* const { List } = require(
|
|
429
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
703
430
|
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
|
704
431
|
* list.setIn([3, 0], 999);
|
|
705
432
|
* // List [ 0, 1, 2, List [ 999, 4 ] ]
|
|
706
433
|
* ```
|
|
707
434
|
*
|
|
435
|
+
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
436
|
+
* Collection, and setIn() can update those values as well, treating them
|
|
437
|
+
* immutably by creating new copies of those values with the changes applied.
|
|
438
|
+
*
|
|
439
|
+
* <!-- runkit:activate -->
|
|
440
|
+
* ```js
|
|
441
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
442
|
+
* const list = List([ 0, 1, 2, { plain: 'object' }])
|
|
443
|
+
* list.setIn([3, 'plain'], 'value');
|
|
444
|
+
* // List([ 0, 1, 2, { plain: 'value' }])
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
708
447
|
* Note: `setIn` can be used in `withMutations`.
|
|
709
448
|
*/
|
|
710
449
|
setIn(keyPath: Iterable<any>, value: any): this;
|
|
@@ -715,12 +454,24 @@ declare module Immutable {
|
|
|
715
454
|
*
|
|
716
455
|
* <!-- runkit:activate -->
|
|
717
456
|
* ```js
|
|
718
|
-
* const { List } = require(
|
|
457
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
719
458
|
* const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
|
720
459
|
* list.deleteIn([3, 0]);
|
|
721
460
|
* // List [ 0, 1, 2, List [ 4 ] ]
|
|
722
461
|
* ```
|
|
723
462
|
*
|
|
463
|
+
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
464
|
+
* Collection, and removeIn() can update those values as well, treating them
|
|
465
|
+
* immutably by creating new copies of those values with the changes applied.
|
|
466
|
+
*
|
|
467
|
+
* <!-- runkit:activate -->
|
|
468
|
+
* ```js
|
|
469
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
470
|
+
* const list = List([ 0, 1, 2, { plain: 'object' }])
|
|
471
|
+
* list.removeIn([3, 'plain']);
|
|
472
|
+
* // List([ 0, 1, 2, {}])
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
724
475
|
* Note: `deleteIn` *cannot* be safely used in `withMutations`.
|
|
725
476
|
*
|
|
726
477
|
* @alias removeIn
|
|
@@ -787,19 +538,19 @@ 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@4.0.0-rc.9');" }
|
|
803
554
|
* -->
|
|
804
555
|
* ```js
|
|
805
556
|
* List([ 1, 2 ]).map(x => 10 * x)
|
|
@@ -846,7 +597,7 @@ declare module Immutable {
|
|
|
846
597
|
* Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
|
847
598
|
*
|
|
848
599
|
* <!-- runkit:activate
|
|
849
|
-
* { "preamble": "const { List } = require(
|
|
600
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
850
601
|
* -->
|
|
851
602
|
* ```js
|
|
852
603
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -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@4.0.0-rc.9');" }
|
|
869
620
|
* -->
|
|
870
621
|
* ```js
|
|
871
622
|
* const a = List([ 1, 2 ]);
|
|
@@ -886,7 +637,7 @@ declare module Immutable {
|
|
|
886
637
|
* custom `zipper` function.
|
|
887
638
|
*
|
|
888
639
|
* <!-- runkit:activate
|
|
889
|
-
* { "preamble": "const { List } = require(
|
|
640
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9');" }
|
|
890
641
|
* -->
|
|
891
642
|
* ```js
|
|
892
643
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -927,7 +678,7 @@ declare module Immutable {
|
|
|
927
678
|
*
|
|
928
679
|
* <!-- runkit:activate -->
|
|
929
680
|
* ```js
|
|
930
|
-
* const { Map, List } = require('immutable@4.0.0-rc.
|
|
681
|
+
* const { Map, List } = require('immutable@4.0.0-rc.9');
|
|
931
682
|
* Map().set(List([ 1 ]), 'listofone').get(List([ 1 ]));
|
|
932
683
|
* // 'listofone'
|
|
933
684
|
* ```
|
|
@@ -945,7 +696,7 @@ declare module Immutable {
|
|
|
945
696
|
*
|
|
946
697
|
* <!-- runkit:activate -->
|
|
947
698
|
* ```js
|
|
948
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
699
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
949
700
|
* Map.isMap({}) // false
|
|
950
701
|
* Map.isMap(Map()) // true
|
|
951
702
|
* ```
|
|
@@ -957,7 +708,7 @@ declare module Immutable {
|
|
|
957
708
|
*
|
|
958
709
|
* <!-- runkit:activate -->
|
|
959
710
|
* ```js
|
|
960
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
711
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
961
712
|
* Map.of(
|
|
962
713
|
* 'key', 'value',
|
|
963
714
|
* 'numerical value', 3,
|
|
@@ -979,7 +730,7 @@ declare module Immutable {
|
|
|
979
730
|
*
|
|
980
731
|
* <!-- runkit:activate -->
|
|
981
732
|
* ```js
|
|
982
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
733
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
983
734
|
* Map({ key: "value" })
|
|
984
735
|
* Map([ [ "key", "value" ] ])
|
|
985
736
|
* ```
|
|
@@ -989,7 +740,7 @@ declare module Immutable {
|
|
|
989
740
|
* quote-less shorthand, while Immutable Maps accept keys of any type.
|
|
990
741
|
*
|
|
991
742
|
* <!-- runkit:activate
|
|
992
|
-
* { "preamble": "const { Map } = require(
|
|
743
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9');" }
|
|
993
744
|
* -->
|
|
994
745
|
* ```js
|
|
995
746
|
* let obj = { 1: "one" }
|
|
@@ -1025,7 +776,7 @@ declare module Immutable {
|
|
|
1025
776
|
*
|
|
1026
777
|
* <!-- runkit:activate -->
|
|
1027
778
|
* ```js
|
|
1028
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
779
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1029
780
|
* const originalMap = Map()
|
|
1030
781
|
* const newerMap = originalMap.set('key', 'value')
|
|
1031
782
|
* const newestMap = newerMap.set('key', 'newer value')
|
|
@@ -1050,7 +801,7 @@ declare module Immutable {
|
|
|
1050
801
|
*
|
|
1051
802
|
* <!-- runkit:activate -->
|
|
1052
803
|
* ```js
|
|
1053
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
804
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1054
805
|
* const originalMap = Map({
|
|
1055
806
|
* key: 'value',
|
|
1056
807
|
* otherKey: 'other value'
|
|
@@ -1072,7 +823,7 @@ declare module Immutable {
|
|
|
1072
823
|
*
|
|
1073
824
|
* <!-- runkit:activate -->
|
|
1074
825
|
* ```js
|
|
1075
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
826
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1076
827
|
* const names = Map({ a: "Aaron", b: "Barry", c: "Connor" })
|
|
1077
828
|
* names.deleteAll([ 'a', 'c' ])
|
|
1078
829
|
* // Map { "b": "Barry" }
|
|
@@ -1090,7 +841,7 @@ declare module Immutable {
|
|
|
1090
841
|
*
|
|
1091
842
|
* <!-- runkit:activate -->
|
|
1092
843
|
* ```js
|
|
1093
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
844
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1094
845
|
* Map({ key: 'value' }).clear()
|
|
1095
846
|
* // Map {}
|
|
1096
847
|
* ```
|
|
@@ -1107,7 +858,7 @@ declare module Immutable {
|
|
|
1107
858
|
*
|
|
1108
859
|
* <!-- runkit:activate -->
|
|
1109
860
|
* ```js
|
|
1110
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
861
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1111
862
|
* const aMap = Map({ key: 'value' })
|
|
1112
863
|
* const newMap = aMap.update('key', value => value + value)
|
|
1113
864
|
* // Map { "key": "valuevalue" }
|
|
@@ -1118,7 +869,7 @@ declare module Immutable {
|
|
|
1118
869
|
* `update` and `push` can be used together:
|
|
1119
870
|
*
|
|
1120
871
|
* <!-- runkit:activate
|
|
1121
|
-
* { "preamble": "const { Map, List } = require(
|
|
872
|
+
* { "preamble": "const { Map, List } = require('immutable@4.0.0-rc.9');" }
|
|
1122
873
|
* -->
|
|
1123
874
|
* ```js
|
|
1124
875
|
* const aMap = Map({ nestedList: List([ 1, 2, 3 ]) })
|
|
@@ -1130,7 +881,7 @@ declare module Immutable {
|
|
|
1130
881
|
* function when the value at the key does not exist in the Map.
|
|
1131
882
|
*
|
|
1132
883
|
* <!-- runkit:activate
|
|
1133
|
-
* { "preamble": "const { Map } = require(
|
|
884
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9');" }
|
|
1134
885
|
* -->
|
|
1135
886
|
* ```js
|
|
1136
887
|
* const aMap = Map({ key: 'value' })
|
|
@@ -1143,7 +894,7 @@ declare module Immutable {
|
|
|
1143
894
|
* is provided.
|
|
1144
895
|
*
|
|
1145
896
|
* <!-- runkit:activate
|
|
1146
|
-
* { "preamble": "const { Map } = require(
|
|
897
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9');" }
|
|
1147
898
|
* -->
|
|
1148
899
|
* ```js
|
|
1149
900
|
* const aMap = Map({ apples: 10 })
|
|
@@ -1159,7 +910,7 @@ declare module Immutable {
|
|
|
1159
910
|
* The previous example behaves differently when written with default values:
|
|
1160
911
|
*
|
|
1161
912
|
* <!-- runkit:activate
|
|
1162
|
-
* { "preamble": "const { Map } = require(
|
|
913
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9');" }
|
|
1163
914
|
* -->
|
|
1164
915
|
* ```js
|
|
1165
916
|
* const aMap = Map({ apples: 10 })
|
|
@@ -1171,7 +922,7 @@ declare module Immutable {
|
|
|
1171
922
|
* returned as well.
|
|
1172
923
|
*
|
|
1173
924
|
* <!-- runkit:activate
|
|
1174
|
-
* { "preamble": "const { Map } = require(
|
|
925
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9');" }
|
|
1175
926
|
* -->
|
|
1176
927
|
* ```js
|
|
1177
928
|
* const aMap = Map({ key: 'value' })
|
|
@@ -1185,7 +936,7 @@ declare module Immutable {
|
|
|
1185
936
|
* For example, to sum the values in a Map
|
|
1186
937
|
*
|
|
1187
938
|
* <!-- runkit:activate
|
|
1188
|
-
* { "preamble": "const { Map } = require(
|
|
939
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9');" }
|
|
1189
940
|
* -->
|
|
1190
941
|
* ```js
|
|
1191
942
|
* function sum(collection) {
|
|
@@ -1215,7 +966,7 @@ declare module Immutable {
|
|
|
1215
966
|
*
|
|
1216
967
|
* <!-- runkit:activate -->
|
|
1217
968
|
* ```js
|
|
1218
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
969
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1219
970
|
* const one = Map({ a: 10, b: 20, c: 30 })
|
|
1220
971
|
* const two = Map({ b: 40, a: 50, d: 60 })
|
|
1221
972
|
* one.merge(two) // Map { "a": 50, "b": 40, "c": 30, "d": 60 }
|
|
@@ -1223,8 +974,13 @@ declare module Immutable {
|
|
|
1223
974
|
* ```
|
|
1224
975
|
*
|
|
1225
976
|
* Note: `merge` can be used in `withMutations`.
|
|
977
|
+
*
|
|
978
|
+
* @alias concat
|
|
1226
979
|
*/
|
|
1227
|
-
merge(...collections: Array<Iterable<[
|
|
980
|
+
merge<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Map<K | KC, V | VC>;
|
|
981
|
+
merge<C>(...collections: Array<{[key: string]: C}>): Map<K | string, V | C>;
|
|
982
|
+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Map<K | KC, V | VC>;
|
|
983
|
+
concat<C>(...collections: Array<{[key: string]: C}>): Map<K | string, V | C>;
|
|
1228
984
|
|
|
1229
985
|
/**
|
|
1230
986
|
* Like `merge()`, `mergeWith()` returns a new Map resulting from merging
|
|
@@ -1233,7 +989,7 @@ declare module Immutable {
|
|
|
1233
989
|
*
|
|
1234
990
|
* <!-- runkit:activate -->
|
|
1235
991
|
* ```js
|
|
1236
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
992
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1237
993
|
* const one = Map({ a: 10, b: 20, c: 30 })
|
|
1238
994
|
* const two = Map({ b: 40, a: 50, d: 60 })
|
|
1239
995
|
* one.mergeWith((oldVal, newVal) => oldVal / newVal, two)
|
|
@@ -1259,7 +1015,7 @@ declare module Immutable {
|
|
|
1259
1015
|
*
|
|
1260
1016
|
* <!-- runkit:activate -->
|
|
1261
1017
|
* ```js
|
|
1262
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
1018
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1263
1019
|
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
|
1264
1020
|
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
|
1265
1021
|
* one.mergeDeep(two)
|
|
@@ -1280,7 +1036,7 @@ declare module Immutable {
|
|
|
1280
1036
|
*
|
|
1281
1037
|
* <!-- runkit:activate -->
|
|
1282
1038
|
* ```js
|
|
1283
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
1039
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1284
1040
|
* const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
|
1285
1041
|
* const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
|
1286
1042
|
* one.mergeDeepWith((oldVal, newVal) => oldVal / newVal, two)
|
|
@@ -1307,7 +1063,7 @@ declare module Immutable {
|
|
|
1307
1063
|
*
|
|
1308
1064
|
* <!-- runkit:activate -->
|
|
1309
1065
|
* ```js
|
|
1310
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
1066
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1311
1067
|
* const originalMap = Map({
|
|
1312
1068
|
* subObject: Map({
|
|
1313
1069
|
* subKey: 'subvalue',
|
|
@@ -1337,8 +1093,33 @@ declare module Immutable {
|
|
|
1337
1093
|
* // }
|
|
1338
1094
|
* ```
|
|
1339
1095
|
*
|
|
1340
|
-
*
|
|
1341
|
-
* (
|
|
1096
|
+
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
1097
|
+
* Collection, and setIn() can update those values as well, treating them
|
|
1098
|
+
* immutably by creating new copies of those values with the changes applied.
|
|
1099
|
+
*
|
|
1100
|
+
* <!-- runkit:activate -->
|
|
1101
|
+
* ```js
|
|
1102
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1103
|
+
* const originalMap = Map({
|
|
1104
|
+
* subObject: {
|
|
1105
|
+
* subKey: 'subvalue',
|
|
1106
|
+
* subSubObject: {
|
|
1107
|
+
* subSubKey: 'subSubValue'
|
|
1108
|
+
* }
|
|
1109
|
+
* }
|
|
1110
|
+
* })
|
|
1111
|
+
*
|
|
1112
|
+
* originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
|
|
1113
|
+
* // Map {
|
|
1114
|
+
* // "subObject": {
|
|
1115
|
+
* // subKey: "ha ha!",
|
|
1116
|
+
* // subSubObject: { subSubKey: "subSubValue" }
|
|
1117
|
+
* // }
|
|
1118
|
+
* // }
|
|
1119
|
+
* ```
|
|
1120
|
+
*
|
|
1121
|
+
* If any key in the path exists but cannot be updated (such as a primitive
|
|
1122
|
+
* like number or a custom Object like Date), an error will be thrown.
|
|
1342
1123
|
*
|
|
1343
1124
|
* Note: `setIn` can be used in `withMutations`.
|
|
1344
1125
|
*/
|
|
@@ -1365,7 +1146,7 @@ declare module Immutable {
|
|
|
1365
1146
|
*
|
|
1366
1147
|
* <!-- runkit:activate -->
|
|
1367
1148
|
* ```js
|
|
1368
|
-
* const { Map, List } = require('immutable@4.0.0-rc.
|
|
1149
|
+
* const { Map, List } = require('immutable@4.0.0-rc.9')
|
|
1369
1150
|
* const map = Map({ inMap: Map({ inList: List([ 1, 2, 3 ]) }) })
|
|
1370
1151
|
* const newMap = map.updateIn(['inMap', 'inList'], list => list.push(4))
|
|
1371
1152
|
* // Map { "inMap": Map { "inList": List [ 1, 2, 3, 4 ] } }
|
|
@@ -1377,7 +1158,7 @@ declare module Immutable {
|
|
|
1377
1158
|
* provided, otherwise `undefined`.
|
|
1378
1159
|
*
|
|
1379
1160
|
* <!-- runkit:activate
|
|
1380
|
-
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.
|
|
1161
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9')" }
|
|
1381
1162
|
* -->
|
|
1382
1163
|
* ```js
|
|
1383
1164
|
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
@@ -1389,7 +1170,7 @@ declare module Immutable {
|
|
|
1389
1170
|
* no change will occur. This is still true if `notSetValue` is provided.
|
|
1390
1171
|
*
|
|
1391
1172
|
* <!-- runkit:activate
|
|
1392
|
-
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.
|
|
1173
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9')" }
|
|
1393
1174
|
* -->
|
|
1394
1175
|
* ```js
|
|
1395
1176
|
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
@@ -1405,7 +1186,7 @@ declare module Immutable {
|
|
|
1405
1186
|
* The previous example behaves differently when written with default values:
|
|
1406
1187
|
*
|
|
1407
1188
|
* <!-- runkit:activate
|
|
1408
|
-
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.
|
|
1189
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9')" }
|
|
1409
1190
|
* -->
|
|
1410
1191
|
* ```js
|
|
1411
1192
|
* const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
|
@@ -1413,8 +1194,23 @@ declare module Immutable {
|
|
|
1413
1194
|
* // Map { "a": Map { "b": Map { "c": 10, "x": 100 } } }
|
|
1414
1195
|
* ```
|
|
1415
1196
|
*
|
|
1416
|
-
*
|
|
1417
|
-
*
|
|
1197
|
+
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
1198
|
+
* Collection, and updateIn() can update those values as well, treating them
|
|
1199
|
+
* immutably by creating new copies of those values with the changes applied.
|
|
1200
|
+
*
|
|
1201
|
+
* <!-- runkit:activate
|
|
1202
|
+
* { "preamble": "const { Map } = require('immutable@4.0.0-rc.9')" }
|
|
1203
|
+
* -->
|
|
1204
|
+
* ```js
|
|
1205
|
+
* const map = Map({ a: { b: { c: 10 } } })
|
|
1206
|
+
* const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
|
|
1207
|
+
* // Map { "a": { b: { c: 20 } } }
|
|
1208
|
+
* ```
|
|
1209
|
+
*
|
|
1210
|
+
* If any key in the path exists but cannot be updated (such as a primitive
|
|
1211
|
+
* like number or a custom Object like Date), an error will be thrown.
|
|
1212
|
+
*
|
|
1213
|
+
* Note: `updateIn` can be used in `withMutations`.
|
|
1418
1214
|
*/
|
|
1419
1215
|
updateIn(keyPath: Iterable<any>, notSetValue: any, updater: (value: any) => any): this;
|
|
1420
1216
|
updateIn(keyPath: Iterable<any>, updater: (value: any) => any): this;
|
|
@@ -1464,7 +1260,7 @@ declare module Immutable {
|
|
|
1464
1260
|
*
|
|
1465
1261
|
* <!-- runkit:activate -->
|
|
1466
1262
|
* ```js
|
|
1467
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
1263
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
1468
1264
|
* const map1 = Map()
|
|
1469
1265
|
* const map2 = map1.withMutations(map => {
|
|
1470
1266
|
* map.set('a', 1).set('b', 2).set('c', 3)
|
|
@@ -1512,12 +1308,6 @@ declare module Immutable {
|
|
|
1512
1308
|
|
|
1513
1309
|
// Sequence algorithms
|
|
1514
1310
|
|
|
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
1311
|
/**
|
|
1522
1312
|
* Returns a new Map with values passed through a
|
|
1523
1313
|
* `mapper` function.
|
|
@@ -1628,14 +1418,34 @@ declare module Immutable {
|
|
|
1628
1418
|
*/
|
|
1629
1419
|
readonly size: number;
|
|
1630
1420
|
|
|
1631
|
-
// Sequence algorithms
|
|
1632
|
-
|
|
1633
1421
|
/**
|
|
1634
|
-
* Returns a new OrderedMap
|
|
1422
|
+
* Returns a new OrderedMap resulting from merging the provided Collections
|
|
1423
|
+
* (or JS objects) into this OrderedMap. In other words, this takes each
|
|
1424
|
+
* entry of each collection and sets it on this OrderedMap.
|
|
1425
|
+
*
|
|
1426
|
+
* Note: Values provided to `merge` are shallowly converted before being
|
|
1427
|
+
* merged. No nested values are altered.
|
|
1428
|
+
*
|
|
1429
|
+
* <!-- runkit:activate -->
|
|
1430
|
+
* ```js
|
|
1431
|
+
* const { OrderedMap } = require('immutable@4.0.0-rc.9')
|
|
1432
|
+
* const one = OrderedMap({ a: 10, b: 20, c: 30 })
|
|
1433
|
+
* const two = OrderedMap({ b: 40, a: 50, d: 60 })
|
|
1434
|
+
* one.merge(two) // OrderedMap { "a": 50, "b": 40, "c": 30, "d": 60 }
|
|
1435
|
+
* two.merge(one) // OrderedMap { "b": 20, "a": 10, "d": 60, "c": 30 }
|
|
1436
|
+
* ```
|
|
1437
|
+
*
|
|
1438
|
+
* Note: `merge` can be used in `withMutations`.
|
|
1439
|
+
*
|
|
1440
|
+
* @alias concat
|
|
1635
1441
|
*/
|
|
1442
|
+
merge<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): OrderedMap<K | KC, V | VC>;
|
|
1443
|
+
merge<C>(...collections: Array<{[key: string]: C}>): OrderedMap<K | string, V | C>;
|
|
1636
1444
|
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): OrderedMap<K | KC, V | VC>;
|
|
1637
1445
|
concat<C>(...collections: Array<{[key: string]: C}>): OrderedMap<K | string, V | C>;
|
|
1638
1446
|
|
|
1447
|
+
// Sequence algorithms
|
|
1448
|
+
|
|
1639
1449
|
/**
|
|
1640
1450
|
* Returns a new OrderedMap with values passed through a
|
|
1641
1451
|
* `mapper` function.
|
|
@@ -1735,7 +1545,7 @@ declare module Immutable {
|
|
|
1735
1545
|
* a collection of other sets.
|
|
1736
1546
|
*
|
|
1737
1547
|
* ```js
|
|
1738
|
-
* const { Set } = require('immutable@4.0.0-rc.
|
|
1548
|
+
* const { Set } = require('immutable@4.0.0-rc.9')
|
|
1739
1549
|
* const intersected = Set.intersect([
|
|
1740
1550
|
* Set([ 'a', 'b', 'c' ])
|
|
1741
1551
|
* Set([ 'c', 'a', 't' ])
|
|
@@ -1750,7 +1560,7 @@ declare module Immutable {
|
|
|
1750
1560
|
* collection of other sets.
|
|
1751
1561
|
*
|
|
1752
1562
|
* ```js
|
|
1753
|
-
* const { Set } = require('immutable@4.0.0-rc.
|
|
1563
|
+
* const { Set } = require('immutable@4.0.0-rc.9')
|
|
1754
1564
|
* const unioned = Set.union([
|
|
1755
1565
|
* Set([ 'a', 'b', 'c' ])
|
|
1756
1566
|
* Set([ 'c', 'a', 't' ])
|
|
@@ -1811,9 +1621,11 @@ declare module Immutable {
|
|
|
1811
1621
|
*
|
|
1812
1622
|
* Note: `union` can be used in `withMutations`.
|
|
1813
1623
|
* @alias merge
|
|
1624
|
+
* @alias concat
|
|
1814
1625
|
*/
|
|
1815
|
-
union(...collections: Array<Iterable<
|
|
1816
|
-
merge(...collections: Array<Iterable<
|
|
1626
|
+
union<C>(...collections: Array<Iterable<C>>): Set<T | C>;
|
|
1627
|
+
merge<C>(...collections: Array<Iterable<C>>): Set<T | C>;
|
|
1628
|
+
concat<C>(...collections: Array<Iterable<C>>): Set<T | C>;
|
|
1817
1629
|
|
|
1818
1630
|
/**
|
|
1819
1631
|
* Returns a Set which has removed any values not also contained
|
|
@@ -1821,14 +1633,14 @@ declare module Immutable {
|
|
|
1821
1633
|
*
|
|
1822
1634
|
* Note: `intersect` can be used in `withMutations`.
|
|
1823
1635
|
*/
|
|
1824
|
-
intersect(...collections: Array<
|
|
1636
|
+
intersect(...collections: Array<Iterable<T>>): this;
|
|
1825
1637
|
|
|
1826
1638
|
/**
|
|
1827
1639
|
* Returns a Set excluding any values contained within `collections`.
|
|
1828
1640
|
*
|
|
1829
1641
|
* Note: `subtract` can be used in `withMutations`.
|
|
1830
1642
|
*/
|
|
1831
|
-
subtract(...collections: Array<
|
|
1643
|
+
subtract(...collections: Array<Iterable<T>>): this;
|
|
1832
1644
|
|
|
1833
1645
|
|
|
1834
1646
|
// Transient changes
|
|
@@ -1863,11 +1675,6 @@ declare module Immutable {
|
|
|
1863
1675
|
|
|
1864
1676
|
// Sequence algorithms
|
|
1865
1677
|
|
|
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
1678
|
/**
|
|
1872
1679
|
* Returns a new Set with values passed through a
|
|
1873
1680
|
* `mapper` function.
|
|
@@ -1956,12 +1763,19 @@ declare module Immutable {
|
|
|
1956
1763
|
*/
|
|
1957
1764
|
readonly size: number;
|
|
1958
1765
|
|
|
1959
|
-
// Sequence algorithms
|
|
1960
|
-
|
|
1961
1766
|
/**
|
|
1962
|
-
* Returns
|
|
1767
|
+
* Returns an OrderedSet including any value from `collections` that does
|
|
1768
|
+
* not already exist in this OrderedSet.
|
|
1769
|
+
*
|
|
1770
|
+
* Note: `union` can be used in `withMutations`.
|
|
1771
|
+
* @alias merge
|
|
1772
|
+
* @alias concat
|
|
1963
1773
|
*/
|
|
1964
|
-
|
|
1774
|
+
union<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
|
|
1775
|
+
merge<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
|
|
1776
|
+
concat<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
|
|
1777
|
+
|
|
1778
|
+
// Sequence algorithms
|
|
1965
1779
|
|
|
1966
1780
|
/**
|
|
1967
1781
|
* Returns a new Set with values passed through a
|
|
@@ -2317,7 +2131,7 @@ declare module Immutable {
|
|
|
2317
2131
|
* infinity. When `start` is equal to `end`, returns empty range.
|
|
2318
2132
|
*
|
|
2319
2133
|
* ```js
|
|
2320
|
-
* const { Range } = require('immutable@4.0.0-rc.
|
|
2134
|
+
* const { Range } = require('immutable@4.0.0-rc.9')
|
|
2321
2135
|
* Range() // [ 0, 1, 2, 3, ... ]
|
|
2322
2136
|
* Range(10) // [ 10, 11, 12, 13, ... ]
|
|
2323
2137
|
* Range(10, 15) // [ 10, 11, 12, 13, 14 ]
|
|
@@ -2334,7 +2148,7 @@ declare module Immutable {
|
|
|
2334
2148
|
* not defined, returns an infinite `Seq` of `value`.
|
|
2335
2149
|
*
|
|
2336
2150
|
* ```js
|
|
2337
|
-
* const { Repeat } = require('immutable@4.0.0-rc.
|
|
2151
|
+
* const { Repeat } = require('immutable@4.0.0-rc.9')
|
|
2338
2152
|
* Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
|
|
2339
2153
|
* Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
|
|
2340
2154
|
* ```
|
|
@@ -2350,7 +2164,7 @@ declare module Immutable {
|
|
|
2350
2164
|
* create Record instances.
|
|
2351
2165
|
*
|
|
2352
2166
|
* ```js
|
|
2353
|
-
* const { Record } = require('immutable@4.0.0-rc.
|
|
2167
|
+
* const { Record } = require('immutable@4.0.0-rc.9')
|
|
2354
2168
|
* const ABRecord = Record({ a: 1, b: 2 })
|
|
2355
2169
|
* const myRecord = new ABRecord({ b: 3 })
|
|
2356
2170
|
* ```
|
|
@@ -2429,6 +2243,44 @@ declare module Immutable {
|
|
|
2429
2243
|
* export type Point3D = RecordOf<Point3DProps>;
|
|
2430
2244
|
* const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 });
|
|
2431
2245
|
* ```
|
|
2246
|
+
*
|
|
2247
|
+
*
|
|
2248
|
+
* **Choosing Records vs plain JavaScript objects**
|
|
2249
|
+
*
|
|
2250
|
+
* Records ofters a persistently immutable alternative to plain JavaScript
|
|
2251
|
+
* objects, however they're not required to be used within Immutable.js
|
|
2252
|
+
* collections. In fact, the deep-access and deep-updating functions
|
|
2253
|
+
* like `getIn()` and `setIn()` work with plain JavaScript Objects as well.
|
|
2254
|
+
*
|
|
2255
|
+
* Deciding to use Records or Objects in your application should be informed
|
|
2256
|
+
* by the tradeoffs and relative benefits of each:
|
|
2257
|
+
*
|
|
2258
|
+
* - *Runtime immutability*: plain JS objects may be carefully treated as
|
|
2259
|
+
* immutable, however Record instances will *throw* if attempted to be
|
|
2260
|
+
* mutated directly. Records provide this additional guarantee, however at
|
|
2261
|
+
* some marginal runtime cost. While JS objects are mutable by nature, the
|
|
2262
|
+
* use of type-checking tools like [Flow](https://medium.com/@gcanti/immutability-with-flow-faa050a1aef4)
|
|
2263
|
+
* can help gain confidence in code written to favor immutability.
|
|
2264
|
+
*
|
|
2265
|
+
* - *Value equality*: Records use value equality when compared with `is()`
|
|
2266
|
+
* or `record.equals()`. That is, two Records with the same keys and values
|
|
2267
|
+
* are equal. Plain objects use *reference equality*. Two objects with the
|
|
2268
|
+
* same keys and values are not equal since they are different objects.
|
|
2269
|
+
* This is important to consider when using objects as keys in a `Map` or
|
|
2270
|
+
* values in a `Set`, which use equality when retrieving values.
|
|
2271
|
+
*
|
|
2272
|
+
* - *API methods*: Records have a full featured API, with methods like
|
|
2273
|
+
* `.getIn()`, and `.equals()`. These can make working with these values
|
|
2274
|
+
* easier, but comes at the cost of not allowing keys with those names.
|
|
2275
|
+
*
|
|
2276
|
+
* - *Default values*: Records provide default values for every key, which
|
|
2277
|
+
* can be useful when constructing Records with often unchanging values.
|
|
2278
|
+
* However default values can make using Flow and TypeScript more laborious.
|
|
2279
|
+
*
|
|
2280
|
+
* - *Serialization*: Records use a custom internal representation to
|
|
2281
|
+
* efficiently store and update their values. Converting to and from this
|
|
2282
|
+
* form isn't free. If converting Records to plain objects is common,
|
|
2283
|
+
* consider sticking with plain objects to begin with.
|
|
2432
2284
|
*/
|
|
2433
2285
|
export module Record {
|
|
2434
2286
|
|
|
@@ -2444,7 +2296,7 @@ declare module Immutable {
|
|
|
2444
2296
|
* method. If one was not provided, the string "Record" is returned.
|
|
2445
2297
|
*
|
|
2446
2298
|
* ```js
|
|
2447
|
-
* const { Record } = require('immutable@4.0.0-rc.
|
|
2299
|
+
* const { Record } = require('immutable@4.0.0-rc.9')
|
|
2448
2300
|
* const Person = Record({
|
|
2449
2301
|
* name: null
|
|
2450
2302
|
* }, 'Person')
|
|
@@ -2462,7 +2314,7 @@ declare module Immutable {
|
|
|
2462
2314
|
* type:
|
|
2463
2315
|
*
|
|
2464
2316
|
* <!-- runkit:activate
|
|
2465
|
-
* { "preamble": "const { Record } = require('immutable@4.0.0-rc.
|
|
2317
|
+
* { "preamble": "const { Record } = require('immutable@4.0.0-rc.9')" }
|
|
2466
2318
|
* -->
|
|
2467
2319
|
* ```js
|
|
2468
2320
|
* // makePerson is a Record Factory function
|
|
@@ -2477,7 +2329,7 @@ declare module Immutable {
|
|
|
2477
2329
|
* access on the resulting instances:
|
|
2478
2330
|
*
|
|
2479
2331
|
* <!-- runkit:activate
|
|
2480
|
-
* { "preamble": "const { Record } = require('immutable@4.0.0-rc.
|
|
2332
|
+
* { "preamble": "const { Record } = require('immutable@4.0.0-rc.9');const makePerson = Record({ name: null, favoriteColor: 'unknown' });const alan = makePerson({ name: 'Alan' });" }
|
|
2481
2333
|
* -->
|
|
2482
2334
|
* ```js
|
|
2483
2335
|
* // Use the Record API
|
|
@@ -2511,7 +2363,7 @@ declare module Immutable {
|
|
|
2511
2363
|
new (values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
|
|
2512
2364
|
}
|
|
2513
2365
|
|
|
2514
|
-
export function Factory(values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
|
|
2366
|
+
export function Factory<TProps extends Object>(values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
|
|
2515
2367
|
}
|
|
2516
2368
|
|
|
2517
2369
|
/**
|
|
@@ -2527,7 +2379,16 @@ declare module Immutable {
|
|
|
2527
2379
|
// Reading values
|
|
2528
2380
|
|
|
2529
2381
|
has(key: string): key is keyof TProps;
|
|
2530
|
-
|
|
2382
|
+
|
|
2383
|
+
/**
|
|
2384
|
+
* Returns the value associated with the provided key, which may be the
|
|
2385
|
+
* default value defined when creating the Record factory function.
|
|
2386
|
+
*
|
|
2387
|
+
* If the requested key is not defined by this Record type, then
|
|
2388
|
+
* notSetValue will be returned if provided. Note that this scenario would
|
|
2389
|
+
* produce an error when using Flow or TypeScript.
|
|
2390
|
+
*/
|
|
2391
|
+
get<K extends keyof TProps>(key: K, notSetValue: any): TProps[K];
|
|
2531
2392
|
|
|
2532
2393
|
// Reading deep values
|
|
2533
2394
|
|
|
@@ -2633,51 +2494,63 @@ declare module Immutable {
|
|
|
2633
2494
|
}
|
|
2634
2495
|
|
|
2635
2496
|
/**
|
|
2636
|
-
*
|
|
2637
|
-
*
|
|
2497
|
+
* `Seq` describes a lazy operation, allowing them to efficiently chain
|
|
2498
|
+
* use of all the higher-order collection methods (such as `map` and `filter`)
|
|
2499
|
+
* by not creating intermediate collections.
|
|
2638
2500
|
*
|
|
2639
2501
|
* **Seq is immutable** — Once a Seq is created, it cannot be
|
|
2640
2502
|
* changed, appended to, rearranged or otherwise modified. Instead, any
|
|
2641
2503
|
* mutative method called on a `Seq` will return a new `Seq`.
|
|
2642
2504
|
*
|
|
2643
|
-
* **Seq is lazy** — Seq does as little work as necessary to respond to any
|
|
2505
|
+
* **Seq is lazy** — `Seq` does as little work as necessary to respond to any
|
|
2644
2506
|
* method call. Values are often created during iteration, including implicit
|
|
2645
2507
|
* iteration when reducing or converting to a concrete data structure such as
|
|
2646
2508
|
* a `List` or JavaScript `Array`.
|
|
2647
2509
|
*
|
|
2648
2510
|
* For example, the following performs no work, because the resulting
|
|
2649
|
-
* Seq's values are never iterated:
|
|
2511
|
+
* `Seq`'s values are never iterated:
|
|
2650
2512
|
*
|
|
2651
2513
|
* ```js
|
|
2652
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
2514
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
2653
2515
|
* const oddSquares = Seq([ 1, 2, 3, 4, 5, 6, 7, 8 ])
|
|
2654
2516
|
* .filter(x => x % 2 !== 0)
|
|
2655
2517
|
* .map(x => x * x)
|
|
2656
2518
|
* ```
|
|
2657
2519
|
*
|
|
2658
|
-
* Once the Seq is used, it performs only the work necessary. In this
|
|
2659
|
-
* example, no intermediate
|
|
2660
|
-
*
|
|
2520
|
+
* Once the `Seq` is used, it performs only the work necessary. In this
|
|
2521
|
+
* example, no intermediate arrays are ever created, filter is called three
|
|
2522
|
+
* times, and map is only called once:
|
|
2661
2523
|
*
|
|
2662
|
-
* ```
|
|
2663
|
-
* oddSquares.get(1)
|
|
2524
|
+
* ```js
|
|
2525
|
+
* oddSquares.get(1); // 9
|
|
2664
2526
|
* ```
|
|
2665
2527
|
*
|
|
2666
|
-
*
|
|
2667
|
-
* allowing for the expression of logic that can otherwise be very tedious:
|
|
2528
|
+
* Any collection can be converted to a lazy Seq with `Seq()`.
|
|
2668
2529
|
*
|
|
2530
|
+
* <!-- runkit:activate -->
|
|
2531
|
+
* ```js
|
|
2532
|
+
* const { Map } = require('immutable')
|
|
2533
|
+
* const map = Map({ a: 1, b: 2, c: 3 }
|
|
2534
|
+
* const lazySeq = Seq(map)
|
|
2669
2535
|
* ```
|
|
2670
|
-
*
|
|
2536
|
+
*
|
|
2537
|
+
* `Seq` allows for the efficient chaining of operations, allowing for the
|
|
2538
|
+
* expression of logic that can otherwise be very tedious:
|
|
2539
|
+
*
|
|
2540
|
+
* ```js
|
|
2541
|
+
* lazySeq
|
|
2671
2542
|
* .flip()
|
|
2672
2543
|
* .map(key => key.toUpperCase())
|
|
2673
2544
|
* .flip()
|
|
2674
2545
|
* // Seq { A: 1, B: 1, C: 1 }
|
|
2675
2546
|
* ```
|
|
2676
2547
|
*
|
|
2677
|
-
* As well as expressing logic that would otherwise
|
|
2548
|
+
* As well as expressing logic that would otherwise seem memory or time
|
|
2549
|
+
* limited, for example `Range` is a special kind of Lazy sequence.
|
|
2678
2550
|
*
|
|
2551
|
+
* <!-- runkit:activate -->
|
|
2679
2552
|
* ```js
|
|
2680
|
-
* const { Range } = require('immutable@4.0.0-rc.
|
|
2553
|
+
* const { Range } = require('immutable@4.0.0-rc.9')
|
|
2681
2554
|
* Range(1, Infinity)
|
|
2682
2555
|
* .skip(1000)
|
|
2683
2556
|
* .map(n => -n)
|
|
@@ -2756,7 +2629,7 @@ declare module Immutable {
|
|
|
2756
2629
|
* `mapper` function.
|
|
2757
2630
|
*
|
|
2758
2631
|
* ```js
|
|
2759
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
2632
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
2760
2633
|
* Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
|
|
2761
2634
|
* // Seq { "a": 10, "b": 20 }
|
|
2762
2635
|
* ```
|
|
@@ -2868,7 +2741,7 @@ declare module Immutable {
|
|
|
2868
2741
|
* `mapper` function.
|
|
2869
2742
|
*
|
|
2870
2743
|
* ```js
|
|
2871
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
2744
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
2872
2745
|
* Seq.Indexed([ 1, 2 ]).map(x => 10 * x)
|
|
2873
2746
|
* // Seq [ 10, 20 ]
|
|
2874
2747
|
* ```
|
|
@@ -3013,7 +2886,7 @@ declare module Immutable {
|
|
|
3013
2886
|
* All entries will be present in the resulting Seq, even if they
|
|
3014
2887
|
* are duplicates.
|
|
3015
2888
|
*/
|
|
3016
|
-
concat<
|
|
2889
|
+
concat<U>(...collections: Array<Iterable<U>>): Seq.Set<T | U>;
|
|
3017
2890
|
|
|
3018
2891
|
/**
|
|
3019
2892
|
* Returns a new Seq.Set with values passed through a
|
|
@@ -3128,7 +3001,7 @@ declare module Immutable {
|
|
|
3128
3001
|
* `mapper` function.
|
|
3129
3002
|
*
|
|
3130
3003
|
* ```js
|
|
3131
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
3004
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
3132
3005
|
* Seq([ 1, 2 ]).map(x => 10 * x)
|
|
3133
3006
|
* // Seq [ 10, 20 ]
|
|
3134
3007
|
* ```
|
|
@@ -3146,7 +3019,7 @@ declare module Immutable {
|
|
|
3146
3019
|
* `mapper` function.
|
|
3147
3020
|
*
|
|
3148
3021
|
* ```js
|
|
3149
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
3022
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
3150
3023
|
* Seq([ 1, 2 ]).map(x => 10 * x)
|
|
3151
3024
|
* // Seq [ 10, 20 ]
|
|
3152
3025
|
* ```
|
|
@@ -3215,22 +3088,22 @@ declare module Immutable {
|
|
|
3215
3088
|
export module Collection {
|
|
3216
3089
|
|
|
3217
3090
|
/**
|
|
3218
|
-
* @deprecated use `const { isKeyed } = require('immutable@4.0.0-rc.
|
|
3091
|
+
* @deprecated use `const { isKeyed } = require('immutable@4.0.0-rc.9')`
|
|
3219
3092
|
*/
|
|
3220
3093
|
function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed<any, any>;
|
|
3221
3094
|
|
|
3222
3095
|
/**
|
|
3223
|
-
* @deprecated use `const { isIndexed } = require('immutable@4.0.0-rc.
|
|
3096
|
+
* @deprecated use `const { isIndexed } = require('immutable@4.0.0-rc.9')`
|
|
3224
3097
|
*/
|
|
3225
3098
|
function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed<any>;
|
|
3226
3099
|
|
|
3227
3100
|
/**
|
|
3228
|
-
* @deprecated use `const { isAssociative } = require('immutable@4.0.0-rc.
|
|
3101
|
+
* @deprecated use `const { isAssociative } = require('immutable@4.0.0-rc.9')`
|
|
3229
3102
|
*/
|
|
3230
3103
|
function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed<any, any> | Collection.Indexed<any>;
|
|
3231
3104
|
|
|
3232
3105
|
/**
|
|
3233
|
-
* @deprecated use `const { isOrdered } = require('immutable@4.0.0-rc.
|
|
3106
|
+
* @deprecated use `const { isOrdered } = require('immutable@4.0.0-rc.9')`
|
|
3234
3107
|
*/
|
|
3235
3108
|
function isOrdered(maybeOrdered: any): boolean;
|
|
3236
3109
|
|
|
@@ -3288,7 +3161,7 @@ declare module Immutable {
|
|
|
3288
3161
|
*
|
|
3289
3162
|
* <!-- runkit:activate -->
|
|
3290
3163
|
* ```js
|
|
3291
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
3164
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
3292
3165
|
* Map({ a: 'z', b: 'y' }).flip()
|
|
3293
3166
|
* // Map { "z": "a", "y": "b" }
|
|
3294
3167
|
* ```
|
|
@@ -3306,7 +3179,7 @@ declare module Immutable {
|
|
|
3306
3179
|
* `mapper` function.
|
|
3307
3180
|
*
|
|
3308
3181
|
* ```js
|
|
3309
|
-
* const { Collection } = require('immutable@4.0.0-rc.
|
|
3182
|
+
* const { Collection } = require('immutable@4.0.0-rc.9')
|
|
3310
3183
|
* Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
|
|
3311
3184
|
* // Seq { "a": 10, "b": 20 }
|
|
3312
3185
|
* ```
|
|
@@ -3325,7 +3198,7 @@ declare module Immutable {
|
|
|
3325
3198
|
*
|
|
3326
3199
|
* <!-- runkit:activate -->
|
|
3327
3200
|
* ```js
|
|
3328
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
3201
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
3329
3202
|
* Map({ a: 1, b: 2 }).mapKeys(x => x.toUpperCase())
|
|
3330
3203
|
* // Map { "A": 1, "B": 2 }
|
|
3331
3204
|
* ```
|
|
@@ -3344,7 +3217,7 @@ declare module Immutable {
|
|
|
3344
3217
|
*
|
|
3345
3218
|
* <!-- runkit:activate -->
|
|
3346
3219
|
* ```js
|
|
3347
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
3220
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
3348
3221
|
* Map({ a: 1, b: 2 })
|
|
3349
3222
|
* .mapEntries(([ k, v ]) => [ k.toUpperCase(), v * 2 ])
|
|
3350
3223
|
* // Map { "A": 2, "B": 4 }
|
|
@@ -3470,10 +3343,10 @@ declare module Immutable {
|
|
|
3470
3343
|
* second from each, etc.
|
|
3471
3344
|
*
|
|
3472
3345
|
* <!-- runkit:activate
|
|
3473
|
-
* { "preamble": "require('immutable@4.0.0-rc.
|
|
3346
|
+
* { "preamble": "require('immutable@4.0.0-rc.9')"}
|
|
3474
3347
|
* -->
|
|
3475
3348
|
* ```js
|
|
3476
|
-
* const { List } = require('immutable@4.0.0-rc.
|
|
3349
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
3477
3350
|
* List([ 1, 2, 3 ]).interleave(List([ 'A', 'B', 'C' ]))
|
|
3478
3351
|
* // List [ 1, "A", 2, "B", 3, "C"" ]
|
|
3479
3352
|
* ```
|
|
@@ -3481,7 +3354,7 @@ declare module Immutable {
|
|
|
3481
3354
|
* The shortest Collection stops interleave.
|
|
3482
3355
|
*
|
|
3483
3356
|
* <!-- runkit:activate
|
|
3484
|
-
* { "preamble": "const { List } = require('immutable@4.0.0-rc.
|
|
3357
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9')" }
|
|
3485
3358
|
* -->
|
|
3486
3359
|
* ```js
|
|
3487
3360
|
* List([ 1, 2, 3 ]).interleave(
|
|
@@ -3490,6 +3363,11 @@ declare module Immutable {
|
|
|
3490
3363
|
* )
|
|
3491
3364
|
* // List [ 1, "A", "X", 2, "B", "Y"" ]
|
|
3492
3365
|
* ```
|
|
3366
|
+
*
|
|
3367
|
+
* Since `interleave()` re-indexes values, it produces a complete copy,
|
|
3368
|
+
* which has `O(N)` complexity.
|
|
3369
|
+
*
|
|
3370
|
+
* Note: `interleave` *cannot* be used in `withMutations`.
|
|
3493
3371
|
*/
|
|
3494
3372
|
interleave(...collections: Array<Collection<any, T>>): this;
|
|
3495
3373
|
|
|
@@ -3503,10 +3381,15 @@ declare module Immutable {
|
|
|
3503
3381
|
*
|
|
3504
3382
|
* <!-- runkit:activate -->
|
|
3505
3383
|
* ```js
|
|
3506
|
-
* const { List } = require('immutable@4.0.0-rc.
|
|
3384
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
3507
3385
|
* List([ 'a', 'b', 'c', 'd' ]).splice(1, 2, 'q', 'r', 's')
|
|
3508
3386
|
* // List [ "a", "q", "r", "s", "d" ]
|
|
3509
3387
|
* ```
|
|
3388
|
+
*
|
|
3389
|
+
* Since `splice()` re-indexes values, it produces a complete copy, which
|
|
3390
|
+
* has `O(N)` complexity.
|
|
3391
|
+
*
|
|
3392
|
+
* Note: `splice` *cannot* be used in `withMutations`.
|
|
3510
3393
|
*/
|
|
3511
3394
|
splice(
|
|
3512
3395
|
index: number,
|
|
@@ -3522,7 +3405,7 @@ declare module Immutable {
|
|
|
3522
3405
|
*
|
|
3523
3406
|
*
|
|
3524
3407
|
* <!-- runkit:activate
|
|
3525
|
-
* { "preamble": "const { List } = require('immutable@4.0.0-rc.
|
|
3408
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9')" }
|
|
3526
3409
|
* -->
|
|
3527
3410
|
* ```js
|
|
3528
3411
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -3555,7 +3438,7 @@ declare module Immutable {
|
|
|
3555
3438
|
* collections by using a custom `zipper` function.
|
|
3556
3439
|
*
|
|
3557
3440
|
* <!-- runkit:activate
|
|
3558
|
-
* { "preamble": "const { List } = require('immutable@4.0.0-rc.
|
|
3441
|
+
* { "preamble": "const { List } = require('immutable@4.0.0-rc.9')" }
|
|
3559
3442
|
* -->
|
|
3560
3443
|
* ```js
|
|
3561
3444
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -3623,7 +3506,7 @@ declare module Immutable {
|
|
|
3623
3506
|
* `mapper` function.
|
|
3624
3507
|
*
|
|
3625
3508
|
* ```js
|
|
3626
|
-
* const { Collection } = require('immutable@4.0.0-rc.
|
|
3509
|
+
* const { Collection } = require('immutable@4.0.0-rc.9')
|
|
3627
3510
|
* Collection.Indexed([1,2]).map(x => 10 * x)
|
|
3628
3511
|
* // Seq [ 1, 2 ]
|
|
3629
3512
|
* ```
|
|
@@ -3675,7 +3558,7 @@ declare module Immutable {
|
|
|
3675
3558
|
* the value as both the first and second arguments to the provided function.
|
|
3676
3559
|
*
|
|
3677
3560
|
* ```js
|
|
3678
|
-
* const { Collection } = require('immutable@4.0.0-rc.
|
|
3561
|
+
* const { Collection } = require('immutable@4.0.0-rc.9')
|
|
3679
3562
|
* const seq = Collection.Set([ 'A', 'B', 'C' ])
|
|
3680
3563
|
* // Seq { "A", "B", "C" }
|
|
3681
3564
|
* seq.forEach((v, k) =>
|
|
@@ -3717,7 +3600,7 @@ declare module Immutable {
|
|
|
3717
3600
|
/**
|
|
3718
3601
|
* Returns a new Collection with other collections concatenated to this one.
|
|
3719
3602
|
*/
|
|
3720
|
-
concat<
|
|
3603
|
+
concat<U>(...collections: Array<Iterable<U>>): Collection.Set<T | U>;
|
|
3721
3604
|
|
|
3722
3605
|
/**
|
|
3723
3606
|
* Returns a new Collection.Set with values passed through a
|
|
@@ -3807,7 +3690,7 @@ declare module Immutable {
|
|
|
3807
3690
|
* lookup via a different instance.
|
|
3808
3691
|
*
|
|
3809
3692
|
* <!-- runkit:activate
|
|
3810
|
-
* { "preamble": "const { Set, List } = require('immutable@4.0.0-rc.
|
|
3693
|
+
* { "preamble": "const { Set, List } = require('immutable@4.0.0-rc.9')" }
|
|
3811
3694
|
* -->
|
|
3812
3695
|
* ```js
|
|
3813
3696
|
* const a = List([ 1, 2, 3 ]);
|
|
@@ -3869,6 +3752,23 @@ declare module Immutable {
|
|
|
3869
3752
|
/**
|
|
3870
3753
|
* Returns the value found by following a path of keys or indices through
|
|
3871
3754
|
* nested Collections.
|
|
3755
|
+
*
|
|
3756
|
+
* <!-- runkit:activate -->
|
|
3757
|
+
* ```js
|
|
3758
|
+
* const { Map, List } = require('immutable@4.0.0-rc.9')
|
|
3759
|
+
* const deepData = Map({ x: List([ Map({ y: 123 }) ]) });
|
|
3760
|
+
* getIn(deepData, ['x', 0, 'y']) // 123
|
|
3761
|
+
* ```
|
|
3762
|
+
*
|
|
3763
|
+
* Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
|
3764
|
+
* Collection, and getIn() can access those values as well:
|
|
3765
|
+
*
|
|
3766
|
+
* <!-- runkit:activate -->
|
|
3767
|
+
* ```js
|
|
3768
|
+
* const { Map, List } = require('immutable@4.0.0-rc.9')
|
|
3769
|
+
* const deepData = Map({ x: [ { y: 123 } ] });
|
|
3770
|
+
* getIn(deepData, ['x', 0, 'y']) // 123
|
|
3771
|
+
* ```
|
|
3872
3772
|
*/
|
|
3873
3773
|
getIn(searchKeyPath: Iterable<any>, notSetValue?: any): any;
|
|
3874
3774
|
|
|
@@ -3888,7 +3788,7 @@ declare module Immutable {
|
|
|
3888
3788
|
*
|
|
3889
3789
|
* <!-- runkit:activate -->
|
|
3890
3790
|
* ```js
|
|
3891
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
3791
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
3892
3792
|
*
|
|
3893
3793
|
* function sum(collection) {
|
|
3894
3794
|
* return collection.reduce((sum, x) => sum + x, 0)
|
|
@@ -3984,7 +3884,7 @@ declare module Immutable {
|
|
|
3984
3884
|
*
|
|
3985
3885
|
* <!-- runkit:activate -->
|
|
3986
3886
|
* ```js
|
|
3987
|
-
* const { Map, List } = require('immutable@4.0.0-rc.
|
|
3887
|
+
* const { Map, List } = require('immutable@4.0.0-rc.9')
|
|
3988
3888
|
* var myMap = Map({ a: 'Apple', b: 'Banana' })
|
|
3989
3889
|
* List(myMap) // List [ [ "a", "Apple" ], [ "b", "Banana" ] ]
|
|
3990
3890
|
* myMap.toList() // List [ "Apple", "Banana" ]
|
|
@@ -4021,7 +3921,7 @@ declare module Immutable {
|
|
|
4021
3921
|
*
|
|
4022
3922
|
* <!-- runkit:activate -->
|
|
4023
3923
|
* ```js
|
|
4024
|
-
* const { Seq } = require('immutable@4.0.0-rc.
|
|
3924
|
+
* const { Seq } = require('immutable@4.0.0-rc.9')
|
|
4025
3925
|
* const indexedSeq = Seq([ 'A', 'B', 'C' ])
|
|
4026
3926
|
* // Seq [ "A", "B", "C" ]
|
|
4027
3927
|
* indexedSeq.filter(v => v === 'B')
|
|
@@ -4102,7 +4002,7 @@ declare module Immutable {
|
|
|
4102
4002
|
*
|
|
4103
4003
|
* <!-- runkit:activate -->
|
|
4104
4004
|
* ```js
|
|
4105
|
-
* const { Collection } = require('immutable@4.0.0-rc.
|
|
4005
|
+
* const { Collection } = require('immutable@4.0.0-rc.9')
|
|
4106
4006
|
* Collection({ a: 1, b: 2 }).map(x => 10 * x)
|
|
4107
4007
|
* // Seq { "a": 10, "b": 20 }
|
|
4108
4008
|
* ```
|
|
@@ -4129,7 +4029,7 @@ declare module Immutable {
|
|
|
4129
4029
|
*
|
|
4130
4030
|
* <!-- runkit:activate -->
|
|
4131
4031
|
* ```js
|
|
4132
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
4032
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
4133
4033
|
* Map({ a: 1, b: 2, c: 3, d: 4}).filter(x => x % 2 === 0)
|
|
4134
4034
|
* // Map { "b": 2, "d": 4 }
|
|
4135
4035
|
* ```
|
|
@@ -4152,7 +4052,7 @@ declare module Immutable {
|
|
|
4152
4052
|
*
|
|
4153
4053
|
* <!-- runkit:activate -->
|
|
4154
4054
|
* ```js
|
|
4155
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
4055
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
4156
4056
|
* Map({ a: 1, b: 2, c: 3, d: 4}).filterNot(x => x % 2 === 0)
|
|
4157
4057
|
* // Map { "a": 1, "c": 3 }
|
|
4158
4058
|
* ```
|
|
@@ -4189,7 +4089,7 @@ declare module Immutable {
|
|
|
4189
4089
|
*
|
|
4190
4090
|
* <!-- runkit:activate -->
|
|
4191
4091
|
* ```js
|
|
4192
|
-
* const { Map } = require('immutable@4.0.0-rc.
|
|
4092
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
4193
4093
|
* Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
|
|
4194
4094
|
* if (a < b) { return -1; }
|
|
4195
4095
|
* if (a > b) { return 1; }
|
|
@@ -4229,7 +4129,7 @@ declare module Immutable {
|
|
|
4229
4129
|
*
|
|
4230
4130
|
* <!-- runkit:activate -->
|
|
4231
4131
|
* ```js
|
|
4232
|
-
* const { List, Map } = require('immutable@4.0.0-rc.
|
|
4132
|
+
* const { List, Map } = require('immutable@4.0.0-rc.9')
|
|
4233
4133
|
* const listOfMaps = List([
|
|
4234
4134
|
* Map({ v: 0 }),
|
|
4235
4135
|
* Map({ v: 1 }),
|
|
@@ -4316,7 +4216,7 @@ declare module Immutable {
|
|
|
4316
4216
|
*
|
|
4317
4217
|
* <!-- runkit:activate -->
|
|
4318
4218
|
* ```js
|
|
4319
|
-
* const { List } = require('immutable@4.0.0-rc.
|
|
4219
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
4320
4220
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4321
4221
|
* .skipWhile(x => x.match(/g/))
|
|
4322
4222
|
* // List [ "cat", "hat", "god"" ]
|
|
@@ -4333,7 +4233,7 @@ declare module Immutable {
|
|
|
4333
4233
|
*
|
|
4334
4234
|
* <!-- runkit:activate -->
|
|
4335
4235
|
* ```js
|
|
4336
|
-
* const { List } = require('immutable@4.0.0-rc.
|
|
4236
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
4337
4237
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4338
4238
|
* .skipUntil(x => x.match(/hat/))
|
|
4339
4239
|
* // List [ "hat", "god"" ]
|
|
@@ -4362,7 +4262,7 @@ declare module Immutable {
|
|
|
4362
4262
|
*
|
|
4363
4263
|
* <!-- runkit:activate -->
|
|
4364
4264
|
* ```js
|
|
4365
|
-
* const { List } = require('immutable@4.0.0-rc.
|
|
4265
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
4366
4266
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4367
4267
|
* .takeWhile(x => x.match(/o/))
|
|
4368
4268
|
* // List [ "dog", "frog" ]
|
|
@@ -4379,7 +4279,7 @@ declare module Immutable {
|
|
|
4379
4279
|
*
|
|
4380
4280
|
* <!-- runkit:activate -->
|
|
4381
4281
|
* ```js
|
|
4382
|
-
* const { List } = require('immutable@4.0.0-rc.
|
|
4282
|
+
* const { List } = require('immutable@4.0.0-rc.9')
|
|
4383
4283
|
* List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
|
|
4384
4284
|
* .takeUntil(x => x.match(/at/))
|
|
4385
4285
|
* // List [ "dog", "frog" ]
|
|
@@ -4674,6 +4574,578 @@ declare module Immutable {
|
|
|
4674
4574
|
*/
|
|
4675
4575
|
isSuperset(iter: Iterable<V>): boolean;
|
|
4676
4576
|
}
|
|
4577
|
+
|
|
4578
|
+
/**
|
|
4579
|
+
* The interface to fulfill to qualify as a Value Object.
|
|
4580
|
+
*/
|
|
4581
|
+
export interface ValueObject {
|
|
4582
|
+
/**
|
|
4583
|
+
* True if this and the other Collection have value equality, as defined
|
|
4584
|
+
* by `Immutable.is()`.
|
|
4585
|
+
*
|
|
4586
|
+
* Note: This is equivalent to `Immutable.is(this, other)`, but provided to
|
|
4587
|
+
* allow for chained expressions.
|
|
4588
|
+
*/
|
|
4589
|
+
equals(other: any): boolean;
|
|
4590
|
+
|
|
4591
|
+
/**
|
|
4592
|
+
* Computes and returns the hashed identity for this Collection.
|
|
4593
|
+
*
|
|
4594
|
+
* The `hashCode` of a Collection is used to determine potential equality,
|
|
4595
|
+
* and is used when adding this to a `Set` or as a key in a `Map`, enabling
|
|
4596
|
+
* lookup via a different instance.
|
|
4597
|
+
*
|
|
4598
|
+
* <!-- runkit:activate -->
|
|
4599
|
+
* ```js
|
|
4600
|
+
* const { List, Set } = require('immutable@4.0.0-rc.9');
|
|
4601
|
+
* const a = List([ 1, 2, 3 ]);
|
|
4602
|
+
* const b = List([ 1, 2, 3 ]);
|
|
4603
|
+
* assert.notStrictEqual(a, b); // different instances
|
|
4604
|
+
* const set = Set([ a ]);
|
|
4605
|
+
* assert.equal(set.has(b), true);
|
|
4606
|
+
* ```
|
|
4607
|
+
*
|
|
4608
|
+
* Note: hashCode() MUST return a Uint32 number. The easiest way to
|
|
4609
|
+
* guarantee this is to return `myHash | 0` from a custom implementation.
|
|
4610
|
+
*
|
|
4611
|
+
* If two values have the same `hashCode`, they are [not guaranteed
|
|
4612
|
+
* to be equal][Hash Collision]. If two values have different `hashCode`s,
|
|
4613
|
+
* they must not be equal.
|
|
4614
|
+
*
|
|
4615
|
+
* Note: `hashCode()` is not guaranteed to always be called before
|
|
4616
|
+
* `equals()`. Most but not all Immutable.js collections use hash codes to
|
|
4617
|
+
* organize their internal data structures, while all Immutable.js
|
|
4618
|
+
* collections use equality during lookups.
|
|
4619
|
+
*
|
|
4620
|
+
* [Hash Collision]: http://en.wikipedia.org/wiki/Collision_(computer_science)
|
|
4621
|
+
*/
|
|
4622
|
+
hashCode(): number;
|
|
4623
|
+
}
|
|
4624
|
+
|
|
4625
|
+
/**
|
|
4626
|
+
* Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
|
|
4627
|
+
*
|
|
4628
|
+
* If a `reviver` is optionally provided, it will be called with every
|
|
4629
|
+
* collection as a Seq (beginning with the most nested collections
|
|
4630
|
+
* and proceeding to the top-level collection itself), along with the key
|
|
4631
|
+
* refering to each collection and the parent JS object provided as `this`.
|
|
4632
|
+
* For the top level, object, the key will be `""`. This `reviver` is expected
|
|
4633
|
+
* to return a new Immutable Collection, allowing for custom conversions from
|
|
4634
|
+
* deep JS objects. Finally, a `path` is provided which is the sequence of
|
|
4635
|
+
* keys to this value from the starting value.
|
|
4636
|
+
*
|
|
4637
|
+
* `reviver` acts similarly to the [same parameter in `JSON.parse`][1].
|
|
4638
|
+
*
|
|
4639
|
+
* If `reviver` is not provided, the default behavior will convert Objects
|
|
4640
|
+
* into Maps and Arrays into Lists like so:
|
|
4641
|
+
*
|
|
4642
|
+
* <!-- runkit:activate -->
|
|
4643
|
+
* ```js
|
|
4644
|
+
* const { fromJS, isKeyed } = require('immutable@4.0.0-rc.9')
|
|
4645
|
+
* function (key, value) {
|
|
4646
|
+
* return isKeyed(value) ? value.Map() : value.toList()
|
|
4647
|
+
* }
|
|
4648
|
+
* ```
|
|
4649
|
+
*
|
|
4650
|
+
* `fromJS` is conservative in its conversion. It will only convert
|
|
4651
|
+
* arrays which pass `Array.isArray` to Lists, and only raw objects (no custom
|
|
4652
|
+
* prototype) to Map.
|
|
4653
|
+
*
|
|
4654
|
+
* Accordingly, this example converts native JS data to OrderedMap and List:
|
|
4655
|
+
*
|
|
4656
|
+
* <!-- runkit:activate -->
|
|
4657
|
+
* ```js
|
|
4658
|
+
* const { fromJS, isKeyed } = require('immutable@4.0.0-rc.9')
|
|
4659
|
+
* fromJS({ a: {b: [10, 20, 30]}, c: 40}, function (key, value, path) {
|
|
4660
|
+
* console.log(key, value, path)
|
|
4661
|
+
* return isKeyed(value) ? value.toOrderedMap() : value.toList()
|
|
4662
|
+
* })
|
|
4663
|
+
*
|
|
4664
|
+
* > "b", [ 10, 20, 30 ], [ "a", "b" ]
|
|
4665
|
+
* > "a", {b: [10, 20, 30]}, [ "a" ]
|
|
4666
|
+
* > "", {a: {b: [10, 20, 30]}, c: 40}, []
|
|
4667
|
+
* ```
|
|
4668
|
+
*
|
|
4669
|
+
* Keep in mind, when using JS objects to construct Immutable Maps, that
|
|
4670
|
+
* JavaScript Object properties are always strings, even if written in a
|
|
4671
|
+
* quote-less shorthand, while Immutable Maps accept keys of any type.
|
|
4672
|
+
*
|
|
4673
|
+
* <!-- runkit:activate -->
|
|
4674
|
+
* ```js
|
|
4675
|
+
* const { Map } = require('immutable@4.0.0-rc.9')
|
|
4676
|
+
* let obj = { 1: "one" };
|
|
4677
|
+
* Object.keys(obj); // [ "1" ]
|
|
4678
|
+
* assert.equal(obj["1"], obj[1]); // "one" === "one"
|
|
4679
|
+
*
|
|
4680
|
+
* let map = Map(obj);
|
|
4681
|
+
* assert.notEqual(map.get("1"), map.get(1)); // "one" !== undefined
|
|
4682
|
+
* ```
|
|
4683
|
+
*
|
|
4684
|
+
* Property access for JavaScript Objects first converts the key to a string,
|
|
4685
|
+
* but since Immutable Map keys can be of any type the argument to `get()` is
|
|
4686
|
+
* not altered.
|
|
4687
|
+
*
|
|
4688
|
+
* [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter
|
|
4689
|
+
* "Using the reviver parameter"
|
|
4690
|
+
*/
|
|
4691
|
+
export function fromJS(
|
|
4692
|
+
jsValue: any,
|
|
4693
|
+
reviver?: (
|
|
4694
|
+
key: string | number,
|
|
4695
|
+
sequence: Collection.Keyed<string, any> | Collection.Indexed<any>,
|
|
4696
|
+
path?: Array<string | number>
|
|
4697
|
+
) => any
|
|
4698
|
+
): any;
|
|
4699
|
+
|
|
4700
|
+
/**
|
|
4701
|
+
* Value equality check with semantics similar to `Object.is`, but treats
|
|
4702
|
+
* Immutable `Collection`s as values, equal if the second `Collection` includes
|
|
4703
|
+
* equivalent values.
|
|
4704
|
+
*
|
|
4705
|
+
* It's used throughout Immutable when checking for equality, including `Map`
|
|
4706
|
+
* key equality and `Set` membership.
|
|
4707
|
+
*
|
|
4708
|
+
* <!-- runkit:activate -->
|
|
4709
|
+
* ```js
|
|
4710
|
+
* const { Map, is } = require('immutable@4.0.0-rc.9')
|
|
4711
|
+
* const map1 = Map({ a: 1, b: 1, c: 1 })
|
|
4712
|
+
* const map2 = Map({ a: 1, b: 1, c: 1 })
|
|
4713
|
+
* assert.equal(map1 !== map2, true)
|
|
4714
|
+
* assert.equal(Object.is(map1, map2), false)
|
|
4715
|
+
* assert.equal(is(map1, map2), true)
|
|
4716
|
+
* ```
|
|
4717
|
+
*
|
|
4718
|
+
* `is()` compares primitive types like strings and numbers, Immutable.js
|
|
4719
|
+
* collections like `Map` and `List`, but also any custom object which
|
|
4720
|
+
* implements `ValueObject` by providing `equals()` and `hashCode()` methods.
|
|
4721
|
+
*
|
|
4722
|
+
* Note: Unlike `Object.is`, `Immutable.is` assumes `0` and `-0` are the same
|
|
4723
|
+
* value, matching the behavior of ES6 Map key equality.
|
|
4724
|
+
*/
|
|
4725
|
+
export function is(first: any, second: any): boolean;
|
|
4726
|
+
|
|
4727
|
+
/**
|
|
4728
|
+
* The `hash()` function is an important part of how Immutable determines if
|
|
4729
|
+
* two values are equivalent and is used to determine how to store those
|
|
4730
|
+
* values. Provided with any value, `hash()` will return a 31-bit integer.
|
|
4731
|
+
*
|
|
4732
|
+
* When designing Objects which may be equal, it's important than when a
|
|
4733
|
+
* `.equals()` method returns true, that both values `.hashCode()` method
|
|
4734
|
+
* return the same value. `hash()` may be used to produce those values.
|
|
4735
|
+
*
|
|
4736
|
+
* For non-Immutable Objects that do not provide a `.hashCode()` functions
|
|
4737
|
+
* (including plain Objects, plain Arrays, Date objects, etc), a unique hash
|
|
4738
|
+
* value will be created for each *instance*. That is, the create hash
|
|
4739
|
+
* represents referential equality, and not value equality for Objects. This
|
|
4740
|
+
* ensures that if that Object is mutated over time that its hash code will
|
|
4741
|
+
* remain consistent, allowing Objects to be used as keys and values in
|
|
4742
|
+
* Immutable.js collections.
|
|
4743
|
+
*
|
|
4744
|
+
* Note that `hash()` attempts to balance between speed and avoiding
|
|
4745
|
+
* collisions, however it makes no attempt to produce secure hashes.
|
|
4746
|
+
*
|
|
4747
|
+
* *New in Version 4.0*
|
|
4748
|
+
*/
|
|
4749
|
+
export function hash(value: any): number;
|
|
4750
|
+
|
|
4751
|
+
/**
|
|
4752
|
+
* True if `maybeImmutable` is an Immutable Collection or Record.
|
|
4753
|
+
*
|
|
4754
|
+
* Note: Still returns true even if the collections is within a `withMutations()`.
|
|
4755
|
+
*
|
|
4756
|
+
* <!-- runkit:activate -->
|
|
4757
|
+
* ```js
|
|
4758
|
+
* const { isImmutable, Map, List, Stack } = require('immutable@4.0.0-rc.9');
|
|
4759
|
+
* isImmutable([]); // false
|
|
4760
|
+
* isImmutable({}); // false
|
|
4761
|
+
* isImmutable(Map()); // true
|
|
4762
|
+
* isImmutable(List()); // true
|
|
4763
|
+
* isImmutable(Stack()); // true
|
|
4764
|
+
* isImmutable(Map().asMutable()); // true
|
|
4765
|
+
* ```
|
|
4766
|
+
*/
|
|
4767
|
+
export function isImmutable(maybeImmutable: any): maybeImmutable is Collection<any, any>;
|
|
4768
|
+
|
|
4769
|
+
/**
|
|
4770
|
+
* True if `maybeCollection` is a Collection, or any of its subclasses.
|
|
4771
|
+
*
|
|
4772
|
+
* <!-- runkit:activate -->
|
|
4773
|
+
* ```js
|
|
4774
|
+
* const { isCollection, Map, List, Stack } = require('immutable@4.0.0-rc.9');
|
|
4775
|
+
* isCollection([]); // false
|
|
4776
|
+
* isCollection({}); // false
|
|
4777
|
+
* isCollection(Map()); // true
|
|
4778
|
+
* isCollection(List()); // true
|
|
4779
|
+
* isCollection(Stack()); // true
|
|
4780
|
+
* ```
|
|
4781
|
+
*/
|
|
4782
|
+
export function isCollection(maybeCollection: any): maybeCollection is Collection<any, any>;
|
|
4783
|
+
|
|
4784
|
+
/**
|
|
4785
|
+
* True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
|
|
4786
|
+
*
|
|
4787
|
+
* <!-- runkit:activate -->
|
|
4788
|
+
* ```js
|
|
4789
|
+
* const { isKeyed, Map, List, Stack } = require('immutable@4.0.0-rc.9');
|
|
4790
|
+
* isKeyed([]); // false
|
|
4791
|
+
* isKeyed({}); // false
|
|
4792
|
+
* isKeyed(Map()); // true
|
|
4793
|
+
* isKeyed(List()); // false
|
|
4794
|
+
* isKeyed(Stack()); // false
|
|
4795
|
+
* ```
|
|
4796
|
+
*/
|
|
4797
|
+
export function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed<any, any>;
|
|
4798
|
+
|
|
4799
|
+
/**
|
|
4800
|
+
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
|
|
4801
|
+
*
|
|
4802
|
+
* <!-- runkit:activate -->
|
|
4803
|
+
* ```js
|
|
4804
|
+
* const { isIndexed, Map, List, Stack, Set } = require('immutable@4.0.0-rc.9');
|
|
4805
|
+
* isIndexed([]); // false
|
|
4806
|
+
* isIndexed({}); // false
|
|
4807
|
+
* isIndexed(Map()); // false
|
|
4808
|
+
* isIndexed(List()); // true
|
|
4809
|
+
* isIndexed(Stack()); // true
|
|
4810
|
+
* isIndexed(Set()); // false
|
|
4811
|
+
* ```
|
|
4812
|
+
*/
|
|
4813
|
+
export function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed<any>;
|
|
4814
|
+
|
|
4815
|
+
/**
|
|
4816
|
+
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
|
|
4817
|
+
*
|
|
4818
|
+
* <!-- runkit:activate -->
|
|
4819
|
+
* ```js
|
|
4820
|
+
* const { isAssociative, Map, List, Stack, Set } = require('immutable@4.0.0-rc.9');
|
|
4821
|
+
* isAssociative([]); // false
|
|
4822
|
+
* isAssociative({}); // false
|
|
4823
|
+
* isAssociative(Map()); // true
|
|
4824
|
+
* isAssociative(List()); // true
|
|
4825
|
+
* isAssociative(Stack()); // true
|
|
4826
|
+
* isAssociative(Set()); // false
|
|
4827
|
+
* ```
|
|
4828
|
+
*/
|
|
4829
|
+
export function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed<any, any> | Collection.Indexed<any>;
|
|
4830
|
+
|
|
4831
|
+
/**
|
|
4832
|
+
* True if `maybeOrdered` is a Collection where iteration order is well
|
|
4833
|
+
* defined. True for Collection.Indexed as well as OrderedMap and OrderedSet.
|
|
4834
|
+
*
|
|
4835
|
+
* <!-- runkit:activate -->
|
|
4836
|
+
* ```js
|
|
4837
|
+
* const { isOrdered, Map, OrderedMap, List, Set } = require('immutable@4.0.0-rc.9');
|
|
4838
|
+
* isOrdered([]); // false
|
|
4839
|
+
* isOrdered({}); // false
|
|
4840
|
+
* isOrdered(Map()); // false
|
|
4841
|
+
* isOrdered(OrderedMap()); // true
|
|
4842
|
+
* isOrdered(List()); // true
|
|
4843
|
+
* isOrdered(Set()); // false
|
|
4844
|
+
* ```
|
|
4845
|
+
*/
|
|
4846
|
+
export function isOrdered(maybeOrdered: any): boolean;
|
|
4847
|
+
|
|
4848
|
+
/**
|
|
4849
|
+
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
|
|
4850
|
+
* and `hashCode()` methods.
|
|
4851
|
+
*
|
|
4852
|
+
* Any two instances of *value objects* can be compared for value equality with
|
|
4853
|
+
* `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
|
|
4854
|
+
*/
|
|
4855
|
+
export function isValueObject(maybeValue: any): maybeValue is ValueObject;
|
|
4856
|
+
|
|
4857
|
+
/**
|
|
4858
|
+
* Returns the value within the provided collection associated with the
|
|
4859
|
+
* provided key, or notSetValue if the key is not defined in the collection.
|
|
4860
|
+
*
|
|
4861
|
+
* A functional alternative to `collection.get(key)` which will also work on
|
|
4862
|
+
* plain Objects and Arrays as an alternative for `collection[key]`.
|
|
4863
|
+
*
|
|
4864
|
+
* <!-- runkit:activate -->
|
|
4865
|
+
* ```js
|
|
4866
|
+
* const { get } = require('immutable@4.0.0-rc.9')
|
|
4867
|
+
* get([ 'dog', 'frog', 'cat' ], 2) // 'frog'
|
|
4868
|
+
* get({ x: 123, y: 456 }, 'x') // 123
|
|
4869
|
+
* get({ x: 123, y: 456 }, 'z', 'ifNotSet') // 'ifNotSet'
|
|
4870
|
+
* ```
|
|
4871
|
+
*/
|
|
4872
|
+
export function get<K, V>(collection: Collection<K, V>, key: K): V | undefined;
|
|
4873
|
+
export function get<K, V, NSV>(collection: Collection<K, V>, key: K, notSetValue: NSV): V | NSV;
|
|
4874
|
+
export function get<TProps, K extends keyof TProps>(record: Record<TProps>, key: K, notSetValue: any): TProps[K];
|
|
4875
|
+
export function get<V>(collection: Array<V>, key: number): V | undefined;
|
|
4876
|
+
export function get<V, NSV>(collection: Array<V>, key: number, notSetValue: NSV): V | NSV;
|
|
4877
|
+
export function get<C extends Object, K extends keyof C>(object: C, key: K, notSetValue: any): C[K];
|
|
4878
|
+
export function get<V>(collection: {[key: string]: V}, key: string): V | undefined;
|
|
4879
|
+
export function get<V, NSV>(collection: {[key: string]: V}, key: string, notSetValue: NSV): V | NSV;
|
|
4880
|
+
|
|
4881
|
+
/**
|
|
4882
|
+
* Returns true if the key is defined in the provided collection.
|
|
4883
|
+
*
|
|
4884
|
+
* A functional alternative to `collection.has(key)` which will also work with
|
|
4885
|
+
* plain Objects and Arrays as an alternative for
|
|
4886
|
+
* `collection.hasOwnProperty(key)`.
|
|
4887
|
+
*
|
|
4888
|
+
* <!-- runkit:activate -->
|
|
4889
|
+
* ```js
|
|
4890
|
+
* const { has } = require('immutable@4.0.0-rc.9')
|
|
4891
|
+
* has([ 'dog', 'frog', 'cat' ], 2) // true
|
|
4892
|
+
* has([ 'dog', 'frog', 'cat' ], 5) // false
|
|
4893
|
+
* has({ x: 123, y: 456 }, 'x') // true
|
|
4894
|
+
* has({ x: 123, y: 456 }, 'z') // false
|
|
4895
|
+
* ```
|
|
4896
|
+
*/
|
|
4897
|
+
export function has(collection: Object, key: any): boolean;
|
|
4898
|
+
|
|
4899
|
+
/**
|
|
4900
|
+
* Returns a copy of the collection with the value at key removed.
|
|
4901
|
+
*
|
|
4902
|
+
* A functional alternative to `collection.remove(key)` which will also work
|
|
4903
|
+
* with plain Objects and Arrays as an alternative for
|
|
4904
|
+
* `delete collectionCopy[key]`.
|
|
4905
|
+
*
|
|
4906
|
+
* <!-- runkit:activate -->
|
|
4907
|
+
* ```js
|
|
4908
|
+
* const { remove } = require('immutable@4.0.0-rc.9')
|
|
4909
|
+
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
4910
|
+
* remove(originalArray, 1) // [ 'dog', 'cat' ]
|
|
4911
|
+
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
4912
|
+
* const originalObject = { x: 123, y: 456 }
|
|
4913
|
+
* remove(originalObject, 'x') // { y: 456 }
|
|
4914
|
+
* console.log(originalObject) // { x: 123, y: 456 }
|
|
4915
|
+
* ```
|
|
4916
|
+
*/
|
|
4917
|
+
export function remove<K, C extends Collection<K, any>>(collection: C, key: K): C;
|
|
4918
|
+
export function remove<TProps, C extends Record<TProps>, K extends keyof TProps>(collection: C, key: K): C;
|
|
4919
|
+
export function remove<C extends Array<any>>(collection: C, key: number): C;
|
|
4920
|
+
export function remove<C, K extends keyof C>(collection: C, key: K): C;
|
|
4921
|
+
export function remove<C extends {[key: string]: any}, K extends keyof C>(collection: C, key: K): C;
|
|
4922
|
+
|
|
4923
|
+
/**
|
|
4924
|
+
* Returns a copy of the collection with the value at key set to the provided
|
|
4925
|
+
* value.
|
|
4926
|
+
*
|
|
4927
|
+
* A functional alternative to `collection.set(key, value)` which will also
|
|
4928
|
+
* work with plain Objects and Arrays as an alternative for
|
|
4929
|
+
* `collectionCopy[key] = value`.
|
|
4930
|
+
*
|
|
4931
|
+
* <!-- runkit:activate -->
|
|
4932
|
+
* ```js
|
|
4933
|
+
* const { set } = require('immutable@4.0.0-rc.9')
|
|
4934
|
+
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
4935
|
+
* set(originalArray, 1, 'cow') // [ 'dog', 'cow', 'cat' ]
|
|
4936
|
+
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
4937
|
+
* const originalObject = { x: 123, y: 456 }
|
|
4938
|
+
* set(originalObject, 'x', 789) // { x: 789, y: 456 }
|
|
4939
|
+
* console.log(originalObject) // { x: 123, y: 456 }
|
|
4940
|
+
* ```
|
|
4941
|
+
*/
|
|
4942
|
+
export function set<K, V, C extends Collection<K, V>>(collection: C, key: K, value: V): C;
|
|
4943
|
+
export function set<TProps, C extends Record<TProps>, K extends keyof TProps>(record: C, key: K, value: TProps[K]): C;
|
|
4944
|
+
export function set<V, C extends Array<V>>(collection: C, key: number, value: V): C;
|
|
4945
|
+
export function set<C, K extends keyof C>(object: C, key: K, value: C[K]): C;
|
|
4946
|
+
export function set<V, C extends {[key: string]: V}>(collection: C, key: string, value: V): C;
|
|
4947
|
+
|
|
4948
|
+
/**
|
|
4949
|
+
* Returns a copy of the collection with the value at key set to the result of
|
|
4950
|
+
* providing the existing value to the updating function.
|
|
4951
|
+
*
|
|
4952
|
+
* A functional alternative to `collection.update(key, fn)` which will also
|
|
4953
|
+
* work with plain Objects and Arrays as an alternative for
|
|
4954
|
+
* `collectionCopy[key] = fn(collection[key])`.
|
|
4955
|
+
*
|
|
4956
|
+
* <!-- runkit:activate -->
|
|
4957
|
+
* ```js
|
|
4958
|
+
* const { update } = require('immutable@4.0.0-rc.9')
|
|
4959
|
+
* const originalArray = [ 'dog', 'frog', 'cat' ]
|
|
4960
|
+
* update(originalArray, 1, val => val.toUpperCase()) // [ 'dog', 'FROG', 'cat' ]
|
|
4961
|
+
* console.log(originalArray) // [ 'dog', 'frog', 'cat' ]
|
|
4962
|
+
* const originalObject = { x: 123, y: 456 }
|
|
4963
|
+
* set(originalObject, 'x', val => val * 6) // { x: 738, y: 456 }
|
|
4964
|
+
* console.log(originalObject) // { x: 123, y: 456 }
|
|
4965
|
+
* ```
|
|
4966
|
+
*/
|
|
4967
|
+
export function update<K, V, C extends Collection<K, V>>(collection: C, key: K, updater: (value: V) => V): C;
|
|
4968
|
+
export function update<K, V, C extends Collection<K, V>, NSV>(collection: C, key: K, notSetValue: NSV, updater: (value: V | NSV) => V): C;
|
|
4969
|
+
export function update<TProps, C extends Record<TProps>, K extends keyof TProps>(record: C, key: K, updater: (value: TProps[K]) => TProps[K]): C;
|
|
4970
|
+
export function update<TProps, C extends Record<TProps>, K extends keyof TProps, NSV>(record: C, key: K, notSetValue: NSV, updater: (value: TProps[K] | NSV) => TProps[K]): C;
|
|
4971
|
+
export function update<V>(collection: Array<V>, key: number, updater: (value: V) => V): Array<V>;
|
|
4972
|
+
export function update<V, NSV>(collection: Array<V>, key: number, notSetValue: NSV, updater: (value: V | NSV) => V): Array<V>;
|
|
4973
|
+
export function update<C, K extends keyof C>(object: C, key: K, updater: (value: C[K]) => C[K]): C;
|
|
4974
|
+
export function update<C, K extends keyof C, NSV>(object: C, key: K, notSetValue: NSV, updater: (value: C[K] | NSV) => C[K]): C;
|
|
4975
|
+
export function update<V, C extends {[key: string]: V}, K extends keyof C>(collection: C, key: K, updater: (value: V) => V): {[key: string]: V};
|
|
4976
|
+
export function update<V, C extends {[key: string]: V}, K extends keyof C, NSV>(collection: C, key: K, notSetValue: NSV, updater: (value: V | NSV) => V): {[key: string]: V};
|
|
4977
|
+
|
|
4978
|
+
/**
|
|
4979
|
+
* Returns the value at the provided key path starting at the provided
|
|
4980
|
+
* collection, or notSetValue if the key path is not defined.
|
|
4981
|
+
*
|
|
4982
|
+
* A functional alternative to `collection.getIn(keypath)` which will also
|
|
4983
|
+
* work with plain Objects and Arrays.
|
|
4984
|
+
*
|
|
4985
|
+
* <!-- runkit:activate -->
|
|
4986
|
+
* ```js
|
|
4987
|
+
* const { getIn } = require('immutable@4.0.0-rc.9')
|
|
4988
|
+
* getIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // 123
|
|
4989
|
+
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
|
|
4990
|
+
* ```
|
|
4991
|
+
*/
|
|
4992
|
+
export function getIn(collection: any, keyPath: Iterable<any>, notSetValue: any): any;
|
|
4993
|
+
|
|
4994
|
+
/**
|
|
4995
|
+
* Returns true if the key path is defined in the provided collection.
|
|
4996
|
+
*
|
|
4997
|
+
* A functional alternative to `collection.hasIn(keypath)` which will also
|
|
4998
|
+
* work with plain Objects and Arrays.
|
|
4999
|
+
*
|
|
5000
|
+
* <!-- runkit:activate -->
|
|
5001
|
+
* ```js
|
|
5002
|
+
* const { hasIn } = require('immutable@4.0.0-rc.9')
|
|
5003
|
+
* hasIn({ x: { y: { z: 123 }}}, ['x', 'y', 'z']) // true
|
|
5004
|
+
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
|
|
5005
|
+
* ```
|
|
5006
|
+
*/
|
|
5007
|
+
export function hasIn(collection: any, keyPath: Iterable<any>): boolean;
|
|
5008
|
+
|
|
5009
|
+
/**
|
|
5010
|
+
* Returns a copy of the collection with the value at the key path removed.
|
|
5011
|
+
*
|
|
5012
|
+
* A functional alternative to `collection.removeIn(keypath)` which will also
|
|
5013
|
+
* work with plain Objects and Arrays.
|
|
5014
|
+
*
|
|
5015
|
+
* <!-- runkit:activate -->
|
|
5016
|
+
* ```js
|
|
5017
|
+
* const { removeIn } = require('immutable@4.0.0-rc.9')
|
|
5018
|
+
* const original = { x: { y: { z: 123 }}}
|
|
5019
|
+
* removeIn(original, ['x', 'y', 'z']) // { x: { y: {}}}
|
|
5020
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5021
|
+
* ```
|
|
5022
|
+
*/
|
|
5023
|
+
export function removeIn<C>(collection: C, keyPath: Iterable<any>): C;
|
|
5024
|
+
|
|
5025
|
+
/**
|
|
5026
|
+
* Returns a copy of the collection with the value at the key path set to the
|
|
5027
|
+
* provided value.
|
|
5028
|
+
*
|
|
5029
|
+
* A functional alternative to `collection.setIn(keypath)` which will also
|
|
5030
|
+
* work with plain Objects and Arrays.
|
|
5031
|
+
*
|
|
5032
|
+
* <!-- runkit:activate -->
|
|
5033
|
+
* ```js
|
|
5034
|
+
* const { setIn } = require('immutable@4.0.0-rc.9')
|
|
5035
|
+
* const original = { x: { y: { z: 123 }}}
|
|
5036
|
+
* setIn(original, ['x', 'y', 'z'], 456) // { x: { y: { z: 456 }}}
|
|
5037
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5038
|
+
* ```
|
|
5039
|
+
*/
|
|
5040
|
+
export function setIn<C>(collection: C, keyPath: Iterable<any>, value: any): C;
|
|
5041
|
+
|
|
5042
|
+
/**
|
|
5043
|
+
* Returns a copy of the collection with the value at key path set to the
|
|
5044
|
+
* result of providing the existing value to the updating function.
|
|
5045
|
+
*
|
|
5046
|
+
* A functional alternative to `collection.updateIn(keypath)` which will also
|
|
5047
|
+
* work with plain Objects and Arrays.
|
|
5048
|
+
*
|
|
5049
|
+
* <!-- runkit:activate -->
|
|
5050
|
+
* ```js
|
|
5051
|
+
* const { setIn } = require('immutable@4.0.0-rc.9')
|
|
5052
|
+
* const original = { x: { y: { z: 123 }}}
|
|
5053
|
+
* setIn(original, ['x', 'y', 'z'], val => val * 6) // { x: { y: { z: 738 }}}
|
|
5054
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5055
|
+
* ```
|
|
5056
|
+
*/
|
|
5057
|
+
export function updateIn<C>(collection: C, keyPath: Iterable<any>, updater: (value: any) => any): C;
|
|
5058
|
+
export function updateIn<C>(collection: C, keyPath: Iterable<any>, notSetValue: any, updater: (value: any) => any): C;
|
|
5059
|
+
|
|
5060
|
+
/**
|
|
5061
|
+
* Returns a copy of the collection with the remaining collections merged in.
|
|
5062
|
+
*
|
|
5063
|
+
* A functional alternative to `collection.merge()` which will also work with
|
|
5064
|
+
* plain Objects and Arrays.
|
|
5065
|
+
*
|
|
5066
|
+
* <!-- runkit:activate -->
|
|
5067
|
+
* ```js
|
|
5068
|
+
* const { merge } = require('immutable@4.0.0-rc.9')
|
|
5069
|
+
* const original = { x: 123, y: 456 }
|
|
5070
|
+
* merge(original, { y: 789, z: 'abc' }) // { x: 123, y: 789, z: 'abc' }
|
|
5071
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5072
|
+
* ```
|
|
5073
|
+
*/
|
|
5074
|
+
export function merge<C>(
|
|
5075
|
+
collection: C,
|
|
5076
|
+
...collections: Array<Iterable<any> | Iterable<[any, any]> | {[key: string]: any}>
|
|
5077
|
+
): C;
|
|
5078
|
+
|
|
5079
|
+
/**
|
|
5080
|
+
* Returns a copy of the collection with the remaining collections merged in,
|
|
5081
|
+
* calling the `merger` function whenever an existing value is encountered.
|
|
5082
|
+
*
|
|
5083
|
+
* A functional alternative to `collection.mergeWith()` which will also work
|
|
5084
|
+
* with plain Objects and Arrays.
|
|
5085
|
+
*
|
|
5086
|
+
* <!-- runkit:activate -->
|
|
5087
|
+
* ```js
|
|
5088
|
+
* const { mergeWith } = require('immutable@4.0.0-rc.9')
|
|
5089
|
+
* const original = { x: 123, y: 456 }
|
|
5090
|
+
* mergeWith(
|
|
5091
|
+
* (oldVal, newVal) => oldVal + newVal,
|
|
5092
|
+
* original,
|
|
5093
|
+
* { y: 789, z: 'abc' }
|
|
5094
|
+
* ) // { x: 123, y: 1245, z: 'abc' }
|
|
5095
|
+
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5096
|
+
* ```
|
|
5097
|
+
*/
|
|
5098
|
+
export function mergeWith<C>(
|
|
5099
|
+
merger: (oldVal: any, newVal: any, key: any) => any,
|
|
5100
|
+
collection: C,
|
|
5101
|
+
...collections: Array<Iterable<any> | Iterable<[any, any]> | {[key: string]: any}>
|
|
5102
|
+
): C;
|
|
5103
|
+
|
|
5104
|
+
/**
|
|
5105
|
+
* Returns a copy of the collection with the remaining collections merged in
|
|
5106
|
+
* deeply (recursively).
|
|
5107
|
+
*
|
|
5108
|
+
* A functional alternative to `collection.mergeDeep()` which will also work
|
|
5109
|
+
* with plain Objects and Arrays.
|
|
5110
|
+
*
|
|
5111
|
+
* <!-- runkit:activate -->
|
|
5112
|
+
* ```js
|
|
5113
|
+
* const { merge } = require('immutable@4.0.0-rc.9')
|
|
5114
|
+
* const original = { x: { y: 123 }}
|
|
5115
|
+
* merge(original, { x: { z: 456 }}) // { x: { y: 123, z: 456 }}
|
|
5116
|
+
* console.log(original) // { x: { y: 123 }}
|
|
5117
|
+
* ```
|
|
5118
|
+
*/
|
|
5119
|
+
export function mergeDeep<C>(
|
|
5120
|
+
collection: C,
|
|
5121
|
+
...collections: Array<Iterable<any> | Iterable<[any, any]> | {[key: string]: any}>
|
|
5122
|
+
): C;
|
|
5123
|
+
|
|
5124
|
+
/**
|
|
5125
|
+
* Returns a copy of the collection with the remaining collections merged in
|
|
5126
|
+
* deeply (recursively), calling the `merger` function whenever an existing
|
|
5127
|
+
* value is encountered.
|
|
5128
|
+
*
|
|
5129
|
+
* A functional alternative to `collection.mergeDeepWith()` which will also
|
|
5130
|
+
* work with plain Objects and Arrays.
|
|
5131
|
+
*
|
|
5132
|
+
* <!-- runkit:activate -->
|
|
5133
|
+
* ```js
|
|
5134
|
+
* const { merge } = require('immutable@4.0.0-rc.9')
|
|
5135
|
+
* const original = { x: { y: 123 }}
|
|
5136
|
+
* mergeDeepWith(
|
|
5137
|
+
* (oldVal, newVal) => oldVal + newVal,
|
|
5138
|
+
* original,
|
|
5139
|
+
* { x: { y: 456 }}
|
|
5140
|
+
* ) // { x: { y: 579 }}
|
|
5141
|
+
* console.log(original) // { x: { y: 123 }}
|
|
5142
|
+
* ```
|
|
5143
|
+
*/
|
|
5144
|
+
export function mergeDeepWith<C>(
|
|
5145
|
+
merger: (oldVal: any, newVal: any, key: any) => any,
|
|
5146
|
+
collection: C,
|
|
5147
|
+
...collections: Array<Iterable<any> | Iterable<[any, any]> | {[key: string]: any}>
|
|
5148
|
+
): C;
|
|
4677
5149
|
}
|
|
4678
5150
|
|
|
4679
5151
|
declare module "immutable" {
|