@@ -515,7 +515,7 @@ declare module 'immutable' {
515
515
/**
516
516
* Returns the value found by following a key path through nested sequences.
517
517
*/
518
- getIn ( searchKeyPath : Array < K > , notSetValue ?: V ) : V ;
518
+ getIn ( searchKeyPath : Array < any > , notSetValue ?: any ) : any ;
519
519
520
520
/**
521
521
* Returns a `Sequence` of `Sequences`, grouped by the return value of the
@@ -1186,24 +1186,6 @@ declare module 'immutable' {
1186
1186
*/
1187
1187
clear ( ) : Map < K , V > ;
1188
1188
1189
- /**
1190
- * When this cursor's (or any of its sub-cursors') `update` method is called,
1191
- * the resulting new data structure will be provided to the `onChange`
1192
- * function. Use this callback to keep track of the most current value or
1193
- * update the rest of your application.
1194
- */
1195
- cursor (
1196
- onChange ?: ( newValue : Map < K , V > , oldValue ?: Map < K , V > , keyPath ?: Array < any > ) => void
1197
- ) : Cursor < Map < K , V > > ;
1198
- cursor (
1199
- keyPath : Array < any > ,
1200
- onChange ?: ( newValue : Map < K , V > , oldValue ?: Map < K , V > , keyPath ?: Array < any > ) => void
1201
- ) : Cursor < any > ;
1202
- cursor (
1203
- key : K ,
1204
- onChange ?: ( newValue : Map < K , V > , oldValue ?: Map < K , V > , keyPath ?: Array < any > ) => void
1205
- ) : Cursor < V > ;
1206
-
1207
1189
/**
1208
1190
* Returns a new Map having updated the value at this `key` with the return
1209
1191
* value of calling `updater` with the existing value, or `notSetValue` if
@@ -1343,6 +1325,69 @@ declare module 'immutable' {
1343
1325
* copy has become immutable and can be safely returned from a function.
1344
1326
*/
1345
1327
asImmutable ( ) : Map < K , V > ;
1328
+
1329
+ /**
1330
+ * Cursors allow you to hold a reference to a path in a nested immutable
1331
+ * data structure, allowing you to pass smaller sections of a larger nested
1332
+ * collection to portions of your application while maintaining a central
1333
+ * point aware of changes to the entire data structure.
1334
+ *
1335
+ * This is particularly useful when used in conjuction with component-based
1336
+ * UI libraries like [React](http://facebook.github.io/react/) or to
1337
+ * simulate "state" throughout an application while maintaining a single
1338
+ * flow of logic.
1339
+ *
1340
+ * Cursors provide a simple API for getting the value at that path
1341
+ * (the equivalent of `this.getIn(keyPath)`), updating the value at that
1342
+ * path (the equivalent of `this.updateIn(keyPath)`), and getting a
1343
+ * sub-cursor starting from that path.
1344
+ *
1345
+ * When updated, a new root collection is created and provided to the
1346
+ * `onChange` function provided to the first call to `map.cursor(...)`. Use
1347
+ * this callback to keep track of the most current value or update the rest
1348
+ * of your application.
1349
+ *
1350
+ * Cursors assume the type of the data they point to. For example:
1351
+ *
1352
+ * var map = Immutable.Map({ x: Immutable.Vector(1, 2, 3) });
1353
+ * assert(map.cursor('x') instanceof Immutable.Vector);
1354
+ *
1355
+ * A cursor to a value that is not an Immutable Sequence simply returns that
1356
+ * value, any edits to which are not tracked:
1357
+ *
1358
+ * var mapToJSArray = Immutable.Map({ x: [1, 2, 3] });
1359
+ * var jsArray = mapToJSArray.cursor('x');
1360
+ * assert(Array.is(jsArray));
1361
+ *
1362
+ * The `onChange` callback is invoked whenever an edit occurs on the cursor,
1363
+ * it is provided the new value, the previous value, and a key-path
1364
+ * illustrating where the change occurred.
1365
+ *
1366
+ * var map = Immutable.fromJS({ a: { b: { x: 1, y: 2 } } });
1367
+ * var ab = map.cursor(['a', 'b'], function (newValue, oldValue, path) {
1368
+ * map = newValue;
1369
+ * console.log('New:', newValue);
1370
+ * console.log('Old:', oldValue);
1371
+ * console.log('Path:', path);
1372
+ * });
1373
+ * ab = ab.set('y', 10);
1374
+ * // New: Map { a: Map { b: Map { x: 1, y: 10 } } }
1375
+ * // Old: Map { a: Map { b: Map { x: 1, y: 2 } } }
1376
+ * // Path: [ 'a', 'b', 'y' ]
1377
+ * console.log(ab); // Map { x: 1, y: 10 }
1378
+ *
1379
+ */
1380
+ cursor (
1381
+ onChange ?: ( newValue : Map < K , V > , oldValue ?: Map < K , V > , changePath ?: Array < any > ) => void
1382
+ ) : Map < K , V > ;
1383
+ cursor (
1384
+ keyPath : Array < any > ,
1385
+ onChange ?: ( newValue : Map < K , V > , oldValue ?: Map < K , V > , changePath ?: Array < any > ) => void
1386
+ ) : any ;
1387
+ cursor (
1388
+ key : K ,
1389
+ onChange ?: ( newValue : Map < K , V > , oldValue ?: Map < K , V > , changePath ?: Array < any > ) => void
1390
+ ) : V ;
1346
1391
}
1347
1392
1348
1393
@@ -1660,22 +1705,6 @@ declare module 'immutable' {
1660
1705
*/
1661
1706
shift ( ) : Vector < T > ;
1662
1707
1663
- /**
1664
- * @see Map.cursor
1665
- */
1666
- cursor (
1667
- onChange ?: ( newValue : Vector < T > , oldValue ?: Vector < T > , keyPath ?: Array < any > ) => void
1668
- ) : Cursor < Vector < T > > ;
1669
- cursor (
1670
- keyPath : Array < any > ,
1671
- onChange ?: ( newValue : Vector < T > , oldValue ?: Vector < T > , keyPath ?: Array < any > ) => void
1672
- ) : Cursor < any > ;
1673
- cursor (
1674
- key : number ,
1675
- onChange ?: ( newValue : Vector < T > , oldValue ?: Vector < T > , keyPath ?: Array < any > ) => void
1676
- ) : Cursor < T > ;
1677
-
1678
-
1679
1708
/**
1680
1709
* Returns a new Vector with an updated value at `index` with the return
1681
1710
* value of calling `updater` with the existing value, or `notSetValue` if
@@ -1762,6 +1791,21 @@ declare module 'immutable' {
1762
1791
* @see `Map.prototype.asImmutable`
1763
1792
*/
1764
1793
asImmutable ( ) : Vector < T > ;
1794
+
1795
+ /**
1796
+ * @see Map.cursor
1797
+ */
1798
+ cursor (
1799
+ onChange ?: ( newValue : Vector < T > , oldValue ?: Vector < T > , changePath ?: Array < any > ) => void
1800
+ ) : Vector < T > ;
1801
+ cursor (
1802
+ keyPath : Array < any > ,
1803
+ onChange ?: ( newValue : Vector < T > , oldValue ?: Vector < T > , changePath ?: Array < any > ) => void
1804
+ ) : any ;
1805
+ cursor (
1806
+ key : number ,
1807
+ onChange ?: ( newValue : Vector < T > , oldValue ?: Vector < T > , changePath ?: Array < any > ) => void
1808
+ ) : T ;
1765
1809
}
1766
1810
1767
1811
@@ -1876,102 +1920,6 @@ declare module 'immutable' {
1876
1920
}
1877
1921
1878
1922
1879
- /**
1880
- * Cursors
1881
- * -------
1882
- *
1883
- * Cursors allow you to hold a reference to a path in a nested immutable data
1884
- * structure, allowing you to pass smaller sections of a larger nested
1885
- * collection to portions of your application while maintaining a central point
1886
- * aware of changes to the entire data structure.
1887
- *
1888
- * This is particularly useful when used in conjuction with component-based UI
1889
- * libraries like [React](http://facebook.github.io/react/) or to simulate
1890
- * "state" throughout an application while maintaining a single flow of logic.
1891
- *
1892
- * Cursors provide a simple API for getting the value at that path
1893
- * (the equivalent of `this.getIn(keyPath)`), updating the value at that path
1894
- * (the equivalent of `this.updateIn(keyPath)`), and getting a sub-cursor
1895
- * starting from that path.
1896
- *
1897
- * When updated, a new root collection is created and provided to the `onChange`
1898
- * function provided to the first call to `map.cursor(...)`.
1899
- *
1900
- * @see Map.cursor
1901
- */
1902
-
1903
- export interface Cursor < T > extends Sequence < any , any > {
1904
-
1905
- /**
1906
- * Returns a sub-cursor following the key-path starting from this cursor.
1907
- */
1908
- cursor ( subKeyPath : Array < any > ) : Cursor < any > ;
1909
- cursor ( subKey : any ) : Cursor < any > ;
1910
-
1911
- /**
1912
- * Returns the value at the cursor, if the cursor path does not yet exist,
1913
- * returns `notSetValue`.
1914
- */
1915
- deref ( notSetValue ?: T ) : T ;
1916
-
1917
- /**
1918
- * Returns the value at the `key` in the cursor, or `notSetValue` if it
1919
- * does not exist.
1920
- *
1921
- * If the key would return a collection, a new Cursor is returned.
1922
- */
1923
- get ( key : any , notSetValue ?: any ) : any ;
1924
-
1925
- /**
1926
- * Returns the value at the `keyPath` in the cursor, or `notSetValue` if it
1927
- * does not exist.
1928
- *
1929
- * If the keyPath would return a collection, a new Cursor is returned.
1930
- */
1931
- getIn ( keyPath : Array < any > , notSetValue ?: any ) : any ;
1932
-
1933
- /**
1934
- * Sets `value` at `key` in the cursor, returning a new cursor to the same
1935
- * point in the new data.
1936
- */
1937
- set ( key : any , value : any ) : Cursor < T > ;
1938
-
1939
- /**
1940
- * Deletes `key` from the cursor, returning a new cursor to the same
1941
- * point in the new data.
1942
- *
1943
- * Note: `delete` cannot be safely used in IE8
1944
- * @alias delete
1945
- */
1946
- remove ( key : any ) : Cursor < T > ;
1947
- delete ( key : any ) : Cursor < T > ;
1948
-
1949
- /**
1950
- * Clears the value at this cursor, returning a new cursor to the same
1951
- * point in the new data.
1952
- */
1953
- clear ( ) : Cursor < T > ;
1954
-
1955
- /**
1956
- * Updates the value in the data this cursor points to, triggering the
1957
- * callback for the root cursor and returning a new cursor pointing to the
1958
- * new data.
1959
- */
1960
- update ( updater : ( value : T ) => T ) : Cursor < T > ;
1961
- update ( key : any , updater : ( value : any ) => any ) : Cursor < T > ;
1962
- update ( key : any , notSetValue : any , updater : ( value : any ) => any ) : Cursor < T > ;
1963
-
1964
-
1965
- /**
1966
- * Every time you call one of the above functions, a new immutable value is
1967
- * created and the callback is triggered. If you need to apply a series of
1968
- * mutations to a Cursor without triggering the callback repeatedly,
1969
- * `withMutations()` creates a temporary mutable copy of the value which
1970
- * can apply mutations in a highly performant manner. Afterwards the
1971
- * callback is triggered with the final value.
1972
- */
1973
- withMutations ( mutator : ( mutable : T ) => T ) : Cursor < T > ;
1974
- }
1975
1923
1976
1924
// ES6 Iterator
1977
1925
export interface Iterator < T > {
0 commit comments