Skip to main content

Class: abstract Observable

Defined in: packages/core/src/event/Observable.ts:8

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.

Extended by

Constructors

new Observable()

new Observable(): Observable

Returns

Observable

Methods

clear()

clear(): Observable

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

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.


destroy()

destroy(): Observable

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

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

Returns

Observable

The instance of the Observable for chaining.


init()

init(): Observable

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

Initializes the observable.

Returns

Observable

The instance of the Observable for chaining.


registerPersistenEvent()

registerPersistenEvent<E>(event): this

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

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

Type Parameters

E extends keyof DispatcherEventsMap

Parameters

event

E

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

Returns

this

The instance of the Observable for chaining.


subscribe()

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

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

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

E extends keyof DispatcherEventsMap

Parameters

event

E

The event to subscribe to.

observer

DispatcherListener<any>

The observer function to be called when the event is dispatched.

scope?

unknown

The scope in which the observer function should be executed. This is optional.

Returns

this

The instance of the Observable for chaining.


unsubscribe()

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

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

Unsubscribes an observer from a specific event.

Type Parameters

E extends keyof DispatcherEventsMap

Parameters

event

E

The event name or key from the DispatcherEventsMap.

observer

DispatcherListener<any>

The observer (listener) to be unsubscribed.

scope?

unknown

Optional scope to be used for the observer.

Returns

this

The current instance for chaining.