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 59c291a

Browse filesBrowse files
authored
Define top level predicate functions (immutable-js#1600)
This makes it more clear how these functions depend on each other, and offers more functional top level API. This is a step in the direction of removing internal circular dependencies to unlock stable builds and tree shaking.
1 parent aeb2172 commit 59c291a
Copy full SHA for 59c291a

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

+321
-151
lines changed

‎src/Collection.js

Copy file name to clipboardExpand all lines: src/Collection.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
*/
77

88
import { Seq, KeyedSeq, IndexedSeq, SetSeq } from './Seq';
9-
import { isCollection, isKeyed, isIndexed, isAssociative } from './Predicates';
9+
import { isCollection } from './predicates/isCollection';
10+
import { isKeyed } from './predicates/isKeyed';
11+
import { isIndexed } from './predicates/isIndexed';
12+
import { isAssociative } from './predicates/isAssociative';
1013

1114
export class Collection {
1215
constructor(value) {

‎src/CollectionImpl.js

Copy file name to clipboardExpand all lines: src/CollectionImpl.js
+5-12Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,11 @@ import {
1111
IndexedCollection,
1212
SetCollection,
1313
} from './Collection';
14-
import {
15-
isCollection,
16-
isKeyed,
17-
isIndexed,
18-
isAssociative,
19-
isOrdered,
20-
IS_COLLECTION_SYMBOL,
21-
IS_KEYED_SYMBOL,
22-
IS_INDEXED_SYMBOL,
23-
IS_ORDERED_SYMBOL,
24-
} from './Predicates';
25-
14+
import { isCollection, IS_COLLECTION_SYMBOL } from './predicates/isCollection';
15+
import { isAssociative } from './predicates/isAssociative';
16+
import { isKeyed, IS_KEYED_SYMBOL } from './predicates/isKeyed';
17+
import { isIndexed, IS_INDEXED_SYMBOL } from './predicates/isIndexed';
18+
import { isOrdered, IS_ORDERED_SYMBOL } from './predicates/isOrdered';
2619
import { is } from './is';
2720
import {
2821
NOT_SET,

‎src/Immutable.js

Copy file name to clipboardExpand all lines: src/Immutable.js
+26-9Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ import { Range } from './Range';
1717
import { Repeat } from './Repeat';
1818
import { is } from './is';
1919
import { fromJS } from './fromJS';
20-
import {
21-
isImmutable,
22-
isCollection,
23-
isKeyed,
24-
isIndexed,
25-
isAssociative,
26-
isOrdered,
27-
isValueObject,
28-
} from './Predicates';
20+
21+
// Functional predicates
22+
import { isImmutable } from './predicates/isImmutable';
23+
import { isCollection } from './predicates/isCollection';
24+
import { isKeyed } from './predicates/isKeyed';
25+
import { isIndexed } from './predicates/isIndexed';
26+
import { isAssociative } from './predicates/isAssociative';
27+
import { isOrdered } from './predicates/isOrdered';
28+
import { isValueObject } from './predicates/isValueObject';
29+
import { isSeq } from './predicates/isSeq';
30+
import { isList } from './predicates/isList';
31+
import { isMap } from './predicates/isMap';
32+
import { isOrderedMap } from './predicates/isOrderedMap';
33+
import { isStack } from './predicates/isStack';
34+
import { isSet } from './predicates/isSet';
35+
import { isOrderedSet } from './predicates/isOrderedSet';
36+
import { isRecord } from './predicates/isRecord';
37+
2938
import { Collection } from './CollectionImpl';
3039
import { hash } from './Hash';
3140

@@ -74,6 +83,14 @@ export default {
7483
isAssociative: isAssociative,
7584
isOrdered: isOrdered,
7685
isValueObject: isValueObject,
86+
isSeq: isSeq,
87+
isList: isList,
88+
isMap: isMap,
89+
isOrderedMap: isOrderedMap,
90+
isStack: isStack,
91+
isSet: isSet,
92+
isOrderedSet: isOrderedSet,
93+
isRecord: isRecord,
7794

7895
get: get,
7996
getIn: getIn,

‎src/List.js

Copy file name to clipboardExpand all lines: src/List.js
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
resolveBegin,
1919
resolveEnd,
2020
} from './TrieUtils';
21+
import { IS_LIST_SYMBOL, isList } from './predicates/isList';
2122
import { IndexedCollection } from './Collection';
2223
import { hasIterator, Iterator, iteratorValue, iteratorDone } from './Iterator';
2324
import { setIn } from './methods/setIn';
@@ -241,14 +242,8 @@ export class List extends IndexedCollection {
241242
}
242243
}
243244

244-
export function isList(maybeList) {
245-
return !!(maybeList && maybeList[IS_LIST_SYMBOL]);
246-
}
247-
248245
List.isList = isList;
249246

250-
const IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
251-
252247
export const ListPrototype = List.prototype;
253248
ListPrototype[IS_LIST_SYMBOL] = true;
254249
ListPrototype[DELETE] = ListPrototype.remove;

‎src/Map.js

Copy file name to clipboardExpand all lines: src/Map.js
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import { is } from './is';
99
import { Collection, KeyedCollection } from './Collection';
10-
import { isOrdered } from './Predicates';
10+
import { IS_MAP_SYMBOL, isMap } from './predicates/isMap';
11+
import { isOrdered } from './predicates/isOrdered';
1112
import {
1213
DELETE,
1314
SHIFT,
@@ -164,14 +165,8 @@ export class Map extends KeyedCollection {
164165
}
165166
}
166167

167-
export function isMap(maybeMap) {
168-
return !!(maybeMap && maybeMap[IS_MAP_SYMBOL]);
169-
}
170-
171168
Map.isMap = isMap;
172169

173-
const IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
174-
175170
export const MapPrototype = Map.prototype;
176171
MapPrototype[IS_MAP_SYMBOL] = true;
177172
MapPrototype[DELETE] = MapPrototype.remove;

‎src/Operations.js

Copy file name to clipboardExpand all lines: src/Operations.js
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ import {
1919
SetCollection,
2020
IndexedCollection,
2121
} from './Collection';
22-
import {
23-
isCollection,
24-
isKeyed,
25-
isIndexed,
26-
isOrdered,
27-
IS_ORDERED_SYMBOL,
28-
} from './Predicates';
22+
import { isCollection } from './predicates/isCollection';
23+
import { isKeyed } from './predicates/isKeyed';
24+
import { isIndexed } from './predicates/isIndexed';
25+
import { isOrdered, IS_ORDERED_SYMBOL } from './predicates/isOrdered';
26+
import { isSeq } from './predicates/isSeq';
2927
import {
3028
getIterator,
3129
Iterator,
@@ -36,7 +34,6 @@ import {
3634
ITERATE_ENTRIES,
3735
} from './Iterator';
3836
import {
39-
isSeq,
4037
Seq,
4138
KeyedSeq,
4239
SetSeq,

‎src/OrderedMap.js

Copy file name to clipboardExpand all lines: src/OrderedMap.js
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
*/
77

88
import { KeyedCollection } from './Collection';
9-
import { IS_ORDERED_SYMBOL, isOrdered } from './Predicates';
10-
import { Map, isMap, emptyMap } from './Map';
9+
import { IS_ORDERED_SYMBOL } from './predicates/isOrdered';
10+
import { isOrderedMap } from './predicates/isOrderedMap';
11+
import { Map, emptyMap } from './Map';
1112
import { emptyList } from './List';
1213
import { DELETE, NOT_SET, SIZE } from './TrieUtils';
1314
import assertNotInfinite from './utils/assertNotInfinite';
@@ -99,10 +100,6 @@ export class OrderedMap extends Map {
99100
}
100101
}
101102

102-
function isOrderedMap(maybeOrderedMap) {
103-
return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
104-
}
105-
106103
OrderedMap.isOrderedMap = isOrderedMap;
107104

108105
OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;

‎src/OrderedSet.js

Copy file name to clipboardExpand all lines: src/OrderedSet.js
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77

88
import { SetCollection, KeyedCollection } from './Collection';
9-
import { IS_ORDERED_SYMBOL, isOrdered } from './Predicates';
9+
import { IS_ORDERED_SYMBOL } from './predicates/isOrdered';
10+
import { isOrderedSet } from './predicates/isOrderedSet';
1011
import { IndexedCollectionPrototype } from './CollectionImpl';
11-
import { Set, isSet } from './Set';
12+
import { Set } from './Set';
1213
import { emptyOrderedMap } from './OrderedMap';
1314
import assertNotInfinite from './utils/assertNotInfinite';
1415

@@ -40,10 +41,6 @@ export class OrderedSet extends Set {
4041
}
4142
}
4243

43-
function isOrderedSet(maybeOrderedSet) {
44-
return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
45-
}
46-
4744
OrderedSet.isOrderedSet = isOrderedSet;
4845

4946
const OrderedSetPrototype = OrderedSet.prototype;

‎src/Predicates.js

Copy file name to clipboardExpand all lines: src/Predicates.js
-49Lines changed: 0 additions & 49 deletions
This file was deleted.

‎src/Record.js

Copy file name to clipboardExpand all lines: src/Record.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { KeyedCollection } from './Collection';
1010
import { keyedSeqFromValue } from './Seq';
1111
import { List } from './List';
1212
import { ITERATE_ENTRIES, ITERATOR_SYMBOL } from './Iterator';
13-
import { isRecord, IS_RECORD_SYMBOL } from './Predicates';
13+
import { isRecord, IS_RECORD_SYMBOL } from './predicates/isRecord';
1414
import { CollectionPrototype } from './CollectionImpl';
1515
import { DELETE } from './TrieUtils';
1616
import { getIn } from './methods/getIn';

‎src/Seq.js

Copy file name to clipboardExpand all lines: src/Seq.js
+7-14Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
import { wrapIndex } from './TrieUtils';
99
import { Collection } from './Collection';
10-
import {
11-
isImmutable,
12-
isCollection,
13-
isKeyed,
14-
isAssociative,
15-
isRecord,
16-
IS_ORDERED_SYMBOL,
17-
} from './Predicates';
10+
import { IS_SEQ_SYMBOL, isSeq } from './predicates/isSeq';
11+
import { isImmutable } from './predicates/isImmutable';
12+
import { isCollection } from './predicates/isCollection';
13+
import { isKeyed } from './predicates/isKeyed';
14+
import { isAssociative } from './predicates/isAssociative';
15+
import { isRecord } from './predicates/isRecord';
16+
import { IS_ORDERED_SYMBOL } from './predicates/isOrdered';
1817
import {
1918
Iterator,
2019
iteratorValue,
@@ -155,8 +154,6 @@ Seq.Keyed = KeyedSeq;
155154
Seq.Set = SetSeq;
156155
Seq.Indexed = IndexedSeq;
157156

158-
const IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
159-
160157
Seq.prototype[IS_SEQ_SYMBOL] = true;
161158

162159
// #pragma Root Sequences
@@ -290,10 +287,6 @@ class CollectionSeq extends IndexedSeq {
290287

291288
// # pragma Helper functions
292289

293-
export function isSeq(maybeSeq) {
294-
return !!(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
295-
}
296-
297290
let EMPTY_SEQ;
298291

299292
function emptySequence() {

‎src/Set.js

Copy file name to clipboardExpand all lines: src/Set.js
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*/
77

88
import { Collection, SetCollection, KeyedCollection } from './Collection';
9-
import { isOrdered } from './Predicates';
9+
import { isOrdered } from './predicates/isOrdered';
10+
import { IS_SET_SYMBOL, isSet } from './predicates/isSet';
1011
import { emptyMap } from './Map';
1112
import { DELETE } from './TrieUtils';
1213
import { sortFactory } from './Operations';
@@ -174,14 +175,8 @@ export class Set extends SetCollection {
174175
}
175176
}
176177

177-
export function isSet(maybeSet) {
178-
return !!(maybeSet && maybeSet[IS_SET_SYMBOL]);
179-
}
180-
181178
Set.isSet = isSet;
182179

183-
const IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
184-
185180
const SetPrototype = Set.prototype;
186181
SetPrototype[IS_SET_SYMBOL] = true;
187182
SetPrototype[DELETE] = SetPrototype.remove;

‎src/Stack.js

Copy file name to clipboardExpand all lines: src/Stack.js
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { wholeSlice, resolveBegin, resolveEnd, wrapIndex } from './TrieUtils';
99
import { IndexedCollection } from './Collection';
1010
import { ArraySeq } from './Seq';
1111
import { Iterator, iteratorValue, iteratorDone } from './Iterator';
12+
import { IS_STACK_SYMBOL, isStack } from './predicates/isStack';
1213
import assertNotInfinite from './utils/assertNotInfinite';
1314
import { asImmutable } from './methods/asImmutable';
1415
import { asMutable } from './methods/asMutable';
@@ -198,14 +199,8 @@ export class Stack extends IndexedCollection {
198199
}
199200
}
200201

201-
function isStack(maybeStack) {
202-
return !!(maybeStack && maybeStack[IS_STACK_SYMBOL]);
203-
}
204-
205202
Stack.isStack = isStack;
206203

207-
const IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
208-
209204
const StackPrototype = Stack.prototype;
210205
StackPrototype[IS_STACK_SYMBOL] = true;
211206
StackPrototype.shift = StackPrototype.pop;

‎src/fromJS.js

Copy file name to clipboardExpand all lines: src/fromJS.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { KeyedSeq, IndexedSeq } from './Seq';
9-
import { isKeyed } from './Predicates';
9+
import { isKeyed } from './predicates/isKeyed';
1010
import isPlainObj from './utils/isPlainObj';
1111

1212
export function fromJS(value, converter) {

‎src/functional/get.js

Copy file name to clipboardExpand all lines: src/functional/get.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { isImmutable } from '../Predicates';
8+
import { isImmutable } from '../predicates/isImmutable';
99
import { has } from './has';
1010

1111
export function get(collection, key, notSetValue) {

‎src/functional/has.js

Copy file name to clipboardExpand all lines: src/functional/has.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { isImmutable } from '../Predicates';
8+
import { isImmutable } from '../predicates/isImmutable';
99
import hasOwnProperty from '../utils/hasOwnProperty';
1010
import isDataStructure from '../utils/isDataStructure';
1111

‎src/functional/merge.js

Copy file name to clipboardExpand all lines: src/functional/merge.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { isImmutable } from '../Predicates';
8+
import { isImmutable } from '../predicates/isImmutable';
99
import { IndexedCollection, KeyedCollection } from '../Collection';
1010
import hasOwnProperty from '../utils/hasOwnProperty';
1111
import isDataStructure from '../utils/isDataStructure';

0 commit comments

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