Skip to content

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

typescript
import { Container, EventsPlugin, Injectable } from "@wirestate/core";

@Injectable()
class CartService {}

const container = new Container({ bindings: [CartService], plugins: [new EventsPlugin()] });

Extends

  • MessagingPlugin

Accessors

handles

Get Signature

ts
get handles(): readonly symbol[];

Defined in: src/wirestate-core/plugin/messaging-plugin.ts:23

Messaging-handler kinds this plugin owns (advanced).

Remarks

Used by the built-in messaging plugins. Provision matches declared handler metadata against the union of registered plugins' kinds and throws on a kind no plugin handles. A nearer plugin owning a kind shadows an ancestor's of the same kind. Observer plugins usually omit this field.

Returns

readonly symbol[]

Inherited from

ts
MessagingPlugin.handles

Constructors

Constructor

ts
new EventsPlugin(): EventsPlugin;

Defined in: src/wirestate-core/plugin/events/events-plugin.ts:29

Returns

EventsPlugin

Overrides

ts
MessagingPlugin.constructor

Methods

install()

ts
install(container: Container): void;

Defined in: src/wirestate-core/plugin/messaging-plugin.ts:27

Contributes bindings (or other one-time setup) when the plugin is registered.

Parameters

ParameterTypeDescription
containerContainerContainer 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.

Inherited from

ts
MessagingPlugin.install

onProvision()

ts
onProvision(
   instance: object, 
   container: Container, 
   addDisposer: (dispose: () => void) => void): void;

Defined in: src/wirestate-core/plugin/messaging-plugin.ts:45

Wires a provisioned instance, before any user @OnProvision.

Parameters

ParameterTypeDescription
instanceobjectThe provisioned instance.
containerContainerContainer being provisioned.
addDisposer(dispose: () => void) => voidRegisters 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

ts
MessagingPlugin.onProvision

participates()

ts
participates(token: ServiceToken): boolean;

Defined in: src/wirestate-core/plugin/messaging-plugin.ts:35

Declares whether a binding token is a participant this plugin wires.

Parameters

ParameterTypeDescription
tokenServiceTokenBinding 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

ts
MessagingPlugin.participates