Observable | API - NativeScript

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

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.

_emit

_emit(eventNames: string): void

addEventListener

addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void

Adds a listener for the specified event name.

get

Gets the value of the specified property.

hasListeners

hasListeners(eventName: string): boolean

Checks whether a listener is registered for the specified event name.

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.

notifyPropertyChange

notifyPropertyChange(name: string, value: any, oldValue?: any): void

Notifies all the registered listeners for the property change event.

off

off(eventNames: string, callback?: (data: EventData) => void, thisArg?: any): void

Shortcut alias to the removeEventListener method.

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).

once

once(event: string, callback: (data: EventData) => void, thisArg?: any): void

Adds one-time listener function for the event named `event`.

removeEventListener

removeEventListener(eventNames: string, callback?: (data: EventData) => void, thisArg?: any): void

Removes listener(s) for the specified event name.

set

set(name: string, value: any): void

Updates the specified property with the provided value.

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.

addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any): void
off(eventName: string, callback?: (data: EventData) => void, thisArg?: any): void
on(eventName: string, callback: (data: EventData) => void, thisArg?: any): void
once(eventName: string, callback: (data: EventData) => void, thisArg?: any): void

removeEventListener

Static

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

Previous
NavigationButton

Next
ObservableArray