Function Observe

  • Prototype property decorator factory. Applying this decorator replaces the decorated property with a getter returning an Observable stream which Observes all values originating from the supplied handle. Depending on the value of the suffix parameter, this Observable stream is either assigned directly to the prototype using the supplied handle, or, if a truthy value is supplied for the suffix parameter, this value is assumed to reference another property of the class containing this decorated property. The first truthy value assigned to this suffix property on an instance of the class containing this Stream decorator will then be used to suffix the supplied handle which is to be Observed and assign the resulting Observable stream to the decorated instance property.

    This decorator is more or less the opposite of the Publish decorator, while both rely on the BusHandler to fulfill contracts.

    Parameters

    • handle: Handle

      The Bus.Handle to Observe.

    • Optional suffix: PropertyKey

      An optional suffix property for the handle.

    Returns ((prototype, propertyKey) => void)

    A prototype property decorator.

      • (prototype, propertyKey): void
      • Parameters

        • prototype: object
        • propertyKey: PropertyKey

        Returns void

    Example

    Observe the 'io.github.sgrud.example' stream:

    import { type Bus, Observe } from '@sgrud/bus';
    import { type Observable } from 'rxjs';

    export class Observer {

    ⁠@Observe('io.github.sgrud.example')
    public readonly stream!: Observable<Bus.Value<unknown>>;

    }

    Observer.prototype.stream.subscribe(console.log);

    Example

    Observe the 'io.github.sgrud.example' stream:

    import { type Bus, Observe } from '@sgrud/bus';
    import { type Observable } from 'rxjs';

    export class Observer {

    ⁠@Observe('io.github.sgrud', 'suffix')
    public readonly stream!: Observable<Bus.Value<unknown>>;

    public constructor(
    public readonly suffix: string
    ) { }

    }

    const observer = new Observer('example');
    observer.stream.subscribe(console.log);

    See

Generated using TypeDoc