@lppedd/message-bus - v0.2.0
    Preparing search index...

    Function AutoSubscribe

    • Class decorator that automatically subscribes to topics based on method parameter decorators.

      This decorator inspects the decorated class looking for methods with topic-decorated parameters, and subscribes to those topics using the provided messageBus.

      When a message is published, the decorated parameter's method is invoked with the message data. If the class instance is garbage collected, the topic subscription is automatically disposed.

      Type Parameters

      Parameters

      • messageBus: MessageBus | (() => MessageBus)

        The message bus instance to use for creating subscriptions.

      • OptionalonTransformedClass: (transformedClass: Ctor, originalClass: Ctor) => void

        An optional callback invoked with the class created by this decorator (transformedClass) and the original class (originalClass). Useful for registering the new class externally.

      Returns ClassDecorator

      const messageBus = createMessageBus();

      @AutoSubscribe(messageBus)
      class UserManager {
      onUserLogin(@LoginTopic login: UserLogin): void {
      // ...
      }
      }