MCPcopy
hub / github.com/immutable-js/immutable-js / OrderedMap

Class OrderedMap

src/OrderedMap.js:9–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import assertNotInfinite from './utils/assertNotInfinite';
8
9export class OrderedMap extends Map {
10 // @pragma Construction
11
12 constructor(value) {
13 // eslint-disable-next-line no-constructor-return
14 return value === undefined || value === null
15 ? emptyOrderedMap()
16 : isOrderedMap(value)
17 ? value
18 : emptyOrderedMap().withMutations((map) => {
19 const iter = KeyedCollection(value);
20 assertNotInfinite(iter.size);
21 iter.forEach((v, k) => map.set(k, v));
22 });
23 }
24
25 static of(/*...values*/) {
26 return this(arguments);
27 }
28
29 toString() {
30 return this.__toString('OrderedMap {', '}');
31 }
32
33 // @pragma Access
34
35 get(k, notSetValue) {
36 const index = this._map.get(k);
37 return index !== undefined ? this._list.get(index)[1] : notSetValue;
38 }
39
40 // @pragma Modification
41
42 clear() {
43 if (this.size === 0) {
44 return this;
45 }
46 if (this.__ownerID) {
47 this.size = 0;
48 this._map.clear();
49 this._list.clear();
50 this.__altered = true;
51 return this;
52 }
53 return emptyOrderedMap();
54 }
55
56 set(k, v) {
57 return updateOrderedMap(this, k, v);
58 }
59
60 remove(k) {
61 return updateOrderedMap(this, k, NOT_SET);
62 }
63
64 __iterate(fn, reverse) {
65 return this._list.__iterate(
66 (entry) => entry && fn(entry[1], entry[0], this),

Callers 4

sortMethod · 0.90
sortByMethod · 0.90
groupByFactoryFunction · 0.90
toOrderedMapFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected