Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 25de6da

Browse filesBrowse files
committed
Merge from facebook/master
# Conflicts: # src/utils/isArrayLike.js
2 parents e769027 + e65e5af commit 25de6da
Copy full SHA for 25de6da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

42 files changed

+2320
-1090
lines changed

‎.eslintrc.json

Copy file name to clipboardExpand all lines: .eslintrc.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"object-shorthand": "off",
4949
"one-var": "error",
5050
"operator-assignment": "error",
51+
"prefer-destructuring": "off",
5152
"prefer-rest-params": "off",
5253
"prefer-spread": "off",
5354
"prefer-template": "off",

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sudo: false
22
language: node_js
3-
node_js: 7
3+
node_js: 8
44

55
cache: yarn
66
script: npm run test:travis

‎README.md

Copy file name to clipboardExpand all lines: README.md
+22-15Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,16 @@ objects represent some thing which could change over time, a value represents
152152
the state of that thing at a particular instance of time. This principle is most
153153
important to understanding the appropriate use of immutable data. In order to
154154
treat Immutable.js collections as values, it's important to use the
155-
`Immutable.is()` function or `.equals()` method to determine value equality
156-
instead of the `===` operator which determines object reference identity.
155+
`Immutable.is()` function or `.equals()` method to determine *value equality*
156+
instead of the `===` operator which determines object *reference identity*.
157157

158158
<!-- runkit:activate -->
159159
```js
160160
const { Map } = require('immutable')
161-
const map1 = Map( {a: 1, b: 2, c: 3 })
162-
const map2 = map1.set('b', 2)
163-
assert.equal(map1, map2) // uses map1.equals
164-
assert.strictEqual(map1, map2) // uses ===
165-
const map3 = map1.set('b', 50)
166-
assert.notEqual(map1, map3) // uses map1.equals
161+
const map1 = Map({ a: 1, b: 2, c: 3 })
162+
const map2 = Map({ a: 1, b: 2, c: 3 })
163+
map1.equals(map2) // true
164+
map1 === map2 // false
167165
```
168166

169167
Note: As a performance optimization Immutable.js attempts to return the existing
@@ -174,6 +172,14 @@ which would prefer to re-run the function if a deeper equality check could
174172
potentially be more costly. The `===` equality check is also used internally by
175173
`Immutable.is` and `.equals()` as a performance optimization.
176174

175+
<!-- runkit:activate -->
176+
```js
177+
const { Map } = require('immutable')
178+
const map1 = Map({ a: 1, b: 2, c: 3 })
179+
const map2 = map1.set('b', 2) // Set to same value
180+
map1 === map2 // true
181+
```
182+
177183
If an object is immutable, it can be "copied" simply by making another reference
178184
to it instead of copying the entire object. Because a reference is much smaller
179185
than the object itself, this results in memory savings and a potential boost in
@@ -182,8 +188,8 @@ execution speed for programs which rely on copies (such as an undo-stack).
182188
<!-- runkit:activate -->
183189
```js
184190
const { Map } = require('immutable')
185-
const map1 = Map({ a: 1, b: 2, c: 3 })
186-
const clone = map1;
191+
const map = Map({ a: 1, b: 2, c: 3 })
192+
const mapCopy = map; // Look, "copies" are free!
187193
```
188194

189195
[React]: http://facebook.github.io/react/
@@ -238,7 +244,7 @@ alpha.map((v, k) => k.toUpperCase()).join();
238244
### Convert from raw JavaScript objects and arrays.
239245

240246
Designed to inter-operate with your existing JavaScript, Immutable.js
241-
accepts plain JavaScript Arrays and Objects anywhere a method expects an
247+
accepts plain JavaScript Arrays and Objects anywhere a method expects a
242248
`Collection`.
243249

244250
<!-- runkit:activate -->
@@ -279,11 +285,11 @@ shorthand, while Immutable Maps accept keys of any type.
279285
const { fromJS } = require('immutable')
280286

281287
const obj = { 1: "one" }
282-
Object.keys(obj) // [ "1" ]
283-
assert.equal(obj["1"], obj[1]) // "one" === "one"
288+
console.log(Object.keys(obj)) // [ "1" ]
289+
console.log(obj["1"], obj[1]) // "one", "one"
284290

285291
const map = fromJS(obj)
286-
assert.notEqual(map.get("1"), map.get(1)) // "one" !== undefined
292+
console.log(map.get("1"), map.get(1)) // "one", undefined
287293
```
288294

289295
Property access for JavaScript Objects first converts the key to a string, but
@@ -296,7 +302,8 @@ not altered.
296302
All Immutable.js Collections can be converted to plain JavaScript Arrays and
297303
Objects shallowly with `toArray()` and `toObject()` or deeply with `toJS()`.
298304
All Immutable Collections also implement `toJSON()` allowing them to be passed
299-
to `JSON.stringify` directly.
305+
to `JSON.stringify` directly. They also respect the custom `toJSON()` methods of
306+
nested objects.
300307

301308
<!-- runkit:activate -->
302309
```js

