Class SettingsManager<T, D>

Manages settings for a given namespace.

This class should not be instantiated directly; use init() for convenience and reliability.

The load() method copies the namespaces' settings data from the file system into the manager. All communication between a SettingsManager and the file system occurs asynchronously over IPC.

Once the settings data has been copied into the SettingsManager, it can be read and written synchronously. The SettingsManager automatically queues and dispatches updates to the file system in the background.

Type Parameters

  • T extends Record<string, Jsonifiable>

  • D extends keyof T

Hierarchy

  • SettingsManager

Constructors

  • Creates a SettingsManager. This does not load any settings from storage; call the load() method before attempting to manage any settings.

    Prefer calling init over constructing instances of this class directly, as init() automatically loads settings from the file system.

    Type Parameters

    • T extends Record<string, Jsonifiable>

    • D extends string | number | symbol

    Parameters

    • namespace: string

      Namespace of settings to manage.

    • defaultSettings: Partial<T> = {}

    Returns SettingsManager<T, D>

Properties

#defaultSettings: Partial<T>
#queuedUpdates: Map<Extract<keyof T, string>, SettingsUpdate<T>>
#saveTimeout: undefined | Timeout
#settings: undefined | T
namespace: string

Namespace for these settings.

Methods

  • Type Parameters

    • K extends string

    Parameters

    • key: K
    • update: SettingsUpdate<T>

    Returns void

  • Returns a copy of the settings data stored in this manager.

    Returns T

    Current values of all settings in this manager's namespace.

  • Deletes a setting.

    Parameters

    • key: Extract<keyof T, string>

      Key of the setting to delete.

    Returns boolean

    Whether the setting was successfully deleted.

  • Gets a setting.

    Type Parameters

    • K extends string

    • F extends undefined | Jsonifiable

    Parameters

    • key: K

      Key of the setting to retrieve.

    • Optional fallback: F

      Value to return if the key does not already exist.

    Returns K extends D
        ? NonNullable<T[K]>
        : F extends undefined | null
            ? undefined | T[K]
            : F | NonNullable<T[K]>

  • Determines whether a setting exists for this namespace.

    Parameters

    • key: Extract<keyof T, string>

      Key to look for.

    Returns boolean

    Whether the setting already exists for this namespace.

  • Loads the latest stored settings for this namespace from the user's file system into this manager. This must be called before managing any settings, unless you have created an instance using init(), which calls this method.

    Returns Promise<void>

  • Sets a setting.

    Type Parameters

    • K extends string

    Parameters

    • key: K

      Key of the setting to set.

    • value: T[K]

      Value to set for the setting.

    Returns void

Generated using TypeDoc