mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
37 lines
861 B
TypeScript
37 lines
861 B
TypeScript
import type { Subscriber, Unsubscriber } from "svelte/store";
|
|
|
|
export class Standalone {
|
|
private static instance: Standalone;
|
|
private _standalone = $state(false);
|
|
private subscribers = new Set<Subscriber<boolean>>();
|
|
|
|
private constructor() {}
|
|
|
|
public static getInstance(): Standalone {
|
|
if (!Standalone.instance) {
|
|
Standalone.instance = new Standalone();
|
|
}
|
|
return Standalone.instance;
|
|
}
|
|
|
|
public setStandalone(value: boolean) {
|
|
this._standalone = value;
|
|
this.subscribers.forEach((subscriber) => subscriber(value));
|
|
}
|
|
|
|
public get standalone() {
|
|
return this._standalone;
|
|
}
|
|
|
|
public subscribe(run: Subscriber<boolean>): Unsubscriber {
|
|
this.subscribers.add(run);
|
|
run(this._standalone);
|
|
|
|
return () => {
|
|
this.subscribers.delete(run);
|
|
};
|
|
}
|
|
}
|
|
|
|
export const standalone = Standalone.getInstance();
|