diff --git a/src/utils/settings.ts b/src/utils/settings.ts index c4a370e..a5bc9d8 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -1,9 +1,36 @@ 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 { + // Our own internal StorageManager so things never interfere #storageManager: StoreManager<"radius||settings">; 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() { function *get() { for (const instance of Settings.#instance.keys()) { @@ -25,7 +52,18 @@ class Settings { await ready(); 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) { this.#storageManager.setVal('theme', theme || this.#storageManager.getVal('theme')); theme === 'default'