Skip to content

Commit c83e64c

Browse files
committed
Merge branch 'master' into fix-typescript-types-for-typescript-2.4
2 parents f393a68 + 37195e5 commit c83e64c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+9773
-553
lines changed
File renamed without changes.
File renamed without changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ yarn-error.log
99
TODO
1010
/pages/out
1111
/pages/generated
12+
/npm

.travis.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ addons:
1818
- g++-4.9
1919

2020
deploy:
21-
- provider: script
22-
skip_cleanup: true
23-
script: npm run deploy
24-
on:
25-
tags: false
26-
branch: master
27-
repo: facebook/immutable-js
21+
- provider: script
22+
script: npm run gitpublish
23+
skip_cleanup: true
24+
on:
25+
branch: master
26+
repo: facebook/immutable-js
27+
- provider: script
28+
skip_cleanup: true
29+
script: npm run deploy
30+
on:
31+
branch: master
32+
repo: facebook/immutable-js

README.md

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ npm install immutable
4141

4242
Then require it into any module.
4343

44+
<!-- runkit:activate -->
4445
```js
4546
const { Map } = require('immutable')
4647
const map1 = Map({ a: 1, b: 2, c: 3 })
4748
const map2 = map1.set('b', 50)
48-
map1.get('b') // 2
49-
map2.get('b') // 50
49+
map1.get('b') + " vs. " + map2.get('b') // 2 vs. 50
5050
```
5151

5252
### Browser
@@ -99,12 +99,12 @@ lib. Include either `"target": "es2015"` or `"lib": "es2015"` in your
9999
`tsconfig.json`, or provide `--target es2015` or `--lib es2015` to the
100100
`tsc` command.
101101

102+
<!-- runkit:activate -->
102103
```js
103-
import { Map } from "immutable";
104+
const { Map } = require("immutable");
104105
const map1 = Map({ a: 1, b: 2, c: 3 });
105106
const map2 = map1.set('b', 50);
106-
map1.get('b'); // 2
107-
map2.get('b'); // 50
107+
map1.get('b') + " vs. " + map2.get('b') // 2 vs. 50
108108
```
109109

110110
#### Using TypeScript with Immutable.js v3 and earlier:
@@ -114,7 +114,7 @@ via relative path to the type definitions at the top of your file.
114114

115115
```js
116116
///<reference path='./node_modules/immutable/dist/immutable.d.ts'/>
117-
import Immutable = require('immutable');
117+
import Immutable from require('immutable');
118118
var map1: Immutable.Map<string, number>;
119119
map1 = Immutable.Map({a:1, b:2, c:3});
120120
var map2 = map1.set('b', 50);
@@ -151,13 +151,15 @@ treat Immutable.js collections as values, it's important to use the
151151
`Immutable.is()` function or `.equals()` method to determine value equality
152152
instead of the `===` operator which determines object reference identity.
153153

154+
<!-- runkit:activate -->
154155
```js
155156
const { Map } = require('immutable')
156157
const map1 = Map( {a: 1, b: 2, c: 3 })
157158
const map2 = map1.set('b', 2)
158-
assert(map1.equals(map2) === true)
159+
assert.equal(map1, map2) // uses map1.equals
160+
assert.strictEqual(map1, map2) // uses ===
159161
const map3 = map1.set('b', 50)
160-
assert(map1.equals(map3) === false)
162+
assert.notEqual(map1, map3) // uses map1.equals
161163
```
162164

163165
Note: As a performance optimization Immutable.js attempts to return the existing
@@ -173,6 +175,7 @@ to it instead of copying the entire object. Because a reference is much smaller
173175
than the object itself, this results in memory savings and a potential boost in
174176
execution speed for programs which rely on copies (such as an undo-stack).
175177

178+
<!-- runkit:activate -->
176179
```js
177180
const { Map } = require('immutable')
178181
const map1 = Map({ a: 1, b: 2, c: 3 })
@@ -197,28 +200,30 @@ of [ES2015][] [Array][], [Map][], and [Set][].
197200
[Set]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
198201

