Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/lib. A collection of common utilities I need. www.npmjs.com/package/@samual/lib
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334export class AutoMap<K, V> extends Map<K, V> { constructor(private readonly fallbackHandler: (key: K) => V) { super() }
override get(key: K): V { if (super.has(key)) return super.get(key)!
const value = this.fallbackHandler(key)
super.set(key, value)
return value }}
export class AutoWeakMap<K extends object, V> extends WeakMap<K, V> { constructor(private readonly fallbackHandler: (key: K) => V) { super() }
override get(key: K): V { if (super.has(key)) return super.get(key)!
const value = this.fallbackHandler(key)
super.set(key, value)
return value }}