immutable 3.7.5 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -26
- package/README.md +20 -10
- package/contrib/cursor/__tests__/{Cursor.ts → Cursor.ts.skip} +99 -90
- package/contrib/cursor/index.d.ts +9 -10
- package/contrib/cursor/index.js +4 -6
- package/dist/immutable-nonambient.d.ts +2533 -0
- package/dist/immutable.d.ts +547 -527
- package/dist/immutable.js +1914 -1897
- package/dist/immutable.js.flow +670 -0
- package/dist/immutable.min.js +31 -33
- package/package.json +60 -26
- package/PATENTS +0 -11
package/LICENSE
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2014-present, Facebook, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Neither the name Facebook nor the names of its contributors may be used to
|
|
18
|
-
endorse or promote products derived from this software without specific
|
|
19
|
-
prior written permission.
|
|
20
|
-
|
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
22
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
23
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
25
|
-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
26
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
27
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
28
|
-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
30
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -9,16 +9,21 @@ and change detection techniques with simple logic. [Persistent][] data presents
|
|
|
9
9
|
a mutative API which does not update the data in-place, but instead always
|
|
10
10
|
yields new updated data.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
`Set`, `OrderedSet` and `Record`.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
Immutable.js provides many Persistent Immutable data structures including:
|
|
13
|
+
`List`, `Stack`, `Map`, `OrderedMap`, `Set`, `OrderedSet` and `Record`.
|
|
14
|
+
|
|
15
|
+
These data structures are highly efficient on modern JavaScript VMs by using
|
|
16
|
+
structural sharing via [hash maps tries][] and [vector tries][] as popularized
|
|
17
|
+
by Clojure and Scala, minimizing the need to copy or cache data.
|
|
17
18
|
|
|
18
19
|
`Immutable` also provides a lazy `Seq`, allowing efficient
|
|
19
20
|
chaining of collection methods like `map` and `filter` without creating
|
|
20
21
|
intermediate representations. Create some `Seq` with `Range` and `Repeat`.
|
|
21
22
|
|
|
23
|
+
Want to hear more? Watch the presentation about Immutable.js:
|
|
24
|
+
|
|
25
|
+
<a href="https://youtu.be/I7IdS-PbEgI" target="_blank" alt="Immutable Data and React"><img src="https://img.youtube.com/vi/I7IdS-PbEgI/0.jpg" /></a>
|
|
26
|
+
|
|
22
27
|
[Persistent]: http://en.wikipedia.org/wiki/Persistent_data_structure
|
|
23
28
|
[Immutable]: http://en.wikipedia.org/wiki/Immutable_object
|
|
24
29
|
[hash maps tries]: http://en.wikipedia.org/wiki/Hash_array_mapped_trie
|
|
@@ -46,7 +51,7 @@ map2.get('b'); // 50
|
|
|
46
51
|
|
|
47
52
|
### Browser
|
|
48
53
|
|
|
49
|
-
To use `immutable` from a browser, download [dist/immutable.min.js](
|
|
54
|
+
To use `immutable` from a browser, download [dist/immutable.min.js](https://github.com/facebook/immutable-js/blob/master/dist/immutable.min.js)
|
|
50
55
|
or use a CDN such as [CDNJS](https://cdnjs.com/libraries/immutable)
|
|
51
56
|
or [jsDelivr](http://www.jsdelivr.com/#!immutable.js).
|
|
52
57
|
|
|
@@ -103,8 +108,7 @@ Much of what makes application development difficult is tracking mutation and
|
|
|
103
108
|
maintaining state. Developing with immutable data encourages you to think
|
|
104
109
|
differently about how data flows through your application.
|
|
105
110
|
|
|
106
|
-
Subscribing to data events throughout your application
|
|
107
|
-
`Object.observe`, or any other mechanism, creates a huge overhead of
|
|
111
|
+
Subscribing to data events throughout your application creates a huge overhead of
|
|
108
112
|
book-keeping which can hurt performance, sometimes dramatically, and creates
|
|
109
113
|
opportunities for areas of your application to get out of sync with each other
|
|
110
114
|
due to easy to make programmer error. Since immutable data never changes,
|
|
@@ -434,6 +438,12 @@ Also, don't miss the [Wiki](https://github.com/facebook/immutable-js/wiki) which
|
|
|
434
438
|
contains articles on specific topics. Can't find something? Open an [issue](https://github.com/facebook/immutable-js/issues).
|
|
435
439
|
|
|
436
440
|
|
|
441
|
+
Testing
|
|
442
|
+
-------
|
|
443
|
+
|
|
444
|
+
If you are using the [Chai Assertion Library](http://chaijs.com/), [Chai Immutable](https://github.com/astorije/chai-immutable) provides a set of assertions to use against `Immutable` collections.
|
|
445
|
+
|
|
446
|
+
|
|
437
447
|
Contribution
|
|
438
448
|
------------
|
|
439
449
|
|
|
@@ -455,10 +465,10 @@ Thanks
|
|
|
455
465
|
and research in persistent data structures.
|
|
456
466
|
|
|
457
467
|
[Hugh Jackson](https://github.com/hughfdjackson/), for providing the npm package
|
|
458
|
-
name. If you're looking for his unsupported package, see [
|
|
468
|
+
name. If you're looking for his unsupported package, see [this repository](https://github.com/hughfdjackson/immutable).
|
|
459
469
|
|
|
460
470
|
|
|
461
471
|
License
|
|
462
472
|
-------
|
|
463
473
|
|
|
464
|
-
|
|
474
|
+
Immutable.js is [MIT-licensed](https://github.com/facebook/immutable-js/blob/master/LICENSE).
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
///<reference path='../../../resources/jest.d.ts'/>
|
|
2
9
|
///<reference path='../../../dist/immutable.d.ts'/>
|
|
3
10
|
///<reference path='../index.d.ts'/>
|
|
@@ -7,14 +14,21 @@ jest.autoMockOff();
|
|
|
7
14
|
import Immutable = require('immutable');
|
|
8
15
|
import Cursor = require('immutable/contrib/cursor');
|
|
9
16
|
|
|
10
|
-
jasmine.getEnv().addEqualityTester((a, b) =>
|
|
11
|
-
a instanceof Immutable.Iterable && b instanceof Immutable.Iterable ?
|
|
12
|
-
Immutable.is(a, b) :
|
|
13
|
-
jasmine.undefined
|
|
14
|
-
);
|
|
15
|
-
|
|
16
17
|
describe('Cursor', () => {
|
|
17
18
|
|
|
19
|
+
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;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
18
32
|
var json = { a: { b: { c: 1 } } };
|
|
19
33
|
|
|
20
34
|
it('gets from its path', () => {
|
|
@@ -60,7 +74,7 @@ describe('Cursor', () => {
|
|
|
60
74
|
var data = Immutable.fromJS(json);
|
|
61
75
|
var cursor = Cursor.from(data, ['a', 'b']);
|
|
62
76
|
expect(cursor.toJS()).toEqual(json.a.b);
|
|
63
|
-
expect(cursor).
|
|
77
|
+
expect(cursor).toValueEqual(data.getIn(['a', 'b']));
|
|
64
78
|
expect(cursor.size).toBe(1);
|
|
65
79
|
expect(cursor.get('c')).toBe(1);
|
|
66
80
|
});
|
|
@@ -85,19 +99,17 @@ describe('Cursor', () => {
|
|
|
85
99
|
// cursor edits return new cursors:
|
|
86
100
|
var newDeepCursor = deepCursor.update(x => x + 1);
|
|
87
101
|
expect(newDeepCursor.deref()).toBe(2);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
);
|
|
102
|
+
var call1 = onChange.mock.calls[0];
|
|
103
|
+
expect(call1[0]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
104
|
+
expect(call1[1]).toBe(data);
|
|
105
|
+
expect(call1[2]).toEqual(['a', 'b', 'c']);
|
|
93
106
|
|
|
94
107
|
var newestDeepCursor = newDeepCursor.update(x => x + 1);
|
|
95
108
|
expect(newestDeepCursor.deref()).toBe(3);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
109
|
+
var call2 = onChange.mock.calls[1];
|
|
110
|
+
expect(call2[0]).toValueEqual(Immutable.fromJS({a:{b:{c:3}}}));
|
|
111
|
+
expect(call2[1]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
112
|
+
expect(call2[2]).toEqual(['a', 'b', 'c']);
|
|
101
113
|
|
|
102
114
|
// meanwhile, data is still immutable:
|
|
103
115
|
expect(data.toJS()).toEqual(json);
|
|
@@ -106,11 +118,10 @@ describe('Cursor', () => {
|
|
|
106
118
|
expect(deepCursor.deref()).toBe(1);
|
|
107
119
|
var otherNewDeepCursor = deepCursor.update(x => x + 10);
|
|
108
120
|
expect(otherNewDeepCursor.deref()).toBe(11);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
121
|
+
var call3 = onChange.mock.calls[2];
|
|
122
|
+
expect(call3[0]).toValueEqual(Immutable.fromJS({a:{b:{c:11}}}));
|
|
123
|
+
expect(call3[1]).toBe(data);
|
|
124
|
+
expect(call3[2]).toEqual(['a', 'b', 'c']);
|
|
114
125
|
|
|
115
126
|
// and update has been called exactly thrice.
|
|
116
127
|
expect(onChange.mock.calls.length).toBe(3);
|
|
@@ -126,21 +137,19 @@ describe('Cursor', () => {
|
|
|
126
137
|
// onChange returning undefined has no effect
|
|
127
138
|
var newCursor = deepCursor.update(x => x + 1);
|
|
128
139
|
expect(newCursor.deref()).toBe(2);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
140
|
+
var call1 = onChange.mock.calls[0];
|
|
141
|
+
expect(call1[0]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
142
|
+
expect(call1[1]).toBe(data);
|
|
143
|
+
expect(call1[2]).toEqual(['a', 'b', 'c']);
|
|
134
144
|
|
|
135
145
|
onChange.mockReturnValueOnce(Immutable.fromJS({a:{b:{c:11}}}));
|
|
136
146
|
// onChange returning something else has an effect
|
|
137
147
|
newCursor = newCursor.update(x => 999);
|
|
138
148
|
expect(newCursor.deref()).toBe(11);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
);
|
|
149
|
+
var call2 = onChange.mock.calls[1];
|
|
150
|
+
expect(call2[0]).toValueEqual(Immutable.fromJS({a:{b:{c:999}}}));
|
|
151
|
+
expect(call2[1]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
152
|
+
expect(call2[2]).toEqual(['a', 'b', 'c']);
|
|
144
153
|
|
|
145
154
|
// and update has been called exactly twice
|
|
146
155
|
expect(onChange.mock.calls.length).toBe(2);
|
|
@@ -154,14 +163,14 @@ describe('Cursor', () => {
|
|
|
154
163
|
var bCursor = aCursor.cursor('b');
|
|
155
164
|
var cCursor = bCursor.cursor('c');
|
|
156
165
|
|
|
157
|
-
expect(bCursor.set('c', 10).deref()).
|
|
166
|
+
expect(bCursor.set('c', 10).deref()).toValueEqual(
|
|
158
167
|
Immutable.fromJS({ c: 10 })
|
|
159
168
|
);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
169
|
+
|
|
170
|
+
var call1 = onChange.mock.calls[0];
|
|
171
|
+
expect(call1[0]).toValueEqual(Immutable.fromJS({a:{b:{c:10}}}));
|
|
172
|
+
expect(call1[1]).toBe(data);
|
|
173
|
+
expect(call1[2]).toEqual(['a', 'b', 'c']);
|
|
165
174
|
});
|
|
166
175
|
|
|
167
176
|
it('creates maps as necessary', () => {
|
|
@@ -169,7 +178,7 @@ describe('Cursor', () => {
|
|
|
169
178
|
var cursor = Cursor.from(data, ['a', 'b', 'c']);
|
|
170
179
|
expect(cursor.deref()).toBe(undefined);
|
|
171
180
|
cursor = cursor.set('d', 3);
|
|
172
|
-
expect(cursor.deref()).
|
|
181
|
+
expect(cursor.deref()).toValueEqual(Immutable.Map({d: 3}));
|
|
173
182
|
});
|
|
174
183
|
|
|
175
184
|
it('can set undefined', () => {
|
|
@@ -183,7 +192,7 @@ describe('Cursor', () => {
|
|
|
183
192
|
it('has the sequence API', () => {
|
|
184
193
|
var data = Immutable.Map({a: 1, b: 2, c: 3});
|
|
185
194
|
var cursor = Cursor.from(data);
|
|
186
|
-
expect(cursor.map((x: number) => x * x)).
|
|
195
|
+
expect(cursor.map((x: number) => x * x)).toValueEqual(Immutable.Map({a: 1, b: 4, c: 9}));
|
|
187
196
|
});
|
|
188
197
|
|
|
189
198
|
it('can push values on a List', () => {
|
|
@@ -191,12 +200,12 @@ describe('Cursor', () => {
|
|
|
191
200
|
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
192
201
|
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
193
202
|
|
|
194
|
-
expect(cursor.push(3,4)).
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
);
|
|
203
|
+
expect(cursor.push(3,4)).toValueEqual(Immutable.List([0, 1, 2, 3, 4]));
|
|
204
|
+
|
|
205
|
+
var call = onChange.mock.calls[0];
|
|
206
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [0, 1, 2, 3, 4]}}));
|
|
207
|
+
expect(call[1]).toBe(data);
|
|
208
|
+
expect(call[2]).toEqual(['a', 'b']);
|
|
200
209
|
});
|
|
201
210
|
|
|
202
211
|
it('can pop values of a List', () => {
|
|
@@ -204,12 +213,12 @@ describe('Cursor', () => {
|
|
|
204
213
|
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
205
214
|
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
206
215
|
|
|
207
|
-
expect(cursor.pop()).
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
);
|
|
216
|
+
expect(cursor.pop()).toValueEqual(Immutable.List([0, 1]));
|
|
217
|
+
|
|
218
|
+
var call = onChange.mock.calls[0];
|
|
219
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [0, 1]}}));
|
|
220
|
+
expect(call[1]).toBe(data);
|
|
221
|
+
expect(call[2]).toEqual(['a', 'b']);
|
|
213
222
|
});
|
|
214
223
|
|
|
215
224
|
it('can unshift values on a List', () => {
|
|
@@ -217,12 +226,12 @@ describe('Cursor', () => {
|
|
|
217
226
|
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
218
227
|
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
219
228
|
|
|
220
|
-
expect(cursor.unshift(-2, -1)).
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
);
|
|
229
|
+
expect(cursor.unshift(-2, -1)).toValueEqual(Immutable.List([-2, -1, 0, 1, 2]));
|
|
230
|
+
|
|
231
|
+
var call = onChange.mock.calls[0];
|
|
232
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [-2, -1, 0, 1, 2]}}));
|
|
233
|
+
expect(call[1]).toBe(data);
|
|
234
|
+
expect(call[2]).toEqual(['a', 'b']);
|
|
226
235
|
});
|
|
227
236
|
|
|
228
237
|
it('can shift values of a List', () => {
|
|
@@ -230,12 +239,12 @@ describe('Cursor', () => {
|
|
|
230
239
|
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
231
240
|
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
232
241
|
|
|
233
|
-
expect(cursor.shift()).
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
);
|
|
242
|
+
expect(cursor.shift()).toValueEqual(Immutable.List([1, 2]));
|
|
243
|
+
|
|
244
|
+
var call = onChange.mock.calls[0];
|
|
245
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [1, 2]}}));
|
|
246
|
+
expect(call[1]).toBe(data);
|
|
247
|
+
expect(call[2]).toEqual(['a', 'b']);
|
|
239
248
|
});
|
|
240
249
|
|
|
241
250
|
|
|
@@ -247,11 +256,11 @@ describe('Cursor', () => {
|
|
|
247
256
|
var found = cursor.find(map => map.get('v') === 2);
|
|
248
257
|
expect(typeof found.deref).toBe('function'); // is a cursor!
|
|
249
258
|
found = found.set('v', 20);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
);
|
|
259
|
+
|
|
260
|
+
var call = onChange.mock.calls[0];
|
|
261
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a: {v: 1}, b: {v: 20}, c: {v: 3}}));
|
|
262
|
+
expect(call[1]).toBe(data);
|
|
263
|
+
expect(call[2]).toEqual(['b', 'v']);
|
|
255
264
|
});
|
|
256
265
|
|
|
257
266
|
it('returns wrapped values for iteration API', () => {
|
|
@@ -309,7 +318,7 @@ describe('Cursor', () => {
|
|
|
309
318
|
var c2 = c1.withMutations(m => m.set('x', 1).set('y', 2).set('z', 3));
|
|
310
319
|
|
|
311
320
|
expect(c1.deref()).toEqual(undefined);
|
|
312
|
-
expect(c2.deref()).
|
|
321
|
+
expect(c2.deref()).toValueEqual(Immutable.fromJS(
|
|
313
322
|
{ x: 1, y: 2, z: 3 }
|
|
314
323
|
));
|
|
315
324
|
expect(onChange.mock.calls.length).toBe(1);
|
|
@@ -334,11 +343,11 @@ describe('Cursor', () => {
|
|
|
334
343
|
var c = Cursor.from(data, ['a'], onChange);
|
|
335
344
|
var c1 = c.updateIn(['b', 'c'], x => x * 10);
|
|
336
345
|
expect(c1.getIn(['b', 'c'])).toBe(10);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
);
|
|
346
|
+
|
|
347
|
+
var call = onChange.mock.calls[0];
|
|
348
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a:{b:{c:10}}}));
|
|
349
|
+
expect(call[1]).toBe(data);
|
|
350
|
+
expect(call[2]).toEqual(['a', 'b', 'c']);
|
|
342
351
|
});
|
|
343
352
|
|
|
344
353
|
it('can set deeply', () => {
|
|
@@ -347,11 +356,11 @@ describe('Cursor', () => {
|
|
|
347
356
|
var c = Cursor.from(data, ['a'], onChange);
|
|
348
357
|
var c1 = c.setIn(['b', 'c'], 10);
|
|
349
358
|
expect(c1.getIn(['b', 'c'])).toBe(10);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
);
|
|
359
|
+
|
|
360
|
+
var call = onChange.mock.calls[0];
|
|
361
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a:{b:{c:10}}}));
|
|
362
|
+
expect(call[1]).toBe(data);
|
|
363
|
+
expect(call[2]).toEqual(['a', 'b', 'c']);
|
|
355
364
|
});
|
|
356
365
|
|
|
357
366
|
it('can get Record value as a property', () => {
|
|
@@ -368,11 +377,11 @@ describe('Cursor', () => {
|
|
|
368
377
|
var c = Cursor.from(data, ['a'], onChange);
|
|
369
378
|
var c1 = c.set(2);
|
|
370
379
|
expect(c1.deref()).toBe(2);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
);
|
|
380
|
+
|
|
381
|
+
var call = onChange.mock.calls[0];
|
|
382
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a:2}));
|
|
383
|
+
expect(call[1]).toBe(data);
|
|
384
|
+
expect(call[2]).toEqual(['a']);
|
|
376
385
|
});
|
|
377
386
|
|
|
378
387
|
it('can set value of a cursor to undefined directly', () => {
|
|
@@ -381,11 +390,11 @@ describe('Cursor', () => {
|
|
|
381
390
|
var c = Cursor.from(data, ['a'], onChange);
|
|
382
391
|
var c1 = c.set(undefined);
|
|
383
392
|
expect(c1.deref()).toBe(undefined);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
393
|
+
|
|
394
|
+
var call = onChange.mock.calls[0];
|
|
395
|
+
expect(call[0]).toValueEqual(Immutable.fromJS({a:undefined}));
|
|
396
|
+
expect(call[1]).toBe(data);
|
|
397
|
+
expect(call[2]).toEqual(['a']);
|
|
389
398
|
});
|
|
390
399
|
|
|
391
400
|
});
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* All rights reserved.
|
|
2
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
|
-
|
|
11
8
|
/**
|
|
12
9
|
* Cursors
|
|
13
10
|
* -------
|
|
@@ -35,11 +32,9 @@
|
|
|
35
32
|
* update the rest of your application.
|
|
36
33
|
*/
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
///<reference path='../../dist/immutable.d.ts'/>
|
|
41
|
-
import Immutable = require('immutable');
|
|
35
|
+
/// <reference path='../../dist/immutable.d.ts'/>
|
|
42
36
|
|
|
37
|
+
declare module __Cursor {
|
|
43
38
|
|
|
44
39
|
export function from(
|
|
45
40
|
collection: Immutable.Collection<any, any>,
|
|
@@ -289,3 +284,7 @@ declare module 'immutable/contrib/cursor' {
|
|
|
289
284
|
}
|
|
290
285
|
|
|
291
286
|
}
|
|
287
|
+
|
|
288
|
+
declare module 'immutable/contrib/cursor' {
|
|
289
|
+
export = __Cursor
|
|
290
|
+
}
|
package/contrib/cursor/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* All rights reserved.
|
|
2
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
/**
|
|
@@ -15,7 +13,7 @@
|
|
|
15
13
|
* If you wish to use it in the browser, please check out Browserify or WebPack!
|
|
16
14
|
*/
|
|
17
15
|
|
|
18
|
-
var Immutable = require('
|
|
16
|
+
var Immutable = require('../../');
|
|
19
17
|
var Iterable = Immutable.Iterable;
|
|
20
18
|
var Iterator = Iterable.Iterator;
|
|
21
19
|
var Seq = Immutable.Seq;
|