Skip to main content

Class: Observable

@ima/core.Observable

An Observable is a class that manages event listeners and allows distributing events to the registered listeners. It maintains a history of events and supports persistent events that are not cleared during route changes.

Hierarchy

Constructors

constructor

new Observable()

Methods

clear

clear(): Observable

Clears all persistent events, observers, and activity history from the observable.

This method will remove all stored events, registered observers, and any recorded activity history, effectively resetting the observable to its initial state.

Returns

Observable

The instance of the Observable for chaining.

Defined in

packages/core/src/event/Observable.ts:35


destroy

destroy(): Observable

Destroys the observable by clearing its internal state and removing all event listeners.

Returns

Observable

The instance of the Observable for chaining.

Defined in

packages/core/src/event/Observable.ts:23


init

init(): Observable

Initializes the observable.

Returns

Observable

The instance of the Observable for chaining.

Defined in

packages/core/src/event/Observable.ts:14


registerPersistenEvent

registerPersistenEvent<E>(event): Observable

Registers an event as persistent, meaning its history won't be cleared upon calling the clear method (route change).

Type parameters

NameType
Eextends keyof DispatcherEventsMap

Parameters

NameTypeDescription
eventEThe name of the event to be registered as persistent. This can be a key from the DispatcherEventsMap or any string.

Returns

Observable

The instance of the Observable for chaining.

Defined in

packages/core/src/event/Observable.ts:45


subscribe

subscribe<E>(event, observer, scope?): Observable

Subscribes an observer to a specific event. When the event is dispatched, the observer will be notified and executed within the provided scope. If the event has already occurred, the observer will be immediately invoked with the historical data.

Type parameters

NameType
Eextends keyof DispatcherEventsMap

Parameters

NameTypeDescription
eventEThe event to subscribe to.
observerDispatcherListener<any>The observer function to be called when the event is dispatched.
scope?unknownThe scope in which the observer function should be executed. This is optional.

Returns

Observable

The instance of the Observable for chaining.

Defined in

packages/core/src/event/Observable.ts:63


unsubscribe

unsubscribe<E>(event, observer, scope?): Observable

Unsubscribes an observer from a specific event.

Type parameters

NameType
Eextends keyof DispatcherEventsMap

Parameters

NameTypeDescription
eventEThe event name or key from the DispatcherEventsMap.
observerDispatcherListener<any>The observer (listener) to be unsubscribed.
scope?unknownOptional scope to be used for the observer.

Returns

Observable

The current instance for chaining.

Defined in

packages/core/src/event/Observable.ts:80