Registry

Param: name

The name of the registry.

Param: idField

The field to use as the ID of items in the registry.

Param: mode

The mode of the registry.

Type Parameters

  • ItemT extends object = object

Constructors

Properties

__banned: IDRegistry

The items that are currently banned.

__idField: string

The field to use as the ID of items in the registry.

The mode of the registry.

__name: string

The name of the registry.

__protected: IDRegistry

The items that are currently protected.

__registered: ItemT[]

The items that are currently registered.

__subscribers: SubscriberRegistry

The subscribers to the registry.

__unregister: IDRegistry

The items that are currently unregistered.

MODES: typeof RegistryModes = RegistryModes

An enumeration of the modes that a registry can be in.

Accessors

  • get listById(): {
        [key: string]: ItemT;
    }
  • Gets the list of items in the registry by ID.

    Returns {
        [key: string]: ItemT;
    }

    The items in the registry, indexed by ID. This list only includes items that are currently active in the registry (i.e., not banned or unregistered).

Methods

  • Subscribes a callback function to notifications from the registry.

    Parameters

    • cb: Subscriber<ItemT>

      The callback function to subscribe.

    • Optional id: string

      The ID to associate with the subscription. If not provided, a new UUID will be generated.

    Returns (() => void)

    A function that, when called, will unsubscribe the callback function from the registry.

      • (): void
      • Returns void

  • Unregisters an item from the registry.

    Parameters

    • id: string

      The ID of the item to unregister.

    Returns this

    The registry instance.

    Throws

    If the item is protected.

    Emits

    Notification of type NotificationTypes.UNREGISTER When an item is unregistered.

    If the registry is in Registry.MODES.CLEAN, the item is immediately removed and the cleanup method is called. If the registry is in Registry.MODES.DEFAULT, the item is marked for unregistration but not immediately removed.

  • Subscribes a callback function to notifications from the registry.

    Parameters

    • Optional id: string

      The ID to associate with the subscription. If not provided, a new UUID will be generated.

    Returns void

    A function that, when called, will unsubscribe the callback function from the registry.