duoyun-ui
Version: 
A lightweight desktop UI component library, implemented using Gem
23 lines • 639 B
JavaScript
export class StringWeakMap {
    #map = new Map();
    #weakMap = new WeakMap();
    #registry = new FinalizationRegistry((key) => this.#map.delete(key));
    set(key, val) {
        this.#map.set(key, new WeakRef(val));
        this.#weakMap.set(val, key);
        this.#registry.register(val, key);
    }
    get(key) {
        return this.#map.get(key)?.deref();
    }
    findKey(val) {
        return this.#weakMap.get(val);
    }
    *[Symbol.iterator]() {
        const entries = this.#map.entries();
        for (const [tag, ref] of entries) {
            yield [tag, ref.deref()];
        }
    }
}
//# sourceMappingURL=map.js.map