@rhombus-toolkit/collections 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/index.d.ts +1 -0
- package/dist/bundle/index.js +15 -11
- package/package.json +1 -1
package/dist/bundle/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ declare class ImmutableLinkedList<T> implements Iterable<T> {
|
|
|
30
30
|
|
|
31
31
|
declare class KindaWeakMap<K, V extends WeakKey> {
|
|
32
32
|
#private;
|
|
33
|
+
/** An existing key keeps its place in iteration order, as with `Map`. */
|
|
33
34
|
set(key: K, value: V): this;
|
|
34
35
|
delete(key: K): boolean;
|
|
35
36
|
get(key: K): V | undefined;
|
package/dist/bundle/index.js
CHANGED
|
@@ -60,25 +60,29 @@ function tailOf(link) {
|
|
|
60
60
|
// src/KindaWeakMap.ts
|
|
61
61
|
class KindaWeakMap {
|
|
62
62
|
#map = new Map;
|
|
63
|
-
#registry = new FinalizationRegistry((key) => {
|
|
64
|
-
if (this.#map.get(key)
|
|
63
|
+
#registry = new FinalizationRegistry(({ key, ref }) => {
|
|
64
|
+
if (this.#map.get(key) === ref) {
|
|
65
65
|
this.#map.delete(key);
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
set(key, value) {
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
const held = this.#map.get(key);
|
|
70
|
+
if (held) {
|
|
71
|
+
this.#registry.unregister(held);
|
|
72
|
+
}
|
|
73
|
+
const ref = new WeakRef(value);
|
|
74
|
+
this.#registry.register(value, { key, ref }, ref);
|
|
75
|
+
this.#map.set(key, ref);
|
|
72
76
|
return this;
|
|
73
77
|
}
|
|
74
78
|
delete(key) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
if (value === undefined) {
|
|
79
|
+
const held = this.#map.get(key);
|
|
80
|
+
if (!held) {
|
|
78
81
|
return false;
|
|
79
82
|
}
|
|
80
|
-
this.#
|
|
81
|
-
|
|
83
|
+
this.#map.delete(key);
|
|
84
|
+
this.#registry.unregister(held);
|
|
85
|
+
return held.deref() !== undefined;
|
|
82
86
|
}
|
|
83
87
|
get(key) {
|
|
84
88
|
return this.#map.get(key)?.deref();
|
|
@@ -87,7 +91,7 @@ class KindaWeakMap {
|
|
|
87
91
|
return this.get(key) !== undefined;
|
|
88
92
|
}
|
|
89
93
|
clear() {
|
|
90
|
-
this.
|
|
94
|
+
this.#map.forEach((ref) => this.#registry.unregister(ref));
|
|
91
95
|
this.#map.clear();
|
|
92
96
|
}
|
|
93
97
|
forEach(callbackfn, thisArg) {
|
package/package.json
CHANGED