|
|
@ -57,7 +57,7 @@ export class SvelteMap extends Map {
|
|
|
|
#sources = new Map();
|
|
|
|
#sources = new Map();
|
|
|
|
#version = state(0);
|
|
|
|
#version = state(0);
|
|
|
|
#size = state(0);
|
|
|
|
#size = state(0);
|
|
|
|
/**@type {Reaction | null} */
|
|
|
|
/**@type {WeakRef<Reaction> | null} */
|
|
|
|
#initial_reaction = null;
|
|
|
|
#initial_reaction = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -67,12 +67,10 @@ export class SvelteMap extends Map {
|
|
|
|
super();
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
|
|
if (active_reaction !== null) {
|
|
|
|
if (active_reaction !== null) {
|
|
|
|
this.#initial_reaction = active_reaction;
|
|
|
|
// we use a WeakRef (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
|
|
|
|
// since we only need `initial_reaction` as long as we are in a derived/effect we can
|
|
|
|
// so that if this Map is somehow stored outside of the active reaction,
|
|
|
|
// safely create a teardown function that will reset it to null and allow for GC
|
|
|
|
// it will not prevent the reaction from being garbage collected.
|
|
|
|
teardown(() => {
|
|
|
|
this.#initial_reaction = new WeakRef(active_reaction);
|
|
|
|
this.#initial_reaction = null;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (DEV) {
|
|
|
|
if (DEV) {
|
|
|
@ -101,7 +99,7 @@ export class SvelteMap extends Map {
|
|
|
|
* @returns {Source<T>}
|
|
|
|
* @returns {Source<T>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#source(value) {
|
|
|
|
#source(value) {
|
|
|
|
if (this.#initial_reaction === active_reaction) {
|
|
|
|
if (this.#initial_reaction !== null && this.#initial_reaction.deref() === active_reaction) {
|
|
|
|
return state(value);
|
|
|
|
return state(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return source(value);
|
|
|
|
return source(value);
|
|
|
|