Interface Config<T>

Config interface. Instances are returned by the Dynasty#config method.

interface Config<T> {
    get isLocked(): boolean;
    all(): Dependency<T>;
    get<const K>(key: K): Dependency<Readonly<T[K]>>;
    has<const K>(key: K): boolean;
    lock(): this;
    replace(config: Readonly<T>): this;
    select<R>(selector: Selector<T, R>): Dependency<Readonly<R>>;
    set<const K>(key: K, value: T[K]): this;
    unlock(): this;
    update(config: Readonly<Partial<T>>): this;
}

Type Parameters

  • T extends Readonly<UnknownRecord>

    The user supplied configuration record type.

Accessors

  • get isLocked(): boolean
  • Is the configuration locked?

    Returns boolean

Methods

  • Get the entire configuration as a dependency.

    Returns Dependency<T>

    The dependency for the entire configuration. A shallow copy is made.

  • Get the configuration value by key.

    Type Parameters

    • const K extends string | number | symbol

    Parameters

    • key: K

      The key of the configuration value. This must be keyof T.

    Returns Dependency<Readonly<T[K]>>

  • Does the configuration have a given key?

    Type Parameters

    • const K extends string | number | symbol

    Parameters

    • key: K

      The key to check. This must be keyof T.

    Returns boolean

    True if the key exists in the configuration.

  • Lock the configuration. Attempts to update the configuration after this will throw.

    Returns this

    Fluent interface.

  • Replace the configuration.

    Parameters

    • config: Readonly<T>

      Full configuration to replace the current configuration with. A shallow copy is made.

    Returns this

    Fluent interface.

  • Select a configuration value as a dependency using a selector.

    Type Parameters

    • R

      The return type from the selector.

    Parameters

    • selector: Selector<T, R>

      The selector function to get the configuration value.

    Returns Dependency<Readonly<R>>

    The dependency for the configuration value.

  • Set a configuration value by key.

    Type Parameters

    • const K extends string | number | symbol

    Parameters

    • key: K

      The key of the configuration value. This must be keyof T.

    • value: T[K]

      The value to set.

    Returns this

    Boolean indicating if the value was set.

  • Unlock the configuration.

    Returns this

    Fluent interface.

  • Update the configuration.

    Parameters

    • config: Readonly<Partial<T>>

      Partial configuration to merge into the configuration.

    Returns this

    Fluent interface.