Skip to content

Commit cc3bcae

Browse files
committed
small tweak
1 parent 047b557 commit cc3bcae

File tree

1 file changed

+13
-14
lines changed
  • packages/svelte/src/reactivity

1 file changed

+13
-14
lines changed

packages/svelte/src/reactivity/set.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ function get_self() {
2929
return this;
3030
}
3131

32+
let inited = false;
33+
3234
/**
3335
* @template T
3436
*/
3537
export class ReactiveSet extends Set {
36-
static #inited = false;
37-
3838
/** @type {Map<T, import('#client').Source<boolean>>} */
3939
#sources = new Map();
4040
#version = source(0);
@@ -55,24 +55,23 @@ export class ReactiveSet extends Set {
5555
}
5656
}
5757

58-
this.#init();
58+
if (!inited) this.#init();
5959
}
6060

6161
// We init as part of the first instance so that we can treeshake this class
6262
#init() {
63-
if (!ReactiveSet.#inited) {
64-
ReactiveSet.#inited = true;
65-
const proto = ReactiveSet.prototype;
66-
const set_proto = Set.prototype;
63+
inited = true;
6764

68-
for (const method of read) {
65+
const proto = ReactiveSet.prototype;
66+
const set_proto = Set.prototype;
67+
68+
for (const method of read) {
69+
// @ts-ignore
70+
proto[method] = function (...v) {
71+
get(this.#version);
6972
// @ts-ignore
70-
proto[method] = function (...v) {
71-
get(this.#version);
72-
// @ts-ignore
73-
return set_proto[method].apply(this, v);
74-
};
75-
}
73+
return set_proto[method].apply(this, v);
74+
};
7675
}
7776
}
7877

0 commit comments

Comments
 (0)