8.7 released—WinterCG Compliance Part 1
Learn more
Observable is used when you want to be notified when a change occurs. Use on/off methods to add/remove listener. Please note that should you be using the `new Observable({})` constructor, it is **obsolete** since v3.0, and you have to migrate to the "data/observable" `fromObject({})` or the `fromObjectRecursive({})` functions.

Summary

Constructors

constructor

new Observable(): Observable
Returns Observable

Properties

propertyChangeEvent

Static
propertyChangeEvent: string
String value used when hooking to propertyChange event.

Methods

_createPropertyChangeData

_createPropertyChangeData(propertyName: string, value: any, oldValue?: any): PropertyChangeData
This method is intended to be overriden by inheritors to provide additional implementation.
Parameter Default Description
propertyName
string

value
any

oldValue
any

_emit

_emit(eventNames: string): void
Parameter Default Description
eventNames
string

Returns void

addEventListener

addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void
Adds a listener for the specified event name.
Parameter Default Description
eventNames
string

Comma delimited names of the events to attach the listener to.

callback
(data: EventData) => void

A function to be called when some of the specified event(s) is raised.

thisArg
any

An optional parameter which when set will be used as "this" in callback method call.

Returns void

get

get(name: string): any
Gets the value of the specified property.
Parameter Default Description
name
string

Returns any

hasListeners

hasListeners(eventName: string): boolean
Checks whether a listener is registered for the specified event name.
Parameter Default Description
eventName
string

The name of the event to check for.

Returns boolean

notify

notify<T>(data: T): void
Notify this Observable instance with some data. This causes all event handlers on the Observable instance to be called, as well as any 'global' event handlers set on the instance's class.
Parameter Default Description
data
T

an object that satisfies the EventData interface, though with an optional 'object' property. If left undefined, the 'object' property will implicitly be set as this Observable instance.

Returns void

notifyPropertyChange

notifyPropertyChange(name: string, value: any, oldValue?: any): void
Notifies all the registered listeners for the property change event.
Parameter Default Description
name
string

value
any

oldValue
any

Returns void

off

off(eventNames: string, callback?: (data: EventData) => void, thisArg?: any): void
Shortcut alias to the removeEventListener method.
Parameter Default Description
eventNames
string

callback
(data: EventData) => void

thisArg
any

Returns void

on

on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void
A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
Parameter Default Description
eventNames
string

String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").

callback
(data: EventData) => void

Callback function which will be executed when event is raised.

thisArg
any

An optional parameter which will be used as `this` context for callback execution.

Returns void

once

once(event: string, callback: (data: EventData) => void, thisArg?: any): void
Adds one-time listener function for the event named `event`.
Parameter Default Description
event
string

Name of the event to attach to.

callback
(data: EventData) => void

A function to be called when the specified event is raised.

thisArg
any

An optional parameter which when set will be used as "this" in callback method call.

Returns void

removeEventListener

removeEventListener(eventNames: string, callback?: (data: EventData) => void, thisArg?: any): void
Removes listener(s) for the specified event name.
Parameter Default Description
eventNames
string

Comma delimited names of the events the specified listener is associated with.

callback
(data: EventData) => void

An optional parameter pointing to a specific listener. If not defined, all listeners for the event names will be removed.

thisArg
any

An optional parameter which when set will be used to refine search of the correct callback which will be removed as event listener.

Returns void

set

set(name: string, value: any): void
Updates the specified property with the provided value.
Parameter Default Description
name
string

value
any

Returns void

setProperty

setProperty(name: string, value: any): void
Updates the specified property with the provided value and raises a property change event and a specific change event based on the property name.
Parameter Default Description
name
string

value
any

Returns void

addEventListener

Static
addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any): void
Parameter Default Description
eventName
string

callback
(data: EventData) => void

thisArg
any

Returns void

off

Static
off(eventName: string, callback?: (data: EventData) => void, thisArg?: any): void
Parameter Default Description
eventName
string

callback
(data: EventData) => void

thisArg
any

Returns void

on

Static
on(eventName: string, callback: (data: EventData) => void, thisArg?: any): void
Parameter Default Description
eventName
string

callback
(data: EventData) => void

thisArg
any

Returns void

once

Static
once(eventName: string, callback: (data: EventData) => void, thisArg?: any): void
Parameter Default Description
eventName
string

callback
(data: EventData) => void

thisArg
any

Returns void

removeEventListener

Static
removeEventListener(eventName: string, callback?: (data: EventData) => void, thisArg?: any): void
Parameter Default Description
eventName
string

callback
(data: EventData) => void

thisArg
any

Returns void