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.
123456789101112131415161718192021222324252627282930313233343536export class DynamicMap<K, V> extends Map<K, V> { constructor(private readonly fallbackHandler: (key: K) => V) { super() }
override get(key: K) { if (super.has(key)) return super.get(key)!
const value = this.fallbackHandler(key)
super.set(key, value)
return value }}
export default DynamicMap
export class DynamicWeakMap<K extends object, V> extends WeakMap<K, V> { constructor(private readonly fallbackHandler: (key: K) => V) { super() }
override get(key: K) { if (super.has(key)) return super.get(key)!
const value = this.fallbackHandler(key)
super.set(key, value)
return value }}