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
Observable
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
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
The instance of the Observable for chaining.
Defined in
packages/core/src/event/Observable.ts:23
init
▸ init(): Observable
Initializes the observable.
Returns
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
Name | Type |
---|---|
E | extends keyof DispatcherEventsMap |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event to be registered as persistent. This can be a key from the DispatcherEventsMap or any string. |
Returns
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
Name | Type |
---|---|
E | extends keyof DispatcherEventsMap |
Parameters
Name | Type | Description |
---|---|---|
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
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
Name | Type |
---|---|
E | extends keyof DispatcherEventsMap |
Parameters
Name | Type | Description |
---|---|---|
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
The current instance for chaining.