Hex Core JS
    Preparing search index...

    Class Publisher<T>

    Class implementing the Publisher-Subscriber pattern. Allows for publishing and subscribing to messages.

    Type Parameters

    • T
    Index

    Constructors

    Methods

    • Shut down the publisher

      Returns void

    • Notifies all subscribers of an error and shuts down the publisher.

      Parameters

      • exception: any

        the exception which occurred

      Returns void

    • Allows for subscribing only to values which meet given criteria. Should only be called in conjunction with subscribe. For example

      const publisher = new Publisher<number>();
      publisher.filter((x) => x < 50).subscribe({
      next: (value: number) => {
      console.log(value, "is less than 50");
      }
      })

      Parameters

      • predicate: (value: T) => boolean

        the predicate determining if subscribers should be notified

      Returns Observable<T>

    • Allows for subscribing only to values of a given subtype the published type Should only be called in conjunction with subscribe. For example

      type First = "first";
      type Second = "second";
      type Option = First | Second;

      function isFirst(value: Options): value is First { ... }

      const publisher = new Publisher<Option>();
      publisher.filterType(isFirst).subscribe({
      next: (value: First) => {
      console.log(value, "is of a subtype of option");
      }
      })

      Type Parameters

      • U

      Parameters

      • guard: (value: T) => value is U

      Returns Observable<U>

    • Emits, or publishes data to all subscribers

      Parameters

      • value: T

        value to emit

      Returns void

    • Attaches a new subscription to the publisher For example

      const publisher = new Publisher<number>();
      publisher.subscribe({
      next: (value: number) => {
      console.log(value);
      }
      })

      Parameters

      • observer: Observer<T>

        an object with at least a next method which is called whenever the publisher publishes new data

      Returns Subscription<T>