getEvents()

The getEvents() function (client-side) handles a group of synchronous events together to retrieve, monitor, and act on several events at the same time.

Syntax

Use this syntax for the getEvents() function:

            var events = getEvents(['eventName1','eventName2', 'eventNamen']); 

          

Return Value

The getEvents() function returns an object representing the specified events. This object includes the name property, which corresponds to the event names provided to the function. The object also exposes several methods to handle event resolution, failure, and listeners.

Method

Description

done(callback)

Invokes the callback when any or all listed events resolve. The callback is attached to each event.

fail(callback)

Attaches the callback as a failure handler to all underlying events.

reject(data)

Invokes reject(data) on each event's deferred object, marking them as failed.

resolve(data)

Invokes resolve(data) on each event's deferred object, marking them as successful.

resolveSpecial(options)

If the verified condition returns true, this method resolves the events and applies the options to each event in the group.

then(callback)

Registers the callback to run after all events are resolved or rejected.

Parameters

The getEvents() function accepts an array of strings representing the event names as a required parameter.

Examples

The following examples show how to use the getEvents() function.

Attaching a Listener to All Events in a Group

This example groups multiple events and runs a function when the specified events finish. The callback runs after all relevant events are resolved.

              var events = getEvents(['floor.ready', 'canvas.ready']);
events.then(function(data){
    console.log('Floor and canvas are ready.');
}); 

            

Related Topics

General Notices