‎__tests__/List.ts

Copy file name to clipboardExpand all lines: __tests__/List.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,12 @@ describe('List', () => {
513513
expect(r.toArray()).toEqual(['A', 'B', 'C']);
514514
});
515515

516+
it('map no-ops return the same reference', () => {
517+
const v = List.of('a', 'b', 'c');
518+
const r = v.map(value => value);
519+
expect(r).toBe(v);
520+
});
521+
516522
it('filters values', () => {
517523
const v = List.of('a', 'b', 'c', 'd', 'e', 'f');
518524
const r = v.filter((value, index) => index % 2 === 1);

‎__tests__/Map.ts

Copy file name to clipboardExpand all lines: __tests__/Map.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ describe('Map', () => {
255255
expect(r.toObject()).toEqual({ A: 'a', B: 'b', C: 'c' });
256256
});
257257

258+
it('maps no-ops return the same reference', () => {
259+
const m = Map({ a: 'a', b: 'b', c: 'c' });
260+
const r = m.map(value => value);
261+
expect(r).toBe(m);
262+
});
263+
258264
it('filters values', () => {
259265
const m = Map({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 });
260266
const r = m.filter(value => value % 2 === 1);

‎__tests__/Record.ts

Copy file name to clipboardExpand all lines: __tests__/Record.ts
+16-15Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ describe('Record', () => {
4848
it('setting an unknown key is a no-op', () => {
4949
const MyType = Record({ a: 1, b: 2, c: 3 });
5050

51-
const t1 = new MyType({ a: 10, b: 20 });
51+
const t1 = MyType({ a: 10, b: 20 });
5252
const t2 = t1.set('d' as any, 4);
5353

5454
expect(t2).toBe(t1);
5555
});
5656

5757
it('falls back to default values when deleted or cleared', () => {
5858
const MyType = Record({ a: 1, b: 2, c: 3 });
59-
const t1 = new MyType({ a: 10, b: 20 });
60-
const t2 = new MyType({ b: 20 });
59+
const t1 = MyType({ a: 10, b: 20 });
60+
const t2 = MyType({ b: 20 });
6161
const t3 = t1.delete('a');
6262
const t4 = t3.clear();
6363

@@ -68,13 +68,13 @@ describe('Record', () => {
6868

6969
expect(t2.equals(t3)).toBe(true);
7070
expect(t2.equals(t4)).toBe(false);
71-
expect(t4.equals(new MyType())).toBe(true);
71+
expect(t4.equals(MyType())).toBe(true);
7272
});
7373

7474
it('allows deletion of values deep within a tree', () => {
7575
const AType = Record({ a: 1 });
76-
const BType = Record({ b: new AType({ a: 2 }) });
77-
const t1 = new BType();
76+
const BType = Record({ b: AType({ a: 2 }) });
77+
const t1 = BType();
7878
const t2 = t1.deleteIn(['b', 'a']);
7979

8080
expect(t1.get('b').get('a')).toBe(2);
@@ -90,7 +90,7 @@ describe('Record', () => {
9090

9191
it('if compared against undefined or null should return false', () => {
9292
const MyType = Record({ a: 1, b: 2 });
93-
const t1 = new MyType();
93+
const t1 = MyType();
9494
expect(t1.equals(undefined)).toBeFalsy();
9595
expect(t1.equals(null)).toBeFalsy();
9696
});
@@ -115,7 +115,7 @@ describe('Record', () => {
115115
it('converts sequences to records', () => {
116116
const MyType = Record({ a: 1, b: 2, c: 3 });
117117
const seq = Seq({ a: 10, b: 20 });
118-
const t = new MyType(seq);
118+
const t = MyType(seq);
119119
expect(t.toObject()).toEqual({ a: 10, b: 20, c: 3 });
120120
});
121121

@@ -129,7 +129,7 @@ describe('Record', () => {
129129
it('skips unknown keys', () => {
130130
const MyType = Record({ a: 1, b: 2 });
131131
const seq = Seq({ b: 20, c: 30 });
132-
const t = new MyType(seq);
132+
const t = MyType(seq);
133133

134134
expect(t.get('a')).toEqual(1);
135135
expect(t.get('b')).toEqual(20);
@@ -138,18 +138,18 @@ describe('Record', () => {
138138

139139
it('returns itself when setting identical values', () => {
140140
const MyType = Record({ a: 1, b: 2 });
141-
const t1 = new MyType();
142-
const t2 = new MyType({ a: 1 });
141+
const t1 = MyType();
142+
const t2 = MyType({ a: 1 });
143143
const t3 = t1.set('a', 1);
144144
const t4 = t2.set('a', 1);
145145
expect(t3).toBe(t1);
146146
expect(t4).toBe(t2);
147147
});
148148

149-
it('returns new record when setting new values', () => {
149+
it('returns record when setting values', () => {
150150
const MyType = Record({ a: 1, b: 2 });
151-
const t1 = new MyType();
152-
const t2 = new MyType({ a: 1 });
151+
const t1 = MyType();
152+
const t2 = MyType({ a: 1 });
153153
const t3 = t1.set('a', 3);
154154
const t4 = t2.set('a', 3);
155155
expect(t3).not.toBe(t1);
@@ -158,7 +158,7 @@ describe('Record', () => {
158158

159159
it('allows for readonly property access', () => {
160160
const MyType = Record({ a: 1, b: 'foo' });
161-
const t1 = new MyType();
161+
const t1 = MyType();
162162
const a: number = t1.a;
163163
const b: string = t1.b;
164164
expect(a).toEqual(1);
@@ -179,6 +179,7 @@ describe('Record', () => {
179179
}
180180
}
181181

182+
// Note: `new` is only used because of `class`
182183
const t1 = new ABClass({ a: 1 });
183184
const t2 = t1.setA(3);
184185
const t3 = t2.setB(10);

‎__tests__/RecordJS.js

Copy file name to clipboardExpand all lines: __tests__/RecordJS.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
const { Record } = require('../');
99

1010
describe('Record', () => {
11-
it('defines a constructor', () => {
11+
it('defines a record factory', () => {
1212
const MyType = Record({ a: 1, b: 2, c: 3 });
1313

14-
const t = new MyType();
14+
const t = MyType();
1515
const t2 = t.set('a', 10);
1616

1717
expect(t.a).toBe(1);
@@ -44,6 +44,7 @@ describe('Record', () => {
4444
}
4545
}
4646

47+
// Note: `new` is only used because of `class`
4748
const t = new Alphabet();
4849
const t2 = t.set('b', 200);
4950

‎__tests__/Set.ts

Copy file name to clipboardExpand all lines: __tests__/Set.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ describe('Set', () => {
9292
expect(s.toObject()).toEqual({ a: 'a', b: 'b', c: 'c' });
9393
});
9494

95+
it('maps no-ops return the same reference', () => {
96+
const s = Set([1, 2, 3]);
97+
const r = s.map(value => value);
98+
expect(r).toBe(s);
99+
});
100+
95101
it('unions an unknown collection of Sets', () => {
96102
const abc = Set(['a', 'b', 'c']);
97103
const cat = Set(['c', 'a', 't']);

‎__tests__/hash.ts

Copy file name to clipboardExpand all lines: __tests__/hash.ts
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,30 @@ describe('hash', () => {
2929
expect(hash(123.4567)).toBe(887769707);
3030
});
3131

32+
it('generates different hashes for different objects', () => {
33+
const objA = {};
34+
const objB = {};
35+
expect(hash(objA)).toBe(hash(objA));
36+
expect(hash(objA)).not.toBe(hash(objB));
37+
});
38+
39+
it('generates different hashes for different functions', () => {
40+
const funA = () => {
41+
return;
42+
};
43+
const funB = () => {
44+
return;
45+
};
46+
expect(hash(funA)).toBe(hash(funA));
47+
expect(hash(funA)).not.toBe(hash(funB));
48+
});
49+
3250
const genValue = gen.oneOf([gen.string, gen.int]);
3351

3452
check.it('generates unsigned 31-bit integers', [genValue], value => {
3553
const hashVal = hash(value);
36-
expect(hashVal % 1).toBe(0);
54+
expect(Number.isInteger(hashVal)).toBe(true);
55+
expect(hashVal).toBeGreaterThan(-Math.pow(2, 31));
3756
expect(hashVal).toBeLessThan(Math.pow(2, 31));
3857
});
3958
});

‎__tests__/splice.ts

Copy file name to clipboardExpand all lines: __tests__/splice.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('splice', () => {
8282
});
8383

8484
it('has the same behavior as array splice in known edge cases', () => {
85-
// arbitary numbers that sum to 31
85+
// arbitrary numbers that sum to 31
8686
const a = Range(0, 49).toArray();
8787
const v = List(a);
8888
a.splice(-18, 0, 0);

‎contrib/cursor/README.md

Copy file name to clipboardExpand all lines: contrib/cursor/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ collection to portions of your application while maintaining a central point
1717
aware of changes to the entire data structure: an `onChange` function which is
1818
called whenever a cursor or sub-cursor calls `update`.
1919

20-
This is particularly useful when used in conjuction with component-based UI
20+
This is particularly useful when used in conjunction with component-based UI
2121
libraries like [React](https://facebook.github.io/react/) or to simulate
2222
"state" throughout an application while maintaining a single flow of logic.
2323

‎contrib/cursor/index.d.ts

Copy file name to clipboardExpand all lines: contrib/cursor/index.d.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* collection to portions of your application while maintaining a central point
1515
* aware of changes to the entire data structure.
1616
*
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
1818
* libraries like [React](http://facebook.github.io/react/) or to simulate
1919
* "state" throughout an application while maintaining a single flow of logic.
2020
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.