199202
The difference for the immutable collections is that methods which would mutate
200-
the collection, like `push`, `set`, `unshift` or `splice` instead return a new
201-
immutable collection. Methods which return new arrays like `slice` or `concat`
203+
the collection, like `push`, `set`, `unshift` or `splice`, instead return a new
204+
immutable collection. Methods which return new arrays, like `slice` or `concat`,
202205
instead return new immutable collections.
203206

207+
<!-- runkit:activate -->
204208
```js
205209
const { List } = require('immutable')
206210
const list1 = List([ 1, 2 ]);
207211
const list2 = list1.push(3, 4, 5);
208212
const list3 = list2.unshift(0);
209213
const list4 = list1.concat(list2, list3);
210-
assert(list1.size === 2);
211-
assert(list2.size === 5);
212-
assert(list3.size === 6);
213-
assert(list4.size === 13);
214-
assert(list4.get(0) === 1);
214+
assert.equal(list1.size, 2);
215+
assert.equal(list2.size, 5);
216+
assert.equal(list3.size, 6);
217+
assert.equal(list4.size, 13);
218+
assert.equal(list4.get(0), 1);
215219
```
216220

217221
Almost all of the methods on [Array][] will be found in similar form on
218222
`Immutable.List`, those of [Map][] found on `Immutable.Map`, and those of [Set][]
219223
found on `Immutable.Set`, including collection operations like `forEach()`
220224
and `map()`.
221225

226+
<!-- runkit:activate -->
222227
```js
223228
const { Map } = require('immutable')
224229
const alpha = Map({ a: 1, b: 2, c: 3, d: 4 });
@@ -232,6 +237,7 @@ Designed to inter-operate with your existing JavaScript, Immutable.js
232237
accepts plain JavaScript Arrays and Objects anywhere a method expects an
233238
`Collection`.
234239

240+
<!-- runkit:activate -->
235241
```js
236242
const { Map } = require('immutable')
237243
const map1 = Map({ a: 1, b: 2, c: 3, d: 4 })
@@ -247,6 +253,7 @@ collection methods on JavaScript Objects, which otherwise have a very sparse
247253
native API. Because Seq evaluates lazily and does not cache intermediate
248254
results, these operations can be extremely efficient.
249255

256+
<!-- runkit:activate -->
250257
```js
251258
const { Seq } = require('immutable')
252259
const myObject = { a: 1, b: 2, c: 3 }
@@ -258,17 +265,16 @@ Keep in mind, when using JS objects to construct Immutable Maps, that
258265
JavaScript Object properties are always strings, even if written in a quote-less
259266
shorthand, while Immutable Maps accept keys of any type.
260267

268+
<!-- runkit:activate -->
261269
```js
262270
const { fromJS } = require('immutable')
263271

264272
const obj = { 1: "one" }
265273
Object.keys(obj) // [ "1" ]
266-
obj["1"] // "one"
267-
obj[1] // "one"
274+
assert.equal(obj["1"], obj[1]) // "one" === "one"
268275

