| 32 | import assertNotInfinite from './utils/assertNotInfinite'; |
| 33 | |
| 34 | export class Map extends KeyedCollection { |
| 35 | // @pragma Construction |
| 36 | |
| 37 | constructor(value) { |
| 38 | // eslint-disable-next-line no-constructor-return |
| 39 | return value === undefined || value === null |
| 40 | ? emptyMap() |
| 41 | : isMap(value) && !isOrdered(value) |
| 42 | ? value |
| 43 | : emptyMap().withMutations((map) => { |
| 44 | const iter = KeyedCollection(value); |
| 45 | assertNotInfinite(iter.size); |
| 46 | iter.forEach((v, k) => map.set(k, v)); |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | toString() { |
| 51 | return this.__toString('Map {', '}'); |
| 52 | } |
| 53 | |
| 54 | // @pragma Access |
| 55 | |
| 56 | get(k, notSetValue) { |
| 57 | return this._root |
| 58 | ? this._root.get(0, undefined, k, notSetValue) |
| 59 | : notSetValue; |
| 60 | } |
| 61 | |
| 62 | // @pragma Modification |
| 63 | |
| 64 | set(k, v) { |
| 65 | return updateMap(this, k, v); |
| 66 | } |
| 67 | |
| 68 | remove(k) { |
| 69 | return updateMap(this, k, NOT_SET); |
| 70 | } |
| 71 | |
| 72 | deleteAll(keys) { |
| 73 | const collection = Collection(keys); |
| 74 | |
| 75 | if (collection.size === 0) { |
| 76 | return this; |
| 77 | } |
| 78 | |
| 79 | return this.withMutations((map) => { |
| 80 | collection.forEach((key) => map.remove(key)); |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | clear() { |
| 85 | if (this.size === 0) { |
| 86 | return this; |
| 87 | } |
| 88 | if (this.__ownerID) { |
| 89 | this.size = 0; |
| 90 | this._root = null; |
| 91 | this.__hash = undefined; |
no outgoing calls
no test coverage detected