Class: EventsPlugin
Defined in: src/wirestate-core/plugin/events/events-plugin.ts:28
Enables event messaging on a container.
Remarks
Register it (new Container({ plugins: [new EventsPlugin()] })) to bind the EventBus and wire @OnEvent handlers at provision. Importing this class is what pulls the event bus into the bundle.
A child container can register its own EventsPlugin for a local bus, or omit it to use the nearest ancestor bus.
Example
import { Container, EventsPlugin, Injectable } from "@wirestate/core";
@Injectable()
class CartService {}
const container = new Container({ bindings: [CartService], plugins: [new EventsPlugin()] });Extends
MessagingPlugin
Constructors
Constructor
new EventsPlugin(): EventsPlugin;Defined in: src/wirestate-core/plugin/events/events-plugin.ts:29
Returns
EventsPlugin
Overrides
MessagingPlugin.constructorMethods
install()
install(container: Container): void;Defined in: src/wirestate-core/plugin/messaging-plugin.ts:39
Contributes bindings (or other one-time setup) when the plugin is registered.
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container the plugin is registered on. |
Returns
void
Remarks
Runs once, on the container the plugin is registered on (not on inheriting children), before any binding activates.
Register cleanup for install-time side effects with addRollback. Rollbacks run in reverse order if this or a later install throws, or if container construction fails afterwards. They are failsafe and do not run during normal container teardown.
Inherited from
MessagingPlugin.installonProvision()
onProvision(
instance: object,
container: Container,
addDisposer: (dispose: () => void) => void): void;Defined in: src/wirestate-core/plugin/messaging-plugin.ts:57
Wires a provisioned instance, before any user @OnProvision.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The provisioned instance. |
container | Container | Container being provisioned. |
addDisposer | (dispose: () => void) => void | Registers a teardown callback for this provision cycle. |
Returns
void
Remarks
Register teardown with addDisposer. Disposers run (reverse order, failsafe) at deprovision. A throw here unwinds the whole provision cycle.
Inherited from
MessagingPlugin.onProvisionparticipates()
participates(token: ServiceToken): boolean;Defined in: src/wirestate-core/plugin/messaging-plugin.ts:47
Declares whether a binding token is a participant this plugin wires.
Parameters
| Parameter | Type | Description |
|---|---|---|
token | ServiceToken | Binding token to inspect. |
Returns
boolean
Whether the plugin participates in this token.
Remarks
Token/class-level so it can drive force-activation: a token this returns true for is resolved (activated) at provision even if nothing injected it, and the instance is then delivered to WirestatePlugin.onProvision. Omit for a pure observer that force-activates nothing.
Inherited from
MessagingPlugin.participates