immutable 4.0.0-rc.1 → 4.0.0-rc.14
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 +409 -224
- package/dist/immutable-nonambient.d.ts +2583 -814
- package/dist/immutable.d.ts +2585 -816
- package/dist/immutable.es.js +5893 -0
- package/dist/immutable.js +5242 -4815
- package/dist/immutable.js.flow +1415 -230
- package/dist/immutable.min.js +53 -37
- package/package.json +9 -90
- package/PATENTS +0 -11
- package/contrib/cursor/README.md +0 -43
- package/contrib/cursor/__tests__/Cursor.ts.skip +0 -388
- package/contrib/cursor/index.d.ts +0 -290
- package/contrib/cursor/index.js +0 -362
package/package.json
CHANGED
|
@@ -1,110 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "immutable",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.14",
|
|
4
4
|
"description": "Immutable Data Collections",
|
|
5
|
-
"
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://immutable-js.com",
|
|
6
7
|
"author": {
|
|
7
8
|
"name": "Lee Byron",
|
|
8
9
|
"url": "https://github.com/leebyron"
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
|
-
"url": "git://github.com/
|
|
13
|
+
"url": "git://github.com/immutable-js/immutable-js.git"
|
|
13
14
|
},
|
|
14
15
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/immutable-js/immutable-js/issues"
|
|
16
17
|
},
|
|
17
18
|
"main": "dist/immutable.js",
|
|
19
|
+
"module": "dist/immutable.es.js",
|
|
18
20
|
"typings": "dist/immutable-nonambient.d.ts",
|
|
19
21
|
"typescript": {
|
|
20
22
|
"definition": "dist/immutable.d.ts"
|
|
21
23
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "run-s build:*",
|
|
24
|
-
"build:dist": "run-s clean:dist bundle:dist copy:dist stats:dist",
|
|
25
|
-
"build:pages": "gulp --gulpfile gulpfile.js default",
|
|
26
|
-
"stats:dist": "node ./resources/dist-stats.js",
|
|
27
|
-
"clean:dist": "rimraf dist",
|
|
28
|
-
"bundle:dist": "rollup -c ./resources/rollup-config.js",
|
|
29
|
-
"copy:dist": "node ./resources/copy-dist-typedefs.js",
|
|
30
|
-
"lint": "run-s lint:*",
|
|
31
|
-
"lint:ts": "tslint \"__tests__/**/*.ts\"",
|
|
32
|
-
"lint:js": "eslint \"{__tests__,src,pages/src,pages/lib}/**/*.js\"",
|
|
33
|
-
"format": "prettier --single-quote --write \"{__tests__,src,pages/src,pages/lib}/**/*.js\"",
|
|
34
|
-
"testonly": "./resources/jest",
|
|
35
|
-
"test": "run-s format build lint testonly type-check",
|
|
36
|
-
"test:travis": "npm run test && ./resources/check-changes",
|
|
37
|
-
"type-check": "cd type-definitions/tests && flow check",
|
|
38
|
-
"perf": "node ./resources/bench.js",
|
|
39
|
-
"start": "gulp --gulpfile gulpfile.js dev",
|
|
40
|
-
"deploy": "(cd ./pages/out && git init && git config user.name \"Travis CI\" && git config user.email \"github@fb.com\" && git add . && git commit -m \"Deploy to GitHub Pages\" && git push --force --quiet \"https://${GH_TOKEN}@github.com/facebook/immutable-js.git\" master:gh-pages > /dev/null 2>1)"
|
|
41
|
-
},
|
|
42
|
-
"jest": {
|
|
43
|
-
"moduleFileExtensions": [
|
|
44
|
-
"js",
|
|
45
|
-
"ts"
|
|
46
|
-
],
|
|
47
|
-
"transform": {
|
|
48
|
-
"^.+\\.ts$": "<rootDir>/resources/jestPreprocessor.js"
|
|
49
|
-
},
|
|
50
|
-
"testRegex": "/__tests__/.*\\.(ts|js)$",
|
|
51
|
-
"unmockedModulePathPatterns": [
|
|
52
|
-
"./node_modules/react"
|
|
53
|
-
]
|
|
54
|
-
},
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"benchmark": "2.1.3",
|
|
57
|
-
"browser-sync": "2.18.8",
|
|
58
|
-
"browserify": "^5.11.2",
|
|
59
|
-
"colors": "1.1.2",
|
|
60
|
-
"del": "2.2.2",
|
|
61
|
-
"eslint": "3.17.1",
|
|
62
|
-
"eslint-config-airbnb": "14.1.0",
|
|
63
|
-
"eslint-config-prettier": "1.5.0",
|
|
64
|
-
"eslint-plugin-import": "2.2.0",
|
|
65
|
-
"eslint-plugin-jsx-a11y": "4.0.0",
|
|
66
|
-
"eslint-plugin-prettier": "2.0.1",
|
|
67
|
-
"eslint-plugin-react": "6.10.0",
|
|
68
|
-
"flow-bin": "0.41.0",
|
|
69
|
-
"gulp": "3.9.1",
|
|
70
|
-
"gulp-concat": "2.6.1",
|
|
71
|
-
"gulp-filter": "5.0.0",
|
|
72
|
-
"gulp-header": "1.8.8",
|
|
73
|
-
"gulp-less": "3.3.0",
|
|
74
|
-
"gulp-size": "2.1.0",
|
|
75
|
-
"gulp-sourcemaps": "2.4.1",
|
|
76
|
-
"gulp-uglify": "2.1.0",
|
|
77
|
-
"gulp-util": "3.0.8",
|
|
78
|
-
"jasmine-check": "0.1.5",
|
|
79
|
-
"jest": "19.0.2",
|
|
80
|
-
"marked": "0.3.6",
|
|
81
|
-
"microtime": "^2.1.2",
|
|
82
|
-
"mkdirp": "0.5.1",
|
|
83
|
-
"npm-run-all": "4.0.2",
|
|
84
|
-
"prettier": "0.22.0",
|
|
85
|
-
"react": "^0.12.0",
|
|
86
|
-
"react-router": "^0.11.2",
|
|
87
|
-
"react-tools": "^0.12.0",
|
|
88
|
-
"rimraf": "2.6.1",
|
|
89
|
-
"rollup": "0.41.5",
|
|
90
|
-
"rollup-plugin-buble": "0.15.0",
|
|
91
|
-
"rollup-plugin-commonjs": "7.1.0",
|
|
92
|
-
"rollup-plugin-strip-banner": "0.1.0",
|
|
93
|
-
"run-sequence": "1.2.2",
|
|
94
|
-
"through2": "2.0.3",
|
|
95
|
-
"tslint": "4.5.1",
|
|
96
|
-
"typescript": "2.2.1",
|
|
97
|
-
"uglify-js": "2.8.11",
|
|
98
|
-
"uglify-save-license": "0.4.1",
|
|
99
|
-
"vinyl-buffer": "1.0.0",
|
|
100
|
-
"vinyl-source-stream": "1.1.0"
|
|
101
|
-
},
|
|
102
24
|
"files": [
|
|
103
25
|
"dist",
|
|
104
|
-
"contrib",
|
|
105
26
|
"README.md",
|
|
106
|
-
"LICENSE"
|
|
107
|
-
"PATENTS"
|
|
27
|
+
"LICENSE"
|
|
108
28
|
],
|
|
109
29
|
"keywords": [
|
|
110
30
|
"immutable",
|
|
@@ -117,6 +37,5 @@
|
|
|
117
37
|
"stateless",
|
|
118
38
|
"sequence",
|
|
119
39
|
"iteration"
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
}
|
|
40
|
+
]
|
|
41
|
+
}
|
package/PATENTS
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Additional Grant of Patent Rights Version 2
|
|
2
|
-
|
|
3
|
-
"Software" means the Immutable JS software distributed by Facebook, Inc.
|
|
4
|
-
|
|
5
|
-
Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software (“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (subject to the termination provision below) license under any Necessary Claims, to make, have made, use, sell, offer to sell, import, and otherwise transfer the Software. For avoidance of doubt, no license is granted under Facebook’s rights in any patent claims that are infringed by (i) modifications to the Software made by you or any third party or (ii) the Software in combination with any software or other technology.
|
|
6
|
-
|
|
7
|
-
The license granted hereunder will terminate, automatically and without notice, if you (or any of your subsidiaries, corporate affiliates or agents) initiate directly or indirectly, or take a direct financial interest in, any Patent Assertion: (i) against Facebook or any of its subsidiaries or corporate affiliates, (ii) against any party if such Patent Assertion arises in whole or in part from any software, technology, product or service of Facebook or any of its subsidiaries or corporate affiliates, or (iii) against any party relating to the Software. Notwithstanding the foregoing, if Facebook or any of its subsidiaries or corporate affiliates files a lawsuit alleging patent infringement against you in the first instance, and you respond by filing a patent infringement counterclaim in that lawsuit against that party that is unrelated to the Software, the license granted hereunder will not terminate under section (i) of this paragraph due to such counterclaim.
|
|
8
|
-
|
|
9
|
-
A “Necessary Claim” is a claim of a patent owned by Facebook that is necessarily infringed by the Software standing alone.
|
|
10
|
-
|
|
11
|
-
A “Patent Assertion” is any lawsuit or other action alleging direct, indirect, or contributory infringement or inducement to infringe any patent, including a cross-claim or counterclaim.
|
package/contrib/cursor/README.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
|
|
11
|
-
Cursors
|
|
12
|
-
-------
|
|
13
|
-
|
|
14
|
-
Cursors allow you to hold a reference to a path in a nested immutable data
|
|
15
|
-
structure, allowing you to pass smaller sections of a larger nested
|
|
16
|
-
collection to portions of your application while maintaining a central point
|
|
17
|
-
aware of changes to the entire data structure: an `onChange` function which is
|
|
18
|
-
called whenever a cursor or sub-cursor calls `update`.
|
|
19
|
-
|
|
20
|
-
This is particularly useful when used in conjuction with component-based UI
|
|
21
|
-
libraries like [React](https://facebook.github.io/react/) or to simulate
|
|
22
|
-
"state" throughout an application while maintaining a single flow of logic.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```javascript
|
|
26
|
-
var Immutable = require('immutable');
|
|
27
|
-
var Cursor = require('immutable/contrib/cursor');
|
|
28
|
-
|
|
29
|
-
var data = Immutable.fromJS({ a: { b: { c: 1 } } });
|
|
30
|
-
var cursor = Cursor.from(data, ['a', 'b'], newData => {
|
|
31
|
-
data = newData;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// ... elsewhere ...
|
|
35
|
-
|
|
36
|
-
cursor.get('c'); // 1
|
|
37
|
-
cursor = cursor.update('c', x => x + 1);
|
|
38
|
-
cursor.get('c'); // 2
|
|
39
|
-
|
|
40
|
-
// ... back to data ...
|
|
41
|
-
|
|
42
|
-
data.getIn(['a', 'b', 'c']); // 2
|
|
43
|
-
```
|
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
///<reference path='../../../resources/jest.d.ts'/>
|
|
2
|
-
|
|
3
|
-
import * as Immutable from '../../../';
|
|
4
|
-
import * as Cursor from '../';
|
|
5
|
-
|
|
6
|
-
describe('Cursor', () => {
|
|
7
|
-
|
|
8
|
-
beforeEach(function () {
|
|
9
|
-
jasmine.addMatchers({
|
|
10
|
-
toValueEqual: function(actual, expected) {
|
|
11
|
-
var passed = Immutable.is(actual, expected);
|
|
12
|
-
return {
|
|
13
|
-
pass: passed,
|
|
14
|
-
message: 'Expected ' + actual + (passed ? '' : ' not') + ' to equal ' + expected
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var json = { a: { b: { c: 1 } } };
|
|
21
|
-
|
|
22
|
-
it('gets from its path', () => {
|
|
23
|
-
var data = Immutable.fromJS(json);
|
|
24
|
-
var cursor = Cursor.from(data);
|
|
25
|
-
|
|
26
|
-
expect(cursor.deref()).toBe(data);
|
|
27
|
-
|
|
28
|
-
var deepCursor = cursor.cursor(['a', 'b']);
|
|
29
|
-
expect(deepCursor.deref().toJS()).toEqual(json.a.b);
|
|
30
|
-
expect(deepCursor.deref()).toBe(data.getIn(['a', 'b']));
|
|
31
|
-
expect(deepCursor.get('c')).toBe(1);
|
|
32
|
-
|
|
33
|
-
var leafCursor = deepCursor.cursor('c');
|
|
34
|
-
expect(leafCursor.deref()).toBe(1);
|
|
35
|
-
|
|
36
|
-
var missCursor = leafCursor.cursor('d');
|
|
37
|
-
expect(missCursor.deref()).toBe(undefined);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('gets return new cursors', () => {
|
|
41
|
-
var data = Immutable.fromJS(json);
|
|
42
|
-
var cursor = Cursor.from(data);
|
|
43
|
-
var deepCursor = cursor.getIn(['a', 'b']);
|
|
44
|
-
expect(deepCursor.deref()).toBe(data.getIn(['a', 'b']));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('gets return new cursors using List', () => {
|
|
48
|
-
var data = Immutable.fromJS(json);
|
|
49
|
-
var cursor = Cursor.from(data);
|
|
50
|
-
var deepCursor = cursor.getIn(Immutable.fromJS(['a', 'b']));
|
|
51
|
-
expect(deepCursor.deref()).toBe(data.getIn(Immutable.fromJS(['a', 'b'])));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('cursor return new cursors of correct type', () => {
|
|
55
|
-
var data = Immutable.fromJS({ a: [1, 2, 3] });
|
|
56
|
-
var cursor = Cursor.from(data);
|
|
57
|
-
var deepCursor = <any>cursor.cursor('a');
|
|
58
|
-
expect(deepCursor.findIndex).toBeDefined();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('can be treated as a value', () => {
|
|
62
|
-
var data = Immutable.fromJS(json);
|
|
63
|
-
var cursor = Cursor.from(data, ['a', 'b']);
|
|
64
|
-
expect(cursor.toJS()).toEqual(json.a.b);
|
|
65
|
-
expect(cursor).toValueEqual(data.getIn(['a', 'b']));
|
|
66
|
-
expect(cursor.size).toBe(1);
|
|
67
|
-
expect(cursor.get('c')).toBe(1);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('can be value compared to a primitive', () => {
|
|
71
|
-
var data = Immutable.Map({ a: 'A' });
|
|
72
|
-
var aCursor = Cursor.from(data, 'a');
|
|
73
|
-
expect(aCursor.size).toBe(undefined);
|
|
74
|
-
expect(aCursor.deref()).toBe('A');
|
|
75
|
-
expect(Immutable.is(aCursor, 'A')).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('updates at its path', () => {
|
|
79
|
-
var onChange = jest.genMockFunction();
|
|
80
|
-
|
|
81
|
-
var data = Immutable.fromJS(json);
|
|
82
|
-
var aCursor = Cursor.from(data, 'a', onChange);
|
|
83
|
-
|
|
84
|
-
var deepCursor = aCursor.cursor(['b', 'c']);
|
|
85
|
-
expect(deepCursor.deref()).toBe(1);
|
|
86
|
-
|
|
87
|
-
// cursor edits return new cursors:
|
|
88
|
-
var newDeepCursor = deepCursor.update(x => x + 1);
|
|
89
|
-
expect(newDeepCursor.deref()).toBe(2);
|
|
90
|
-
var call1 = onChange.mock.calls[0];
|
|
91
|
-
expect(call1[0]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
92
|
-
expect(call1[1]).toBe(data);
|
|
93
|
-
expect(call1[2]).toEqual(['a', 'b', 'c']);
|
|
94
|
-
|
|
95
|
-
var newestDeepCursor = newDeepCursor.update(x => x + 1);
|
|
96
|
-
expect(newestDeepCursor.deref()).toBe(3);
|
|
97
|
-
var call2 = onChange.mock.calls[1];
|
|
98
|
-
expect(call2[0]).toValueEqual(Immutable.fromJS({a:{b:{c:3}}}));
|
|
99
|
-
expect(call2[1]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
100
|
-
expect(call2[2]).toEqual(['a', 'b', 'c']);
|
|
101
|
-
|
|
102
|
-
// meanwhile, data is still immutable:
|
|
103
|
-
expect(data.toJS()).toEqual(json);
|
|
104
|
-
|
|
105
|
-
// as is the original cursor.
|
|
106
|
-
expect(deepCursor.deref()).toBe(1);
|
|
107
|
-
var otherNewDeepCursor = deepCursor.update(x => x + 10);
|
|
108
|
-
expect(otherNewDeepCursor.deref()).toBe(11);
|
|
109
|
-
var call3 = onChange.mock.calls[2];
|
|
110
|
-
expect(call3[0]).toValueEqual(Immutable.fromJS({a:{b:{c:11}}}));
|
|
111
|
-
expect(call3[1]).toBe(data);
|
|
112
|
-
expect(call3[2]).toEqual(['a', 'b', 'c']);
|
|
113
|
-
|
|
114
|
-
// and update has been called exactly thrice.
|
|
115
|
-
expect(onChange.mock.calls.length).toBe(3);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('updates with the return value of onChange', () => {
|
|
119
|
-
var onChange = jest.genMockFunction();
|
|
120
|
-
|
|
121
|
-
var data = Immutable.fromJS(json);
|
|
122
|
-
var deepCursor = Cursor.from(data, ['a', 'b', 'c'], onChange);
|
|
123
|
-
|
|
124
|
-
onChange.mockReturnValueOnce(undefined);
|
|
125
|
-
// onChange returning undefined has no effect
|
|
126
|
-
var newCursor = deepCursor.update(x => x + 1);
|
|
127
|
-
expect(newCursor.deref()).toBe(2);
|
|
128
|
-
var call1 = onChange.mock.calls[0];
|
|
129
|
-
expect(call1[0]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
130
|
-
expect(call1[1]).toBe(data);
|
|
131
|
-
expect(call1[2]).toEqual(['a', 'b', 'c']);
|
|
132
|
-
|
|
133
|
-
onChange.mockReturnValueOnce(Immutable.fromJS({a:{b:{c:11}}}));
|
|
134
|
-
// onChange returning something else has an effect
|
|
135
|
-
newCursor = newCursor.update(x => 999);
|
|
136
|
-
expect(newCursor.deref()).toBe(11);
|
|
137
|
-
var call2 = onChange.mock.calls[1];
|
|
138
|
-
expect(call2[0]).toValueEqual(Immutable.fromJS({a:{b:{c:999}}}));
|
|
139
|
-
expect(call2[1]).toValueEqual(Immutable.fromJS({a:{b:{c:2}}}));
|
|
140
|
-
expect(call2[2]).toEqual(['a', 'b', 'c']);
|
|
141
|
-
|
|
142
|
-
// and update has been called exactly twice
|
|
143
|
-
expect(onChange.mock.calls.length).toBe(2);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('has map API for update shorthand', () => {
|
|
147
|
-
var onChange = jest.genMockFunction();
|
|
148
|
-
|
|
149
|
-
var data = Immutable.fromJS(json);
|
|
150
|
-
var aCursor = Cursor.from(data, 'a', onChange);
|
|
151
|
-
var bCursor = aCursor.cursor('b');
|
|
152
|
-
var cCursor = bCursor.cursor('c');
|
|
153
|
-
|
|
154
|
-
expect(bCursor.set('c', 10).deref()).toValueEqual(
|
|
155
|
-
Immutable.fromJS({ c: 10 })
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
var call1 = onChange.mock.calls[0];
|
|
159
|
-
expect(call1[0]).toValueEqual(Immutable.fromJS({a:{b:{c:10}}}));
|
|
160
|
-
expect(call1[1]).toBe(data);
|
|
161
|
-
expect(call1[2]).toEqual(['a', 'b', 'c']);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('creates maps as necessary', () => {
|
|
165
|
-
var data = Immutable.Map();
|
|
166
|
-
var cursor = Cursor.from(data, ['a', 'b', 'c']);
|
|
167
|
-
expect(cursor.deref()).toBe(undefined);
|
|
168
|
-
cursor = cursor.set('d', 3);
|
|
169
|
-
expect(cursor.deref()).toValueEqual(Immutable.Map({d: 3}));
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('can set undefined', () => {
|
|
173
|
-
var data = Immutable.Map();
|
|
174
|
-
var cursor = Cursor.from(data, ['a', 'b', 'c']);
|
|
175
|
-
expect(cursor.deref()).toBe(undefined);
|
|
176
|
-
cursor = cursor.set('d', undefined);
|
|
177
|
-
expect(cursor.toJS()).toEqual({d: undefined});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('has the sequence API', () => {
|
|
181
|
-
var data = Immutable.Map({a: 1, b: 2, c: 3});
|
|
182
|
-
var cursor = Cursor.from(data);
|
|
183
|
-
expect(cursor.map((x: number) => x * x)).toValueEqual(Immutable.Map({a: 1, b: 4, c: 9}));
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('can push values on a List', () => {
|
|
187
|
-
var onChange = jest.genMockFunction();
|
|
188
|
-
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
189
|
-
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
190
|
-
|
|
191
|
-
expect(cursor.push(3,4)).toValueEqual(Immutable.List([0, 1, 2, 3, 4]));
|
|
192
|
-
|
|
193
|
-
var call = onChange.mock.calls[0];
|
|
194
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [0, 1, 2, 3, 4]}}));
|
|
195
|
-
expect(call[1]).toBe(data);
|
|
196
|
-
expect(call[2]).toEqual(['a', 'b']);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('can pop values of a List', () => {
|
|
200
|
-
var onChange = jest.genMockFunction();
|
|
201
|
-
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
202
|
-
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
203
|
-
|
|
204
|
-
expect(cursor.pop()).toValueEqual(Immutable.List([0, 1]));
|
|
205
|
-
|
|
206
|
-
var call = onChange.mock.calls[0];
|
|
207
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [0, 1]}}));
|
|
208
|
-
expect(call[1]).toBe(data);
|
|
209
|
-
expect(call[2]).toEqual(['a', 'b']);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('can unshift values on a List', () => {
|
|
213
|
-
var onChange = jest.genMockFunction();
|
|
214
|
-
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
215
|
-
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
216
|
-
|
|
217
|
-
expect(cursor.unshift(-2, -1)).toValueEqual(Immutable.List([-2, -1, 0, 1, 2]));
|
|
218
|
-
|
|
219
|
-
var call = onChange.mock.calls[0];
|
|
220
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [-2, -1, 0, 1, 2]}}));
|
|
221
|
-
expect(call[1]).toBe(data);
|
|
222
|
-
expect(call[2]).toEqual(['a', 'b']);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('can shift values of a List', () => {
|
|
226
|
-
var onChange = jest.genMockFunction();
|
|
227
|
-
var data = Immutable.fromJS({a: {b: [0, 1, 2]}});
|
|
228
|
-
var cursor = Cursor.from(data, ['a', 'b'], onChange);
|
|
229
|
-
|
|
230
|
-
expect(cursor.shift()).toValueEqual(Immutable.List([1, 2]));
|
|
231
|
-
|
|
232
|
-
var call = onChange.mock.calls[0];
|
|
233
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a: {b: [1, 2]}}));
|
|
234
|
-
expect(call[1]).toBe(data);
|
|
235
|
-
expect(call[2]).toEqual(['a', 'b']);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
it('returns wrapped values for sequence API', () => {
|
|
240
|
-
var data = Immutable.fromJS({a: {v: 1}, b: {v: 2}, c: {v: 3}});
|
|
241
|
-
var onChange = jest.genMockFunction();
|
|
242
|
-
var cursor = Cursor.from(data, onChange);
|
|
243
|
-
|
|
244
|
-
var found = cursor.find(map => map.get('v') === 2);
|
|
245
|
-
expect(typeof found.deref).toBe('function'); // is a cursor!
|
|
246
|
-
found = found.set('v', 20);
|
|
247
|
-
|
|
248
|
-
var call = onChange.mock.calls[0];
|
|
249
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a: {v: 1}, b: {v: 20}, c: {v: 3}}));
|
|
250
|
-
expect(call[1]).toBe(data);
|
|
251
|
-
expect(call[2]).toEqual(['b', 'v']);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('returns wrapped values for iteration API', () => {
|
|
255
|
-
var jsData = [{val: 0}, {val: 1}, {val: 2}];
|
|
256
|
-
var data = Immutable.fromJS(jsData);
|
|
257
|
-
var cursor = Cursor.from(data);
|
|
258
|
-
cursor.forEach(function (c, i) {
|
|
259
|
-
expect(typeof c.deref).toBe('function'); // is a cursor!
|
|
260
|
-
expect(c.get('val')).toBe(i);
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('can map over values to get subcursors', () => {
|
|
265
|
-
var data = Immutable.fromJS({a: {v: 1}, b: {v: 2}, c: {v: 3}});
|
|
266
|
-
var cursor = Cursor.from(data);
|
|
267
|
-
|
|
268
|
-
var mapped = cursor.map(val => {
|
|
269
|
-
expect(typeof val.deref).toBe('function'); // mapped values are cursors.
|
|
270
|
-
return val;
|
|
271
|
-
}).toMap();
|
|
272
|
-
// Mapped is not a cursor, but it is a sequence of cursors.
|
|
273
|
-
expect(typeof (<any>mapped).deref).not.toBe('function');
|
|
274
|
-
expect(typeof (<any>mapped.get('a')).deref).toBe('function');
|
|
275
|
-
|
|
276
|
-
// Same for indexed cursors
|
|
277
|
-
var data2 = Immutable.fromJS({x: [{v: 1}, {v: 2}, {v: 3}]});
|
|
278
|
-
var cursor2 = Cursor.from(data2);
|
|
279
|
-
|
|
280
|
-
var mapped2 = cursor2.get('x').map(val => {
|
|
281
|
-
expect(typeof val.deref).toBe('function'); // mapped values are cursors.
|
|
282
|
-
return val;
|
|
283
|
-
}).toList();
|
|
284
|
-
// Mapped is not a cursor, but it is a sequence of cursors.
|
|
285
|
-
expect(typeof mapped2.deref).not.toBe('function');
|
|
286
|
-
expect(typeof mapped2.get(0).deref).toBe('function');
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('can have mutations apply with a single callback', () => {
|
|
290
|
-
var onChange = jest.genMockFunction();
|
|
291
|
-
var data = Immutable.fromJS({'a': 1});
|
|
292
|
-
|
|
293
|
-
var c1 = Cursor.from(data, onChange);
|
|
294
|
-
var c2 = c1.withMutations(m => m.set('b', 2).set('c', 3).set('d', 4));
|
|
295
|
-
|
|
296
|
-
expect(c1.deref().toObject()).toEqual({'a': 1});
|
|
297
|
-
expect(c2.deref().toObject()).toEqual({'a': 1, 'b': 2, 'c': 3, 'd': 4});
|
|
298
|
-
expect(onChange.mock.calls.length).toBe(1);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it('can use withMutations on an unfulfilled cursor', () => {
|
|
302
|
-
var onChange = jest.genMockFunction();
|
|
303
|
-
var data = Immutable.fromJS({});
|
|
304
|
-
|
|
305
|
-
var c1 = Cursor.from(data, ['a', 'b', 'c'], onChange);
|
|
306
|
-
var c2 = c1.withMutations(m => m.set('x', 1).set('y', 2).set('z', 3));
|
|
307
|
-
|
|
308
|
-
expect(c1.deref()).toEqual(undefined);
|
|
309
|
-
expect(c2.deref()).toValueEqual(Immutable.fromJS(
|
|
310
|
-
{ x: 1, y: 2, z: 3 }
|
|
311
|
-
));
|
|
312
|
-
expect(onChange.mock.calls.length).toBe(1);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('maintains indexed sequences', () => {
|
|
316
|
-
var data = Immutable.fromJS([]);
|
|
317
|
-
var c = Cursor.from(data);
|
|
318
|
-
expect(c.toJS()).toEqual([]);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('properly acts as an iterable', () => {
|
|
322
|
-
var data = Immutable.fromJS({key: {val: 1}});
|
|
323
|
-
var c = Cursor.from(data).values();
|
|
324
|
-
var c1 = c.next().value.get('val');
|
|
325
|
-
expect(c1).toBe(1);
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('can update deeply', () => {
|
|
329
|
-
var onChange = jest.genMockFunction();
|
|
330
|
-
var data = Immutable.fromJS({a:{b:{c:1}}});
|
|
331
|
-
var c = Cursor.from(data, ['a'], onChange);
|
|
332
|
-
var c1 = c.updateIn(['b', 'c'], x => x * 10);
|
|
333
|
-
expect(c1.getIn(['b', 'c'])).toBe(10);
|
|
334
|
-
|
|
335
|
-
var call = onChange.mock.calls[0];
|
|
336
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a:{b:{c:10}}}));
|
|
337
|
-
expect(call[1]).toBe(data);
|
|
338
|
-
expect(call[2]).toEqual(['a', 'b', 'c']);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('can set deeply', () => {
|
|
342
|
-
var onChange = jest.genMockFunction();
|
|
343
|
-
var data = Immutable.fromJS({a:{b:{c:1}}});
|
|
344
|
-
var c = Cursor.from(data, ['a'], onChange);
|
|
345
|
-
var c1 = c.setIn(['b', 'c'], 10);
|
|
346
|
-
expect(c1.getIn(['b', 'c'])).toBe(10);
|
|
347
|
-
|
|
348
|
-
var call = onChange.mock.calls[0];
|
|
349
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a:{b:{c:10}}}));
|
|
350
|
-
expect(call[1]).toBe(data);
|
|
351
|
-
expect(call[2]).toEqual(['a', 'b', 'c']);
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('can get Record value as a property', () => {
|
|
355
|
-
var User = Immutable.Record({ name: 'John' });
|
|
356
|
-
var users = Immutable.List.of(new User());
|
|
357
|
-
var data = Immutable.Map({'users': users});
|
|
358
|
-
var cursor = Cursor.from(data, ['users']);
|
|
359
|
-
expect(cursor.first().name).toBe('John');
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
it('can set value of a cursor directly', () => {
|
|
363
|
-
var onChange = jest.genMockFunction();
|
|
364
|
-
var data = Immutable.fromJS({a:1});
|
|
365
|
-
var c = Cursor.from(data, ['a'], onChange);
|
|
366
|
-
var c1 = c.set(2);
|
|
367
|
-
expect(c1.deref()).toBe(2);
|
|
368
|
-
|
|
369
|
-
var call = onChange.mock.calls[0];
|
|
370
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a:2}));
|
|
371
|
-
expect(call[1]).toBe(data);
|
|
372
|
-
expect(call[2]).toEqual(['a']);
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
it('can set value of a cursor to undefined directly', () => {
|
|
376
|
-
var onChange = jest.genMockFunction();
|
|
377
|
-
var data = Immutable.fromJS({a:1});
|
|
378
|
-
var c = Cursor.from(data, ['a'], onChange);
|
|
379
|
-
var c1 = c.set(undefined);
|
|
380
|
-
expect(c1.deref()).toBe(undefined);
|
|
381
|
-
|
|
382
|
-
var call = onChange.mock.calls[0];
|
|
383
|
-
expect(call[0]).toValueEqual(Immutable.fromJS({a:undefined}));
|
|
384
|
-
expect(call[1]).toBe(data);
|
|
385
|
-
expect(call[2]).toEqual(['a']);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
});
|