dynamic-forms / Class

EventBus

Decorators:@Injectable

Event bus service for form-wide event communication.

Provides type-safe event dispatching and subscription for form components to communicate without direct coupling. Uses RxJS observables for reactive event handling and supports both single event type and multiple event type subscriptions.

Properties

NameTypeDescription
events$
Observable<FormEvent>

Methods

dispatch()

Dispatches an event to all subscribers.

Creates an instance of the provided event constructor and broadcasts it through the event pipeline to all active subscribers.

Presentation
dispatch(eventConstructor: T, args: ConstructorParameters<T>): void;
Parameters
NameTypeDescription
eventConstructor
T

Constructor function for the event to dispatch

args
ConstructorParameters<T>
Returns
void
Example usage
// Dispatch a submit event
eventBus.dispatch(SubmitEvent);

// Dispatch a custom event
eventBus.dispatch(CustomFormEvent);

on()

Subscribes to form events with type-safe filtering.

Provides a reactive stream of events filtered by type. Supports both single event type subscriptions and multi-type subscriptions for flexible event handling.

Presentation
on(eventType: T["type"] | T["type"][]): Observable<T>;
Parameters
NameTypeDescription
eventType
T["type"] | T["type"][]

Event type string or array of event type strings to filter by

Returns
Observable<T> -

Observable stream of filtered events

Example usage
// Subscribe to a single event type
eventBus.on<SubmitEvent>('submit').subscribe(event => {
  console.log('Submit event received');
});

// Subscribe to multiple event types
eventBus.on<SubmitEvent | FormResetEvent | ValidationErrorEvent>(['submit', 'form-reset', 'validation-error']).subscribe(event => {
  switch (event.type) {
    case 'submit':
      handleSubmit();
      break;
    case 'form-reset':
      handleReset();
      break;
    case 'validation-error':
      handleValidationError();
      break;
  }
});
Overload #1

Subscribes to events of a specific type.

Presentation
on(eventType: T["type"]): Observable<T>;
Parameters
NameTypeDescription
eventType
T["type"]

The type of event to subscribe to

Returns
Observable<T> -

Observable that emits events of the specified type

Overload #2

Subscribes to events of multiple types.

Presentation
on(eventType: T["type"][]): Observable<T>;
Parameters
NameTypeDescription
eventType
T["type"][]

Array of event types to subscribe to

Returns
Observable<T> -

Observable that emits events matching any of the specified types

Example usage