Options
All
  • Public
  • Public/Protected
  • All
Menu

Stores and manages mutable program state that can change at runtime and persists between page reloads. Allows watchers to be notified when data changes.

Hierarchy

  • Settings

Index

Constructors

constructor

  • new Settings(prefix: string): Settings
  • Parameters

    • prefix: string

      An arbitrary but unique string without underscores that represents this specific settings object

    Returns Settings

Properties

Private data

data: Map<string, unknown>

Private watchers

watchers: Map<string, ((newValue: unknown) => void)[]>

Methods

addWatcher

  • addWatcher(dataId: string, watcher: (newValue: unknown) => void, callOnAdd?: boolean): void
  • Register a function to call when certain data changes

    Parameters

    • dataId: string

      ID to watch for changes on

    • watcher: (newValue: unknown) => void

      Function to call when data changes

        • (newValue: unknown): void
        • Parameters

          • newValue: unknown

          Returns void

    • callOnAdd: boolean = true

      If true, calls the watcher immediately after registering it

    Returns void

getAllSettingNames

  • getAllSettingNames(): string[]
  • Get all setting IDs

    Returns string[]

getData

  • getData(id: string): Option<unknown>
  • See the current value associated with an ID. However, addWatcher should be used instead when possible.

    Parameters

    • id: string

    Returns Option<unknown>

Protected loadSavedData

  • loadSavedData(): void
  • Loads data saved from a previous page load into this instance by the prefix, if data is available

    Returns void

removeWatcher

  • removeWatcher(dataId: string, watcher: (newValue: unknown) => void): void
  • Unregister a watcher so it is no longer called when certain data is updated

    Parameters

    • dataId: string
    • watcher: (newValue: unknown) => void
        • (newValue: unknown): void
        • Parameters

          • newValue: unknown

          Returns void

    Returns void

setDefault

  • setDefault(id: string, defaultValue: unknown): void
  • Sets an initial value for data only if the data wasn't already initialized, such as by loadSavedData

    Parameters

    • id: string
    • defaultValue: unknown

    Returns void

updateData

  • updateData(id: string, data: unknown): void
  • Sets the data stored at id to the new data. Calls relevant watchers.

    Parameters

    • id: string
    • data: unknown

    Returns void

Generated using TypeDoc