Class “Listeners”

Object > Listeners

Objects of the type Listeners provide methods to manage listeners and trigger events. They encapsulate the tabris event system in a way that is more convenient to use with TypeScript and the ES2017 async/await feature.

TypeScript type Listeners<EventData extends object = MinimalEventObject<object>> extends Object
Constructor public
Singleton No
Namespace tabris
Direct subclasses None
JSX support No

Constructor

new Listeners(target, type)

Parameter Type Optional Description
target object No  
type string No  

Methods

addListener(listener)

Registers a listener to be notified by new events. Each listener can only be added once. Returns the target object. Instances of Listeners can also be called directly as a function to register a new listener. I.e. widget.onResize(listener); is the same as widget.onResize.addListener(listener); It is also the same as widget.on('resize', listener');, but with better TypeScript support.

Parameter Type Optional Description
listener (event: EventObject) => void No  

Returns this.target

once(listener)

Notifies the given listener the next time an event is issued, but not afterwards. Returns the target object.

Parameter Type Optional Description
listener (event: EventObject) => void No  

Returns this.target

promise()

Returns a promise that resolves the next time an event is issued. The dispatched event object will be used as the resolved value.

Returns Promise

removeListener(listener)

Deregisters a listener, it will not be notified of future events. Returns the target object.

Parameter Type Optional Description
listener (event: EventObject) => void No  

Returns this.target

trigger()

Issues a plain event object to all registered listeners with a newly constructed event object.

Returns this.target

trigger(eventData?)

Issues an event object to all registered listeners. If an uninitialized (not previously issued) instance of EventObject is given as the argument it will be issued directly as-is. Any other type of object (including an already initialized/previously issued event object) will be copied to create a new event object. This allows for simple event re-routing.

Parameter Type Optional Description
eventData object Yes  

Returns this.target

Properties

target

The object that issues the events, e.g. a widget.

Type object
Settable No

type

The event type. This value will be set in the type field of the event object given to the listener. It is the same value used by the on and trigger methods.

Type string
Settable No

Change Events

typeChanged

Fired when the type property has changed.

Parameter Type Description
value string The new value of type.

targetChanged

Fired when the target property has changed.

Parameter Type Description
value object The new value of target.