269276
const map = fromJS(obj)
270-
map.get("1") // "one"
271-
map.get(1) // undefined
277+
assert.notEqual(map.get("1"), map.get(1)) // "one" !== undefined
272278
```
273279

274280
Property access for JavaScript Objects first converts the key to a string, but
@@ -283,12 +289,13 @@ Objects shallowly with `toArray()` and `toObject()` or deeply with `toJS()`.
283289
All Immutable Collections also implement `toJSON()` allowing them to be passed
284290
to `JSON.stringify` directly.
285291

292+
<!-- runkit:activate -->
286293
```js
287294
const { Map, List } = require('immutable')
288295
const deep = Map({ a: 1, b: 2, c: List([ 3, 4, 5 ]) })
289-
deep.toObject() // { a: 1, b: 2, c: List [ 3, 4, 5 ] }
290-
deep.toArray() // [ 1, 2, List [ 3, 4, 5 ] ]
291-
deep.toJS() // { a: 1, b: 2, c: [ 3, 4, 5 ] }
296+
console.log(deep.toObject()) // { a: 1, b: 2, c: List [ 3, 4, 5 ] }
297+
console.log(deep.toArray()) // [ 1, 2, List [ 3, 4, 5 ] ]
298+
console.log(deep.toJS()) // { a: 1, b: 2, c: [ 3, 4, 5 ] }
292299
JSON.stringify(deep) // '{"a":1,"b":2,"c":[3,4,5]}'
293300
```
294301

@@ -301,12 +308,12 @@ JavaScript in [ES2015][], the latest standard version of JavaScript, including
301308
by the native [Map][] and [Set][] collections added to ES2015.
302309

303310
All examples in the Documentation are presented in ES2015. To run in all
304-
browsers, they need to be translated to ES3.
311+
browsers, they need to be translated to ES5.
305312

306313
```js
307314
// ES2015
308315
const mapped = foo.map(x => x * x);
309-
// ES3
316+
// ES5
310317
var mapped = foo.map(function (x) { return x * x; });
311318
```
312319

@@ -322,6 +329,7 @@ Nested Structures
322329
The collections in Immutable.js are intended to be nested, allowing for deep
323330
trees of data, similar to JSON.
324331

332+
<!-- runkit:activate -->
325333
```js
326334
const { fromJS } = require('immutable')
327335
const nested = fromJS({ a: { b: { c: [ 3, 4, 5 ] } } })
@@ -332,13 +340,18 @@ A few power-tools allow for reading and operating on nested data. The
332340
most useful are `mergeDeep`, `getIn`, `setIn`, and `updateIn`, found on `List`,
333341
`Map` and `OrderedMap`.
334342

343+
<!-- runkit:activate -->
335344
```js
345+
const { fromJS } = require('immutable')
346+
const nested = fromJS({ a: { b: { c: [ 3, 4, 5 ] } } })
347+
336348
const nested2 = nested.mergeDeep({ a: { b: { d: 6 } } })
337349
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ], d: 6 } } }
338350

339-
nested2.getIn([ 'a', 'b', 'd' ]) // 6
351+
console.log(nested2.getIn([ 'a', 'b', 'd' ])) // 6
340352

341353
const nested3 = nested2.updateIn([ 'a', 'b', 'd' ], value => value + 1)
354+
console.log(nested3);
342355
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ], d: 7 } } }
343356

344357
const nested4 = nested3.updateIn([ 'a', 'b', 'c' ], list => list.push(6))
@@ -379,6 +392,7 @@ console.log(oddSquares.get(1)); // 9
379392

380393
Any collection can be converted to a lazy Seq with `.toSeq()`.
381394

395+
<!-- runkit:activate -->
382396
```js
383397
const { Map } = require('immutable')
384398
const seq = Map({ a: 1, b: 2, c: 3 }).toSeq()
@@ -389,11 +403,12 @@ converting to a different concrete type (such as to a JS object):
389403

390404
```js
391405
seq.flip().map(key => key.toUpperCase()).flip().toObject();
392-
// { A: 1, B: 1, C: 1 }
406+
// { A: 1, B: 2, C: 3 }
393407
```
394408

395409
As well as expressing logic that would otherwise seem memory-limited:
396410

