8000 cleanup · spmjs/immutable-js@944be90 · GitHub
[go: up one dir, main page]

Skip to conte 8000 nt

Commit 944be90

Browse files
committed
cleanup
1 parent 47abea9 commit 944be90

File tree

6 files changed

+51
-39
lines changed

6 files changed

+51
-39
lines changed

contrib/cursor/index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ var Map = Immutable.Map;
1515

1616

1717
function cursorFrom(rootData, keyPath, onChange) {
18-
keyPath =
19-
arguments.length === 1 ||
20-
typeof keyPath === 'function' && (onChange = keyPath) ? [] :
21-
Array.isArray(keyPath) ? keyPath : [keyPath];
18+
if (arguments.length === 1) {
19+
keyPath = [];
20+
} else if (typeof keyPath === 'function') {
21+
onChange = keyPath;
22+
keyPath = [];
23+
} else if (!Array.isArray(keyPath)) {
24+
keyPath = [keyPath];
25+
}
2226
return makeCursor(rootData, keyPath, onChange);
2327
}
2428

@@ -108,6 +112,9 @@ IndexedCursorPrototype.cursor = function(subKey) {
108112
this : subCursor(this, subKey);
109113
}
110114

115+
/**
116+
* All iterables need to implement __iterate
117+
*/
111118
KeyedCursorPrototype.__iterate =
112119
IndexedCursorPrototype.__iterate = function(fn, reverse) {
113120
var deref = this.deref();
@@ -117,10 +124,14 @@ IndexedCursorPrototype.__iterate = function(fn, reverse) {
117124
) : 0;
118125
}
119126

127+
/**
128+
* All iterables need to implement __iterator
129+
*/
120130
KeyedCursorPrototype.__iterator =
121131
IndexedCursorPrototype.__iterator = function(type, reverse) {
122132
var deref = this.deref();
123-
var iterator = deref && deref.__iterator && deref.__iterator(Iterator.ENTRIES, reverse);
133+
var iterator = deref && deref.__iterator &&
134+
deref.__iterator(Iterator.ENTRIES, reverse);
124135
return new Iterator(function () {
125136
if (!iterator) {
126137
return { value: undefined, done: true };

dist/immutable.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ function wrapIndex(iter, index) {
9696
function returnTrue() {
9797
return true;
9898
}
99+
function isPlainObj(value) {
100+
return value && value.constructor === Object;
101+
}
99102
function wholeSlice(begin, end, size) {
100103
return (begin === 0 || (size !== undefined && begin <= -size)) && (end === undefined || (size !== undefined && end >= size));
101104
}
@@ -1102,9 +1105,6 @@ function seqFromValue(value, maybeSingleton) {
11021105
function isArrayLike(value) {
11031106
return value && typeof value.length === 'number';
11041107
}
1105-
function isPlainObj(value) {
1106-
return value && value.constructor === Object;
1107-
}
11081108
function seqIterate(seq, fn, reverse, useKeys) {
11091109
assertNotInfinite(seq.size);
11101110
var cache = seq._cache;
@@ -3533,7 +3533,7 @@ function fromJS(json, converter) {
35333533
return _fromJSDefault(json);
35343534
}
35353535
function _fromJSWith(converter, json, key, parentJSON) {
3536-
if (json && (Array.isArray(json) || json.constructor === Object)) {
3536+
if (Array.isArray(json) || isPlainObj(json)) {
35373537
return converter.call(parentJSON, key, Iterable(json).map((function(v, k) {
35383538
return _fromJSWith(converter, v, k, json);
35393539
})));

0 commit comments

Comments
 (0)
0