Loads of JSDoc
This commit is contained in:
+39
-1
@@ -1,9 +1,36 @@
|
|||||||
import { StoreManager } from "./storage";
|
import { StoreManager } from "./storage";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The settings class
|
||||||
|
* Initializes it's own StorageManager, and handles everything within the class itself
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Create a new Settings instance (needs to be done only once)
|
||||||
|
* import { Settings } from "@utils/settings.ts";
|
||||||
|
* const settings = new Settings();
|
||||||
|
* //Consume any of the methods with:
|
||||||
|
* settings.methodName();
|
||||||
|
*
|
||||||
|
* // Most of the time, you'll want to get the running instance this can be done with
|
||||||
|
* import { Settings } from "@utils/settings.ts";
|
||||||
|
* const settings = await Settings.getInstance();
|
||||||
|
* //Consume any of the methods with:
|
||||||
|
* settings.methodName();
|
||||||
|
*/
|
||||||
class Settings {
|
class Settings {
|
||||||
|
// Our own internal StorageManager so things never interfere
|
||||||
#storageManager: StoreManager<"radius||settings">;
|
#storageManager: StoreManager<"radius||settings">;
|
||||||
static #instance = new Set();
|
static #instance = new Set();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to get the current or other Settings instance(s)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const settings = await Settings.getInstance();
|
||||||
|
* // Consume the other methods
|
||||||
|
*/
|
||||||
static async getInstance() {
|
static async getInstance() {
|
||||||
function *get() {
|
function *get() {
|
||||||
for (const instance of Settings.#instance.keys()) {
|
for (const instance of Settings.#instance.keys()) {
|
||||||
@@ -25,7 +52,18 @@ class Settings {
|
|||||||
await ready();
|
await ready();
|
||||||
return get().next().value! as Settings;
|
return get().next().value! as Settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set's the theme either to the current theme OR to a new one
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Retrieve the Settings instance
|
||||||
|
* const settings = await Settings.getInstance();
|
||||||
|
*
|
||||||
|
* // Consume the method
|
||||||
|
* settings.theme() // Whatever value is in localstorage at the time
|
||||||
|
* settings.theme('theme name') // A new theme based off of the class name
|
||||||
|
*/
|
||||||
theme(theme?: string) {
|
theme(theme?: string) {
|
||||||
this.#storageManager.setVal('theme', theme || this.#storageManager.getVal('theme'));
|
this.#storageManager.setVal('theme', theme || this.#storageManager.getVal('theme'));
|
||||||
theme === 'default'
|
theme === 'default'
|
||||||
|
|||||||
Reference in New Issue
Block a user