* Returns an existing value for the tuple or computes, stores, and returns a * new one when the tuple is missing. * @param {[...K, (...args: K) => V]} args tuple * @returns {V} the value
(...args)
| 118 | * @returns {V} the value |
| 119 | */ |
| 120 | provide(...args) { |
| 121 | /** @type {WeakTupleMap<K, V>} */ |
| 122 | let node = this; |
| 123 | for (let i = 0; i < args.length - 1; i++) { |
| 124 | node = node._get(/** @type {ArrayElement<K>} */ (args[i])); |
| 125 | } |
| 126 | if (node._hasValue()) return /** @type {V} */ (node._getValue()); |
| 127 | const fn = /** @type {(...args: K) => V} */ (args[args.length - 1]); |
| 128 | const newValue = fn(.../** @type {K} */ (args.slice(0, -1))); |
| 129 | node._setValue(newValue); |
| 130 | return newValue; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Memoizes `compute(thisArg, ...args)` under the tuple key `[compute, |