411+
<!-- runkit:activate -->
397412
```js
398413
const { Range } = require('immutable')
399414
Range(1, Infinity)
@@ -415,13 +430,14 @@ Equality treats Collections as Data
415430
Immutable.js provides equality which treats immutable data structures as pure
416431
data, performing a deep equality check if necessary.
417432

433+
<!-- runkit:activate -->
418434
```js
419435
const { Map, is } = require('immutable')
420436
const map1 = Map({ a: 1, b: 2, c: 3 })
421437
const map2 = Map({ a: 1, b: 2, c: 3 })
422-
assert(map1 !== map2) // two different instances
423-
assert(is(map1, map2)) // have equivalent values
424-
assert(map1.equals(map2)) // alternatively use the equals method
438+
assert.equal(map1 !== map2, true) // two different instances
439+
assert.equal(is(map1, map2), true) // have equivalent values
440+
assert.equal(map1.equals(map2), true) // alternatively use the equals method
425441
```
426442

427443
`Immutable.is()` uses the same measure of equality as [Object.is][]
@@ -451,14 +467,15 @@ exactly how Immutable.js applies complex mutations itself.
451467
As an example, building `list2` results in the creation of 1, not 3, new
452468
immutable Lists.
453469

470+
<!-- runkit:activate -->
454471
```js
455472
const { List } = require('immutable')
456473
const list1 = List([ 1, 2, 3 ]);
457474
const list2 = list1.withMutations(function (list) {
458475
list.push(4).push(5).push(6);
459476
});
460-
assert(list1.size === 3);
461-
assert(list2.size === 6);
477+
assert.equal(list1.size, 3);
478+
assert.equal(list2.size, 6);
462479
```
463480

464481
Note: Immutable.js also provides `asMutable` and `asImmutable`, but only

__tests__/ArraySeq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('ArraySequence', () => {
4040
});
4141

4242
it('counts from the end of the sequence on negative index', () => {
43-
let i = Seq.of(1, 2, 3, 4, 5, 6, 7);
43+
let i = Seq([1, 2, 3, 4, 5, 6, 7]);
4444
expect(i.get(-1)).toBe(7);
4545
expect(i.get(-5)).toBe(3);
4646
expect(i.get(-9)).toBe(undefined);

__tests__/Equality.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ describe('Equality', () => {
8585
});
8686

8787
it('compares sequences', () => {
88-
let arraySeq = Seq.of(1, 2, 3);
88+
let arraySeq = Seq([1, 2, 3]);
8989
let arraySeq2 = Seq([1, 2, 3]);
9090
expectIs(arraySeq, arraySeq);
91-
expectIs(arraySeq, Seq.of(1, 2, 3));
91+
expectIs(arraySeq, Seq([1, 2, 3]));
9292
expectIs(arraySeq2, arraySeq2);
9393
expectIs(arraySeq2, Seq([1, 2, 3]));
9494
expectIsNot(arraySeq, [1, 2, 3]);
@@ -99,12 +99,12 @@ describe('Equality', () => {
9999
});
100100

101101
it('compares lists', () => {
102-
let list = List.of(1, 2, 3);
102+
let list = List([1, 2, 3]);
103103
expectIs(list, list);
104104
expectIsNot(list, [1, 2, 3]);
105105

106-
expectIs(list, Seq.of(1, 2, 3));
107-
expectIs(list, List.of(1, 2, 3));
106+
expectIs(list, Seq([1, 2, 3]));
107+
expectIs(list, List([1, 2, 3]));
108108

109109
let listLonger = list.push(4);
110110
expectIsNot(list, listLonger);
@@ -135,9 +135,9 @@ describe('Equality', () => {
135135

136136
it('differentiates decimals', () => {
137137
expect(
138-
Seq.of(1.5).hashCode(),
138+
Seq([1.5]).hashCode(),
139139
).not.toBe(
140-
Seq.of(1.6).hashCode(),
140+
Seq([1.6]).hashCode(),
141141
);
142142
});
143143

__tests__/Record.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ describe('Record', () => {
8282
expect(t1.equals(t2));
8383
});
8484

85+
it('if compared against undefined or null should return false', () => {
86+
const MyType = Record({ a: 1, b: 2 });
87+
const t1 = new MyType();
88+
expect(t1.equals(undefined)).toBeFalsy();
89+
expect(t1.equals(null)).toBeFalsy();
90+
});
91+
8592
it('merges in Objects and other Records', () => {
8693
let Point2 = Record({x: 0, y: 0});
8794
let Point3 = Record({x: 0, y: 0, z: 0});

__tests__/Seq.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ describe('Seq', () => {
2828
expect(Seq(new Foo()).size).toBe(2);
2929
});
3030

31-
it('of accepts varargs', () => {
32-
expect(Seq.of(1, 2, 3).size).toBe(3);
33-
});
34-
3531
it('accepts another sequence', () => {
36-
let seq = Seq.of(1, 2, 3);
32+
let seq = Seq([1, 2, 3]);
3733
expect(Seq(seq).size).toBe(3);
3834
});
3935

@@ -59,7 +55,7 @@ describe('Seq', () => {
5955
});
6056

6157
it('detects sequences', () => {
62-
let seq = Seq.of(1, 2, 3);
58+
let seq = Seq([1, 2, 3]);
6359
expect(Seq.isSeq(seq)).toBe(true);
6460
expect(isCollection(seq)).toBe(true);
6561
});

0 commit comments

Comments
 (0)