Function Stream

  • Prototype property decorator factory. Applying this decorator replaces the decorated property with a getter returning a Bus, thereby allowing to duplex Stream values designated by the supplied handle. Depending on the value of the suffix parameter, this Bus 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 upon construction of the Bus, which is assigned to the decorated instance property.

    Through these two different modes of operation, a Bus can be assigned statically to the prototype of the class containing the decorated property, or this assignment can be deferred until an instance of the class containing the decorated property is constructed and a truthy value is assigned to its suffix property.

    Parameters

    • handle: Handle

      The Bus.Handle to Stream.

    • 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

    Stream 'io.github.sgrud.example':

    import { type Bus, Stream } from '@sgrud/bus';

    export class Streamer {

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

    }

    Streamer.prototype.stream.next('value');
    Streamer.prototype.stream.complete();

    Streamer.prototype.stream.subscribe({
    next: console.log
    });

    Example

    Stream 'io.github.sgrud.example':

    import { type Bus, Stream } from '@sgrud/bus';

    export class Streamer {

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

    public constructor(
    public readonly suffix: string
    ) { }

    }

    const streamer = new Streamer('example');
    streamer.stream.next('value');
    streamer.stream.complete();

    streamer.stream.subscribe({
    next: console.log
    });

    See

Generated using TypeDoc