The Bus.Handle to Publish.
Optional
suffix: PropertyKeyAn optional suffix
property for the handle
.
A prototype property decorator.
Publish the 'io.github.sgrud.example'
stream:
import { Publish } from '@sgrud/bus';
import { type Subject } from 'rxjs';
export class Publisher {
@Publish('io.github.sgrud.example')
public readonly stream!: Subject<unknown>;
}
Publisher.prototype.stream.next('value');
Publisher.prototype.stream.complete();
Publish the 'io.github.sgrud.example'
stream:
import { Publish } from '@sgrud/bus';
import { type Subject } from 'rxjs';
export class Publisher {
@Publish('io.github.sgrud', 'suffix')
public readonly stream: Subject<unknown>;
public constructor(
private readonly suffix: string
) {}
}
const publisher = new Publisher('example');
publisher.stream.next('value');
publisher.stream.complete();
Generated using TypeDoc
Prototype property decorator factory. This decorator Publishes a newly instantiated Subject under the supplied
handle
and assigns it to the decorated property. Depending on the value of thesuffix
parameter, this newly instantiated Subject is either assigned directly to the prototype and Published using the suppliedhandle
, or, if a truthy value is supplied for thesuffix
parameter, this value is assumed to reference another property of the class containing this decorated property. The first truthy value assigned to thissuffix
property on an instance of the class containing this Publish decorator will then be used to suffix the suppliedhandle
upon Publishment of the newly instantiated Subject, which is assigned to the decorated instance property.Through these two different modes of operation, the Subject that will be Published 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.This decorator is more or less the opposite of the Observe decorator, while both rely on the BusHandler to fulfill contracts. Furthermore, precautions should be taken to ensure the completion of the Published Subject as memory leaks may occur due to dangling subscriptions.