Skip to content

Commit bcd1732

Browse files
authored
Use Symbol instead of Sentinel terminology (immutable-js#1597)
1 parent e1a9649 commit bcd1732

11 files changed

+44
-43
lines changed

src/CollectionImpl.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717
isIndexed,
1818
isAssociative,
1919
isOrdered,
20-
IS_ITERABLE_SENTINEL,
21-
IS_KEYED_SENTINEL,
22-
IS_INDEXED_SENTINEL,
23-
IS_ORDERED_SENTINEL,
20+
IS_COLLECTION_SYMBOL,
21+
IS_KEYED_SYMBOL,
22+
IS_INDEXED_SYMBOL,
23+
IS_ORDERED_SYMBOL,
2424
} from './Predicates';
2525

2626
import { is } from './is';
@@ -520,7 +520,7 @@ mixin(Collection, {
520520
});
521521

522522
const CollectionPrototype = Collection.prototype;
523-
CollectionPrototype[IS_ITERABLE_SENTINEL] = true;
523+
CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
524524
CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
525525
CollectionPrototype.toJSON = CollectionPrototype.toArray;
526526
CollectionPrototype.__toStringMapper = quoteString;
@@ -559,7 +559,7 @@ mixin(KeyedCollection, {
559559
});
560560

561561
const KeyedCollectionPrototype = KeyedCollection.prototype;
562-
KeyedCollectionPrototype[IS_KEYED_SENTINEL] = true;
562+
KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
563563
KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
564564
KeyedCollectionPrototype.toJSON = toObject;
565565
KeyedCollectionPrototype.__toStringMapper = (v, k) =>
@@ -697,8 +697,8 @@ mixin(IndexedCollection, {
697697
});
698698

699699
const IndexedCollectionPrototype = IndexedCollection.prototype;
700-
IndexedCollectionPrototype[IS_INDEXED_SENTINEL] = true;
701-
IndexedCollectionPrototype[IS_ORDERED_SENTINEL] = true;
700+
IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
701+
IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
702702

