immutable 3.8.2 → 4.0.0-rc.12

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.
@@ -1,3 +1,13 @@
1
+ # DEPRECATED
2
+
3
+ The Cursor API is deprecated and will be removed in a future major release.
4
+
5
+ It is strongly suggested that you use the excellent `immutable-cursor` module
6
+ which has an extremely similar API but is much higher quality.
7
+
8
+ https://github.com/redbadger/immutable-cursor
9
+
10
+
1
11
  Cursors
2
12
  -------
3
13
 
@@ -7,8 +17,8 @@ collection to portions of your application while maintaining a central point
7
17
  aware of changes to the entire data structure: an `onChange` function which is
8
18
  called whenever a cursor or sub-cursor calls `update`.
9
19
 
10
- This is particularly useful when used in conjuction with component-based UI
11
- libraries like [React](http://facebook.github.io/react/) or to simulate
20
+ This is particularly useful when used in conjunction with component-based UI
21
+ libraries like [React](https://facebook.github.io/react/) or to simulate
12
22
  "state" throughout an application while maintaining a single flow of logic.
13
23
 
14
24
 
@@ -6,25 +6,20 @@
6
6
  */
7
7
 
8
8
  ///<reference path='../../../resources/jest.d.ts'/>
9
- ///<reference path='../../../dist/immutable.d.ts'/>
10
- ///<reference path='../index.d.ts'/>
11
9
 
12
- jest.autoMockOff();
13
-
14
- import Immutable = require('immutable');
15
- import Cursor = require('immutable/contrib/cursor');
10
+ import * as Immutable from '../../../';
11
+ import * as Cursor from '../';
16
12
 
17
13
  describe('Cursor', () => {
18
14
 
19
15
  beforeEach(function () {
20
- this.addMatchers({
21
- toValueEqual: function (expected) {
22
- var actual = this.actual;
23
- if (!Immutable.is(expected, this.actual)) {
24
- this.message = 'Expected\n' + this.actual + '\nto equal\n' + expected;
25
- return false;
26
- }
27
- return true;
16
+ jasmine.addMatchers({
17
+ toValueEqual: function(actual, expected) {
18
+ var passed = Immutable.is(actual, expected);
19
+ return {
20
+ pass: passed,
21
+ message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected
22
+ };
28
23
  }
29
24
  });
30
25
  });
@@ -14,7 +14,7 @@
14
14
  * collection to portions of your application while maintaining a central point
15
15
  * aware of changes to the entire data structure.
16
16
  *
17
- * This is particularly useful when used in conjuction with component-based UI
17
+ * This is particularly useful when used in conjunction with component-based UI
18
18
  * libraries like [React](http://facebook.github.io/react/) or to simulate
19
19
  * "state" throughout an application while maintaining a single flow of logic.
20
20
  *
@@ -32,259 +32,256 @@
32
32
  * update the rest of your application.
33
33
  */
34
34
 
35
- /// <reference path='../../dist/immutable.d.ts'/>
35
+ import * as Immutable from '../../';
36
+
37
+ export function from(
38
+ collection: Immutable.Collection<any, any>,
39
+ onChange?: (newValue: any, oldValue?: any, keyPath?: Array<any>) => any
40
+ ): Cursor;
41
+ export function from(
42
+ collection: Immutable.Collection<any, any>,
43
+ keyPath: Array<any>,
44
+ onChange?: (newValue: any, oldValue?: any, keyPath?: Array<any>) => any
45
+ ): Cursor;
46
+ export function from(
47
+ collection: Immutable.Collection<any, any>,
48
+ key: any,
49
+ onChange?: (newValue: any, oldValue?: any, keyPath?: Array<any>) => any
50
+ ): Cursor;
51
+
52
+
53
+ export interface Cursor extends Immutable.Iterable<any, any>, Immutable.Seq<any, any> {
54
+
55
+ /**
56
+ * Returns a sub-cursor following the key-path starting from this cursor.
57
+ */
58
+ cursor(subKeyPath: Array<any>): Cursor;
59
+ cursor(subKey: any): Cursor;
60
+
61
+ /**
62
+ * Returns the value at the cursor, if the cursor path does not yet exist,
63
+ * returns `notSetValue`.
64
+ */
65
+ deref(notSetValue?: any): any;
66
+
67
+ /**
68
+ * Returns the value at the `key` in the cursor, or `notSetValue` if it
69
+ * does not exist.
70
+ *
71
+ * If the key would return a collection, a new Cursor is returned.
72
+ */
73
+ get(key: any, notSetValue?: any): any;
74
+
75
+ /**
76
+ * Returns the value at the `keyPath` in the cursor, or `notSetValue` if it
77
+ * does not exist.
78
+ *
79
+ * If the keyPath would return a collection, a new Cursor is returned.
80
+ */
81
+ getIn(keyPath: Array<any>, notSetValue?: any): any;
82
+ getIn(keyPath: Immutable.Iterable<any, any>, notSetValue?: any): any;
83
+
84
+ /**
85
+ * Sets `value` at `key` in the cursor, returning a new cursor to the same
86
+ * point in the new data.
87
+ *
88
+ * If only one parameter is provided, it is set directly as the cursor's value.
89
+ */
90
+ set(key: any, value: any): Cursor;
91
+ set(value: any): Cursor;
92
+
93
+ /**
94
+ * Deletes `key` from the cursor, returning a new cursor to the same
95
+ * point in the new data.
96
+ *
97
+ * Note: `delete` cannot be safely used in IE8
98
+ * @alias remove
99
+ */
100
+ delete(key: any): Cursor;
101
+ remove(key: any): Cursor;
102
+
103
+ /**
104
+ * Clears the value at this cursor, returning a new cursor to the same
105
+ * point in the new data.
106
+ */
107
+ clear(): Cursor;
108
+
109
+ /**
110
+ * Updates the value in the data this cursor points to, triggering the
111
+ * callback for the root cursor and returning a new cursor pointing to the
112
+ * new data.
113
+ */
114
+ update(updater: (value: any) => any): Cursor;
115
+ update(key: any, updater: (value: any) => any): Cursor;
116
+ update(key: any, notSetValue: any, updater: (value: any) => any): Cursor;
117
+
118
+ /**
119
+ * @see `Map#merge`
120
+ */
121
+ merge(...iterables: Immutable.Iterable<any, any>[]): Cursor;
122
+ merge(...iterables: {[key: string]: any}[]): Cursor;
123
+
124
+ /**
125
+ * @see `Map#mergeWith`
126
+ */
127
+ mergeWith(
128
+ merger: (previous?: any, next?: any) => any,
129
+ ...iterables: Immutable.Iterable<any, any>[]
130
+ ): Cursor;
131
+ mergeWith(
132
+ merger: (previous?: any, next?: any) => any,
133
+ ...iterables: {[key: string]: any}[]
134
+ ): Cursor;
36
135
 
37
- declare module __Cursor {
136
+ /**
137
+ * @see `Map#mergeDeep`
138
+ */
139
+ mergeDeep(...iterables: Immutable.Iterable<any, any>[]): Cursor;
140
+ mergeDeep(...iterables: {[key: string]: any}[]): Cursor;
141
+
142
+ /**
143
+ * @see `Map#mergeDeepWith`
144
+ */
145
+ mergeDeepWith(
146
+ merger: (previous?: any, next?: any) => any,
147
+ ...iterables: Immutable.Iterable<any, any>[]
148
+ ): Cursor;
149
+ mergeDeepWith(
150
+ merger: (previous?: any, next?: any) => any,
151
+ ...iterables: {[key: string]: any}[]
152
+ ): Cursor;
38
153
 
39
- export function from(
40
- collection: Immutable.Collection<any, any>,
41
- onChange?: (newValue: any, oldValue?: any, keyPath?: Array<any>) => any
154
+ // Deep persistent changes
155
+
156
+ /**
157
+ * Returns a new Cursor having set `value` at this `keyPath`. If any keys in
158
+ * `keyPath` do not exist, a new immutable Map will be created at that key.
159
+ */
160
+ setIn(keyPath: Array<any>, value: any): Cursor;
161
+ setIn(keyPath: Immutable.Iterable<any, any>, value: any): Cursor;
162
+
163
+ /**
164
+ * Returns a new Cursor with provided `values` appended
165
+ */
166
+ push(...values: Array<any>): Cursor;
167
+
168
+ /**
169
+ * Returns a new Cursor with a size ones less than this Cursor,
170
+ * excluding the last index in this Cursor.
171
+ */
172
+ pop(): Cursor;
173
+
174
+ /**
175
+ * Returns a new Cursor with the provided `values` prepended,
176
+ * shifting other values ahead to higher indices.
177
+ */
178
+ unshift(...values: Array<any>): Cursor;
179
+
180
+ /**
181
+ * Returns a new Cursor with a size ones less than this Cursor, excluding
182
+ * the first index in this Cursor, shifting all other values to a lower index.
183
+ */
184
+ shift(): Cursor;
185
+
186
+ /**
187
+ * Returns a new Cursor having removed the value at this `keyPath`.
188
+ *
189
+ * @alias removeIn
190
+ */
191
+ deleteIn(keyPath: Array<any>): Cursor;
192
+ deleteIn(keyPath: Immutable.Iterable<any, any>): Cursor;
193
+ removeIn(keyPath: Array<any>): Cursor;
194
+ removeIn(keyPath: Immutable.Iterable<any, any>): Cursor;
195
+
196
+ /**
197
+ * Returns a new Cursor having applied the `updater` to the value found at
198
+ * the keyPath.
199
+ *
200
+ * If any keys in `keyPath` do not exist, new Immutable `Map`s will
201
+ * be created at those keys. If the `keyPath` does not already contain a
202
+ * value, the `updater` function will be called with `notSetValue`, if
203
+ * provided, otherwise `undefined`.
204
+ *
205
+ * If the `updater` function returns the same value it was called with, then
206
+ * no change will occur. This is still true if `notSetValue` is provided.
207
+ */
208
+ updateIn(
209
+ keyPath: Array<any>,
210
+ updater: (value: any) => any
42
211
  ): Cursor;
43
- export function from(
44
- collection: Immutable.Collection<any, any>,
212
+ updateIn(
45
213
  keyPath: Array<any>,
46
- onChange?: (newValue: any, oldValue?: any, keyPath?: Array<any>) => any
214
+ notSetValue: any,
215
+ updater: (value: any) => any
47
216
  ): Cursor;
48
- export function from(
49
- collection: Immutable.Collection<any, any>,
50
- key: any,
51
- onChange?: (newValue: any, oldValue?: any, keyPath?: Array<any>) => any
217
+ updateIn(
218
+ keyPath: Immutable.Iterable<any, any>,
219
+ updater: (value: any) => any
220
+ ): Cursor;
221
+ updateIn(
222
+ keyPath: Immutable.Iterable<any, any>,
223
+ notSetValue: any,
224
+ updater: (value: any) => any
52
225
  ): Cursor;
53
226
 
227
+ /**
228
+ * A combination of `updateIn` and `merge`, returning a new Cursor, but
229
+ * performing the merge at a point arrived at by following the keyPath.
230
+ * In other words, these two lines are equivalent:
231
+ *
232
+ * x.updateIn(['a', 'b', 'c'], abc => abc.merge(y));
233
+ * x.mergeIn(['a', 'b', 'c'], y);
234
+ *
235
+ */
236
+ mergeIn(
237
+ keyPath: Immutable.Iterable<any, any>,
238
+ ...iterables: Immutable.Iterable<any, any>[]
239
+ ): Cursor;
240
+ mergeIn(
241
+ keyPath: Array<any>,
242
+ ...iterables: Immutable.Iterable<any, any>[]
243
+ ): Cursor;
244
+ mergeIn(
245
+ keyPath: Array<any>,
246
+ ...iterables: {[key: string]: any}[]
247
+ ): Cursor;
54
248
 
55
- export interface Cursor extends Immutable.Seq<any, any> {
56
-
57
- /**
58
- * Returns a sub-cursor following the key-path starting from this cursor.
59
- */
60
- cursor(subKeyPath: Array<any>): Cursor;
61
- cursor(subKey: any): Cursor;
62
-
63
- /**
64
- * Returns the value at the cursor, if the cursor path does not yet exist,
65
- * returns `notSetValue`.
66
- */
67
- deref(notSetValue?: any): any;
68
-
69
- /**
70
- * Returns the value at the `key` in the cursor, or `notSetValue` if it
71
- * does not exist.
72
- *
73
- * If the key would return a collection, a new Cursor is returned.
74
- */
75
- get(key: any, notSetValue?: any): any;
76
-
77
- /**
78
- * Returns the value at the `keyPath` in the cursor, or `notSetValue` if it
79
- * does not exist.
80
- *
81
- * If the keyPath would return a collection, a new Cursor is returned.
82
- */
83
- getIn(keyPath: Array<any>, notSetValue?: any): any;
84
- getIn(keyPath: Immutable.Iterable<any, any>, notSetValue?: any): any;
85
-
86
- /**
87
- * Sets `value` at `key` in the cursor, returning a new cursor to the same
88
- * point in the new data.
89
- *
90
- * If only one parameter is provided, it is set directly as the cursor's value.
91
- */
92
- set(key: any, value: any): Cursor;
93
- set(value: any): Cursor;
94
-
95
- /**
96
- * Deletes `key` from the cursor, returning a new cursor to the same
97
- * point in the new data.
98
- *
99
- * Note: `delete` cannot be safely used in IE8
100
- * @alias remove
101
- */
102
- delete(key: any): Cursor;
103
- remove(key: any): Cursor;
104
-
105
- /**
106
- * Clears the value at this cursor, returning a new cursor to the same
107
- * point in the new data.
108
- */
109
- clear(): Cursor;
110
-
111
- /**
112
- * Updates the value in the data this cursor points to, triggering the
113
- * callback for the root cursor and returning a new cursor pointing to the
114
- * new data.
115
- */
116
- update(updater: (value: any) => any): Cursor;
117
- update(key: any, updater: (value: any) => any): Cursor;
118
- update(key: any, notSetValue: any, updater: (value: any) => any): Cursor;
119
-
120
- /**
121
- * @see `Map#merge`
122
- */
123
- merge(...iterables: Immutable.Iterable<any, any>[]): Cursor;
124
- merge(...iterables: {[key: string]: any}[]): Cursor;
125
-
126
- /**
127
- * @see `Map#mergeWith`
128
- */
129
- mergeWith(
130
- merger: (previous?: any, next?: any) => any,
131
- ...iterables: Immutable.Iterable<any, any>[]
132
- ): Cursor;
133
- mergeWith(
134
- merger: (previous?: any, next?: any) => any,
135
- ...iterables: {[key: string]: any}[]
136
- ): Cursor;
137
-
138
- /**
139
- * @see `Map#mergeDeep`
140
- */
141
- mergeDeep(...iterables: Immutable.Iterable<any, any>[]): Cursor;
142
- mergeDeep(...iterables: {[key: string]: any}[]): Cursor;
143
-
144
- /**
145
- * @see `Map#mergeDeepWith`
146
- */
147
- mergeDeepWith(
148
- merger: (previous?: any, next?: any) => any,
149
- ...iterables: Immutable.Iterable<any, any>[]
150
- ): Cursor;
151
- mergeDeepWith(
152
- merger: (previous?: any, next?: any) => any,
153
- ...iterables: {[key: string]: any}[]
154
- ): Cursor;
155
-
156
- // Deep persistent changes
157
-
158
- /**
159
- * Returns a new Cursor having set `value` at this `keyPath`. If any keys in
160
- * `keyPath` do not exist, a new immutable Map will be created at that key.
161
- */
162
- setIn(keyPath: Array<any>, value: any): Cursor;
163
- setIn(keyPath: Immutable.Iterable<any, any>, value: any): Cursor;
164
-
165
- /**
166
- * Returns a new Cursor with provided `values` appended
167
- */
168
- push(...values: Array<any>): Cursor;
169
-
170
- /**
171
- * Returns a new Cursor with a size ones less than this Cursor,
172
- * excluding the last index in this Cursor.
173
- */
174
- pop(): Cursor;
175
-
176
- /**
177
- * Returns a new Cursor with the provided `values` prepended,
178
- * shifting other values ahead to higher indices.
179
- */
180
- unshift(...values: Array<any>): Cursor;
181
-
182
- /**
183
- * Returns a new Cursor with a size ones less than this Cursor, excluding
184
- * the first index in this Cursor, shifting all other values to a lower index.
185
- */
186
- shift(): Cursor;
187
-
188
- /**
189
- * Returns a new Cursor having removed the value at this `keyPath`.
190
- *
191
- * @alias removeIn
192
- */
193
- deleteIn(keyPath: Array<any>): Cursor;
194
- deleteIn(keyPath: Immutable.Iterable<any, any>): Cursor;
195
- removeIn(keyPath: Array<any>): Cursor;
196
- removeIn(keyPath: Immutable.Iterable<any, any>): Cursor;
197
-
198
- /**
199
- * Returns a new Cursor having applied the `updater` to the value found at
200
- * the keyPath.
201
- *
202
- * If any keys in `keyPath` do not exist, new Immutable `Map`s will
203
- * be created at those keys. If the `keyPath` does not already contain a
204
- * value, the `updater` function will be called with `notSetValue`, if
205
- * provided, otherwise `undefined`.
206
- *
207
- * If the `updater` function returns the same value it was called with, then
208
- * no change will occur. This is still true if `notSetValue` is provided.
209
- */
210
- updateIn(
211
- keyPath: Array<any>,
212
- updater: (value: any) => any
213
- ): Cursor;
214
- updateIn(
215
- keyPath: Array<any>,
216
- notSetValue: any,
217
- updater: (value: any) => any
218
- ): Cursor;
219
- updateIn(
220
- keyPath: Immutable.Iterable<any, any>,
221
- updater: (value: any) => any
222
- ): Cursor;
223
- updateIn(
224
- keyPath: Immutable.Iterable<any, any>,
225
- notSetValue: any,
226
- updater: (value: any) => any
227
- ): Cursor;
228
-
229
- /**
230
- * A combination of `updateIn` and `merge`, returning a new Cursor, but
231
- * performing the merge at a point arrived at by following the keyPath.
232
- * In other words, these two lines are equivalent:
233
- *
234
- * x.updateIn(['a', 'b', 'c'], abc => abc.merge(y));
235
- * x.mergeIn(['a', 'b', 'c'], y);
236
- *
237
- */
238
- mergeIn(
239
- keyPath: Immutable.Iterable<any, any>,
240
- ...iterables: Immutable.Iterable<any, any>[]
241
- ): Cursor;
242
- mergeIn(
243
- keyPath: Array<any>,
244
- ...iterables: Immutable.Iterable<any, any>[]
245
- ): Cursor;
246
- mergeIn(
247
- keyPath: Array<any>,
248
- ...iterables: {[key: string]: any}[]
249
- ): Cursor;
250
-
251
- /**
252
- * A combination of `updateIn` and `mergeDeep`, returning a new Cursor, but
253
- * performing the deep merge at a point arrived at by following the keyPath.
254
- * In other words, these two lines are equivalent:
255
- *
256
- * x.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y));
257
- * x.mergeDeepIn(['a', 'b', 'c'], y);
258
- *
259
- */
260
- mergeDeepIn(
261
- keyPath: Immutable.Iterable<any, any>,
262
- ...iterables: Immutable.Iterable<any, any>[]
263
- ): Cursor;
264
- mergeDeepIn(
265
- keyPath: Array<any>,
266
- ...iterables: Immutable.Iterable<any, any>[]
267
- ): Cursor;
268
- mergeDeepIn(
269
- keyPath: Array<any>,
270
- ...iterables: {[key: string]: any}[]
271
- ): Cursor;
272
-
273
- // Transient changes
274
-
275
- /**
276
- * Every time you call one of the above functions, a new immutable value is
277
- * created and the callback is triggered. If you need to apply a series of
278
- * mutations to a Cursor without triggering the callback repeatedly,
279
- * `withMutations()` creates a temporary mutable copy of the value which
280
- * can apply mutations in a highly performant manner. Afterwards the
281
- * callback is triggered with the final value.
282
- */
283
- withMutations(mutator: (mutable: any) => any): Cursor;
284
- }
249
+ /**
250
+ * A combination of `updateIn` and `mergeDeep`, returning a new Cursor, but
251
+ * performing the deep merge at a point arrived at by following the keyPath.
252
+ * In other words, these two lines are equivalent:
253
+ *
254
+ * x.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y));
255
+ * x.mergeDeepIn(['a', 'b', 'c'], y);
256
+ *
257
+ */
258
+ mergeDeepIn(
259
+ keyPath: Immutable.Iterable<any, any>,
260
+ ...iterables: Immutable.Iterable<any, any>[]
261
+ ): Cursor;
262
+ mergeDeepIn(
263
+ keyPath: Array<any>,
264
+ ...iterables: Immutable.Iterable<any, any>[]
265
+ ): Cursor;
266
+ mergeDeepIn(
267
+ keyPath: Array<any>,
268
+ ...iterables: {[key: string]: any}[]
269
+ ): Cursor;
285
270
 
271
+ // Transient changes
272
+
273
+ /**
274
+ * Every time you call one of the above functions, a new immutable value is
275
+ * created and the callback is triggered. If you need to apply a series of
276
+ * mutations to a Cursor without triggering the callback repeatedly,
277
+ * `withMutations()` creates a temporary mutable copy of the value which
278
+ * can apply mutations in a highly performant manner. Afterwards the
279
+ * callback is triggered with the final value.
280
+ */
281
+ withMutations(mutator: (mutable: any) => any): Cursor;
282
+
283
+ /**
284
+ * @ignore
285
+ */
286
+ map(fn: (v: any, k: any, c: this) => any): this;
286
287
  }
287
-
288
- declare module 'immutable/contrib/cursor' {
289
- export = __Cursor
290
- }
@@ -5,6 +5,25 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ /**
9
+ * DEPRECATED
10
+ *
11
+ * The Cursor API is deprecated and will be removed in a future major release.
12
+ *
13
+ * It is strongly suggested that you use the excellent `immutable-cursor` module
14
+ * which has an extremely similar API but is much higher quality.
15
+ *
16
+ * https://github.com/redbadger/immutable-cursor
17
+ */
18
+ typeof console === 'object' && console.warn && console.warn(
19
+ 'The Cursor API is deprecated and will be removed in a future major release.\n' +
20
+ '\n' +
21
+ 'It is strongly suggested that you use the excellent `immutable-cursor` module\n' +
22
+ 'which has an extremely similar API but is much higher quality.\n' +
23
+ '\n' +
24
+ 'https://github.com/redbadger/immutable-cursor\n' +
25
+ );
26
+
8
27
  /**
9
28
  * Cursor is expected to be required in a node or other CommonJS context:
10
29
  *