* Returns the visible value for a key, caching parent hits and misses in the * current layer. * @param {K} item the key of the element to return * @returns {Cell<V>} the value of the element
(item)
| 114 | * @returns {Cell<V>} the value of the element |
| 115 | */ |
| 116 | get(item) { |
| 117 | const topValue = this.map.get(item); |
| 118 | if (topValue !== undefined) { |
| 119 | return topValue === TOMBSTONE || topValue === UNDEFINED_MARKER |
| 120 | ? undefined |
| 121 | : topValue; |
| 122 | } |
| 123 | if (this.stack.length > 1) { |
| 124 | for (let i = this.stack.length - 2; i >= 0; i--) { |
| 125 | const value = this.stack[i].get(item); |
| 126 | if (value !== undefined) { |
| 127 | this.map.set(item, value); |
| 128 | return value === TOMBSTONE || value === UNDEFINED_MARKER |
| 129 | ? undefined |
| 130 | : value; |
| 131 | } |
| 132 | } |
| 133 | this.map.set(item, TOMBSTONE); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Collapses the stacked layers into a single concrete map. |
no test coverage detected