703703
mixin(SetCollection, {
704704
// ### ES6 Collection methods (ES6 Array and Map)

src/List.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,15 @@ export class List extends IndexedCollection {
243243
}
244244

245245
export function isList(maybeList) {
246-
return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
246+
return !!(maybeList && maybeList[IS_LIST_SYMBOL]);
247247
}
248248

249249
List.isList = isList;
250250

251-
const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
251+
const IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
252252

253253
export const ListPrototype = List.prototype;
254-
ListPrototype[IS_LIST_SENTINEL] = true;
254+
ListPrototype[IS_LIST_SYMBOL] = true;
255255
ListPrototype[DELETE] = ListPrototype.remove;
256256
ListPrototype.merge = ListPrototype.concat;
257257
ListPrototype.setIn = setIn;

src/Map.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ export class Map extends KeyedCollection {
167167
}
168168

169169
export function isMap(maybeMap) {
170-
return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
170+
return !!(maybeMap && maybeMap[IS_MAP_SYMBOL]);
171171
}
172172

173173
Map.isMap = isMap;
174174

175-
const IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
175+
const IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
176176

177177
export const MapPrototype = Map.prototype;
178-
MapPrototype[IS_MAP_SENTINEL] = true;
178+
MapPrototype[IS_MAP_SYMBOL] = true;
179179
MapPrototype[DELETE] = MapPrototype.remove;
180180
MapPrototype.removeAll = MapPrototype.deleteAll;
181181
MapPrototype.setIn = setIn;

src/Operations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
isKeyed,
2525
isIndexed,
2626
isOrdered,
27-
IS_ORDERED_SENTINEL,
27+
IS_ORDERED_SYMBOL,
2828
} from './Predicates';
2929
import {
3030
getIterator,
@@ -92,7 +92,7 @@ export class ToKeyedSequence extends KeyedSeq {
9292
return this._iter.__iterator(type, reverse);
9393
}
9494
}
95-
ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
95+
ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
9696

9797
export class ToIndexedSequence extends IndexedSeq {
9898
constructor(iter) {

src/OrderedMap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { KeyedCollection } from './Collection';
9-
import { IS_ORDERED_SENTINEL, isOrdered } from './Predicates';
9+
import { IS_ORDERED_SYMBOL, isOrdered } from './Predicates';
1010
import { Map, isMap, emptyMap } from './Map';
1111
import { emptyList } from './List';
1212
import { DELETE, NOT_SET, SIZE } from './TrieUtils';
@@ -105,7 +105,7 @@ function isOrderedMap(maybeOrderedMap) {
105105

106106
OrderedMap.isOrderedMap = isOrderedMap;
107107

108-
OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
108+
OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
109109
OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
110110

111111
function makeOrderedMap(map, list, ownerID, hash) {

src/OrderedSet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { SetCollection, KeyedCollection } from './Collection';
9-
import { IS_ORDERED_SENTINEL, isOrdered } from './Predicates';
9+
import { IS_ORDERED_SYMBOL, isOrdered } from './Predicates';
1010
import { IndexedCollectionPrototype } from './CollectionImpl';
1111
import { Set, isSet } from './Set';
1212
import { emptyOrderedMap } from './OrderedMap';
@@ -47,7 +47,7 @@ function isOrderedSet(maybeOrderedSet) {
4747
OrderedSet.isOrderedSet = isOrderedSet;
4848

4949
const OrderedSetPrototype = OrderedSet.prototype;
50-
OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
50+
OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
5151
OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
5252
OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
5353

src/Predicates.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ export function isImmutable(maybeImmutable) {
1010
}
1111

1212
export function isCollection(maybeCollection) {
13-
return !!(maybeCollection && maybeCollection[IS_ITERABLE_SENTINEL]);
13+
return !!(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
1414
}
1515

1616
export function isKeyed(maybeKeyed) {
17-
return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
17+
return !!(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
1818
}
1919

2020
export function isIndexed(maybeIndexed) {
21-
return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
21+
return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
2222
}
2323

2424
export function isAssociative(maybeAssociative) {
2525
return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
2626
}
2727

2828
export function isOrdered(maybeOrdered) {
29-
return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
29+
return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
3030
}
3131

3232
export function isRecord(maybeRecord) {
33-
return !!(maybeRecord && maybeRecord[IS_RECORD_SENTINEL]);
33+
return !!(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
3434
}
3535

3636
export function isValueObject(maybeValue) {
@@ -41,8 +41,9 @@ export function isValueObject(maybeValue) {
4141
);
4242
}
4343

44-
export const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
45-
export const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
46-
export const IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
47-
export const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
48-
export const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@';
44+
// Note: values unchanged to preserve immutable-devtools.
45+
export const IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
46+
export const IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
47+
export const IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
48+
export const IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
49+
export const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';

src/Record.js

Lines changed: 2 additions & 2 deletions
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_SENTINEL } from './Predicates';
13+
import { isRecord, IS_RECORD_SYMBOL } from './Predicates';
1414
import { CollectionPrototype } from './CollectionImpl';
1515
import { DELETE } from './TrieUtils';
1616
import { getIn } from './methods/getIn';
@@ -188,7 +188,7 @@ export class Record {
188188
Record.isRecord = isRecord;
189189
Record.getDescriptiveName = recordName;
190190
const RecordPrototype = Record.prototype;
191-
RecordPrototype[IS_RECORD_SENTINEL] = true;
191+
RecordPrototype[IS_RECORD_SYMBOL] = true;
192192
RecordPrototype[DELETE] = RecordPrototype.remove;
193193
RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
194194
RecordPrototype.getIn = getIn;

src/Seq.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
isKeyed,
1414
isAssociative,
1515
isRecord,
16-
IS_ORDERED_SENTINEL,
16+
IS_ORDERED_SYMBOL,
1717
} from './Predicates';
1818
import {
1919
Iterator,
@@ -155,9 +155,9 @@ Seq.Keyed = KeyedSeq;
155155
Seq.Set = SetSeq;
156156
Seq.Indexed = IndexedSeq;
157157

158-
const IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
158+
const IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
159159

160-
Seq.prototype[IS_SEQ_SENTINEL] = true;
160+
Seq.prototype[IS_SEQ_SYMBOL] = true;
161161

162162
// #pragma Root Sequences
163163

@@ -245,7 +245,7 @@ class ObjectSeq extends KeyedSeq {
245245
});
246246
}
247247
}
248-
ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
248+
ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
249249

250250
class CollectionSeq extends IndexedSeq {
251251
constructor(collection) {
@@ -291,7 +291,7 @@ class CollectionSeq extends IndexedSeq {
291291
// # pragma Helper functions
292292

293293
export function isSeq(maybeSeq) {
294-
return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
294+
return !!(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
295295
}
296296

297297
let EMPTY_SEQ;

src/Set.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ export class Set extends SetCollection {
175175
}
176176

177177
export function isSet(maybeSet) {
178-
return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
178+
return !!(maybeSet && maybeSet[IS_SET_SYMBOL]);
179179
}
180180

181181
Set.isSet = isSet;
182182

183-
const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
183+
const IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
184184

185185
const SetPrototype = Set.prototype;
186-
SetPrototype[IS_SET_SENTINEL] = true;
186+
SetPrototype[IS_SET_SYMBOL] = true;
187187
SetPrototype[DELETE] = SetPrototype.remove;
188188
SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
189189
SetPrototype.withMutations = withMutations;

src/Stack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ export class Stack extends IndexedCollection {
199199
}
200200

201201
function isStack(maybeStack) {
202-
return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
202+
return !!(maybeStack && maybeStack[IS_STACK_SYMBOL]);
203203
}
204204

205205
Stack.isStack = isStack;
206206

207-
const IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
207+
const IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
208208

209209
const StackPrototype = Stack.prototype;
210-
StackPrototype[IS_STACK_SENTINEL] = true;
210+
StackPrototype[IS_STACK_SYMBOL] = true;
211211
StackPrototype.shift = StackPrototype.pop;
212212
StackPrototype.unshift = StackPrototype.push;
213213
StackPrototype.unshiftAll = StackPrototype.pushAll;

0 commit comments

Comments
 (0)