Class: ObservableImpl
@ima/core.ObservableImpl
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.
Remarks
- The Observable class relies on a Dispatcher to handle the actual event distribution.
- It maintains a history of events, which can be limited by a maximum history length.
Hierarchy
↳
ObservableImpl
Constructors
constructor
• new ObservableImpl(dispatcher
, settings?
)
Creates an instance of Observable.
Parameters
Name | Type | Description |
---|---|---|
dispatcher | Dispatcher | The dispatcher responsible for managing event listeners. |
settings? | Object | Optional settings for the Observable instance. |
settings.maxHistoryLength? | number | - |
Overrides
Defined in
packages/core/src/event/ObservableImpl.ts:40
Properties
_activityHistory
• Protected
_activityHistory: Map
<string
, unknown
[]>
Defined in
packages/core/src/event/ObservableImpl.ts:25
_dispatcher
• Protected
_dispatcher: Dispatcher
Defined in
packages/core/src/event/ObservableImpl.ts:23
_observers
• Protected
_observers: Map
<string
, Map
<DispatcherListener
<any
>, Set
<unknown
>>>
Defined in
packages/core/src/event/ObservableImpl.ts:24
_persistentEvents
• Protected
_persistentEvents: Set
<string
>
Defined in
packages/core/src/event/ObservableImpl.ts:26
_settings
• Protected
_settings: undefined
| { maxHistoryLength?
: number
}
Defined in
packages/core/src/event/ObservableImpl.ts:27
$dependencies
▪ Static
$dependencies: Dependencies
Defined in
packages/core/src/event/ObservableImpl.ts:29
Methods
_handleDispatcherEvent
▸ _handleDispatcherEvent(event
, data
): void
Handles dispatcher events by updating the activity history and notifying observers.
It also resets the activity history for non-persistent events on BEFORE_HANDLE_ROUTE
ecvent.
Parameters
Name | Type | Description |
---|---|---|
event | string | The name of the event being dispatched. |
data | any | The data associated with the event. |
Returns
void
Defined in
packages/core/src/event/ObservableImpl.ts:148
clear
▸ clear(): ObservableImpl
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.
Overrides
Defined in
packages/core/src/event/ObservableImpl.ts:72
destroy
▸ destroy(): ObservableImpl
Destroys the observable by clearing its internal state and removing all event listeners.
Returns
The instance of the Observable for chaining.
Overrides
Defined in
packages/core/src/event/ObservableImpl.ts:62
init
▸ init(): ObservableImpl
Initializes the observable.
Returns
The instance of the Observable for chaining.
Overrides
Defined in
packages/core/src/event/ObservableImpl.ts:52
registerPersistenEvent
▸ registerPersistenEvent(event
): ObservableImpl
Registers an event as persistent, meaning its history won't be cleared upon calling the clear
method (route change).
Parameters
Name | Type | Description |
---|---|---|
event | string | 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.
Overrides
Observable.registerPersistenEvent
Defined in
packages/core/src/event/ObservableImpl.ts:83
subscribe
▸ subscribe(event
, observer
, scope?
): ObservableImpl
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.
Parameters
Name | Type | Description |
---|---|---|
event | string | 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.
Overrides
Defined in
packages/core/src/event/ObservableImpl.ts:92
unsubscribe
▸ unsubscribe(event
, observer
, scope?
): ObservableImpl
Unsubscribes an observer from a specific event.
Parameters
Name | Type | Description |
---|---|---|
event | string | 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.