Usage
For additional information visit:
Final classes in JET
Classes in JET are generally final and do not support subclassing. At the moment, final is not enforced. However, this will likely change in an upcoming JET release.
Constructor
new Events
Fields
-
(static) EventType :string
-
Properties:
Name Type Default Description ADD
string add Triggered when a model is added to a collection The event passes these arguments to the handler:
-
model: the model being added to the collection
collection: the collection to which the model has been added
options: any options passed in to the add call that triggered the eventALL
string all Triggered for any of the above events The event passes the name of the actual event and then any arguments normally passed to that event following the name
ALLADDED
string alladded Triggered by a collection during an add call once all models passed in have been added The event passes these arguments to the handler:
-
collection: the collection to which the models have been added
models: the array of models that have been added
options: any options passed in to the add callALLREMOVED
string allremoved Triggered by a collection during a remove call once all models passed in have been removed and destroyed The event passes these arguments to the handler:
-
collection: the collection from which the models have been removed
models: the array of models that have been removed
options: any options passed in to the remove callCHANGE
string change Triggered when a model's attributes are changed. This can be the result of a clear call on a model; a property set call on a model; an unset call on a model; or the changing of properties due to the merging of models (in an add, for example) The event passes these arguments to the handler:
-
model: the model on which the change occurred
value: for property-specific change events, the new value of the property being changed
options: any options passed in to the call that triggered the change event. This is the second argument passed for overall change events, and the third parameter (after value) for property-specific change events.DESTROY
string destroy Triggered when a model is deleted from the data service (and thus from its Collection), due to a model destroy call The event passes these arguments to the handler:
-
model: the model being deleted
collection: the deleted model's collection, if anyERROR
string error Triggered when a model has failed to update on the data service The event passes these arguments to the handler:
collection or model: the collection or model that made the call that resulted in the error
xhr: the xhr argument for the failing request, if any
options: any options passed in to the call that triggered the failing request, plus the status and error as textStatus and errorThrownINVALID
string invalid Triggered on an error with data source interactions The event passes these arguments to the handler:
-
model: the model (or collection) on which the error operation happened
xhr: the xhr involved, if relevant
options: any options passed in to the call that triggered the invalid eventREADY
string ready Triggered when all pending promises from Collection API calls have been resolved The event passes these arguments to the handler:
-
collection: the collection on which the promises have been resolved
REFRESH
string refresh Triggered when a collection is refreshed (see Collection.refresh) The event passes these arguments to the handler:
-
collection: the collection being refreshed
options: any options passed in to the refresh callREMOVE
string remove Triggered when a model is removed from a collection The event passes these arguments to the handler:
-
model: the model being removed from the collection
collection: the collection from which the model was removed
options: index: the index of the model being removedREQUEST
string request Triggered when a model or collection has sent a request to the data service The event passes these arguments to the handler:
-
collection or model: the collection or model triggering the request
xhr: the xhr argument for the request
options: any options passed as part of the requestRESET
string reset Triggered when a collection is reset (see Collection.reset) The event passes these arguments to the handler:
-
collection: the collection being reset
options: any options passed in to the reset callSORT
string sort Triggered when a collection is sorted. If the second argument to the callback is set (options) and 'add' is true, it means this sort event was triggered as a result of an add The event passes these arguments to the handler:
-
collection: the collection being sorted
options: add: true if this sort event was triggered as the result of an add call, undefined or false if notSYNC
string sync Triggered when a model or collection has been updated from the data service The event passes these arguments to the handler:
-
collection or model: the collection or model that triggered the update
response: the response object from the data service
options: any options passed in to the call that triggered the update
Methods
-
(static) listenTo(otherObj, eventType, callback) : {undefined}
-
Add an event handler for an event type to a second model or collection object ("otherObj"), but track it on the called object.
Parameters:
Name Type Description otherObj
Model | Collection Model or collection object on which to add this event handler. eventType
string Types of event handlers to add (may be a single event type or a space-delimited set of event types). callback
(context: Object, data?: any, data2?: any)=> void User's event handler callback function (called with the model or collection object and event specific values as parameters--the context will be the model or collection unless specified by context, below). - Since:
- 1.0.0
Returns:
- Type
- undefined
-
(static) listenToOnce(otherObj, eventType, callback) : {undefined}
-
Add an event handler for an event type to a second model or collection object ("otherObj"), but track it on the called object. Only fire once.
Parameters:
Name Type Description otherObj
Model | Collection Model or collection object on which to add this event handler. eventType
string Types of event handlers to add (may be a single event type or a space-delimited set of event types). callback
(context: Object, data?: any, data2?: any)=> void User's event handler callback function (called with the model or collection object and event specific values as parameters--the context will be the model or collection unless specified by context, below). - Since:
- 1.0.0
Returns:
- Type
- undefined
-
(static) off(eventType, callback, context) : {undefined}
-
Remove an event handler for an event type from the model or collection object.
Parameters:
Name Type Argument Description eventType
string | Object <optional>
Types of event handlers to remove (may be a single event type, a space-delimited set of event types, or a map of events to callbacks). If omitted, remove all event handlers. callback
(context: object, data?: any, data2?: any)=> void <optional>
If provided, remove handlers only for eventType events with the given callback function. context
Object <optional>
If provided, remove handlers only for eventType events with the given callback function and context object. - Since:
- 1.0.0
Returns:
- Type
- undefined
-
(static) on(eventType, callback, context) : {undefined}
-
Add an event handler for an event type to the model or collection object.
Parameters:
Name Type Argument Description eventType
string | Object Types of event handlers to add (may be a single event type, a space-delimited set of event types, or an object mapping events to callbacks). callback
(context: Object, data?: any, data2?: any)=> void User's event handler callback function (called with the model or collection object and event specific values as parameters--the context will be the model or collection unless specified by context, below). context
Object <optional>
A context for the event - Since:
- 1.0.0
Returns:
- Type
- undefined
-
(static) once(eventType, callback, context) : {undefined}
-
Add an event handler for an event type to the model or collection object, but only fire it once, then remove it from the list of handlers.
Parameters:
Name Type Argument Description eventType
string Types of event handlers to add (may be a single event type or a space-delimited set of event types). callback
(context: Object, data?: any, data2?: any)=> void User's event handler callback function (called with the model or collection object and event specific values as parameters--the context will be the model or collection unless specified by context, below). context
Object <optional>
A context for the event - Since:
- 1.0.0
Returns:
- Type
- undefined
-
(static) stopListening(otherObj, eventType, callback) : {undefined}
-
Remove event handlers from a model or collection object. If the arguments are omitted, removes all event handlers from the model or collection.
Parameters:
Name Type Argument Description otherObj
Model | Collection If specified, remove event handlers that target otherObj from this model or collection. eventType
string <optional>
If specified, remove the event handlers for the given event types from this model or collection callback
(context: Object, data?: any, data2?: any)=> void <optional>
If specified, remove event handlers that call the given user callback function from this model or collection - Since:
- 1.0.0
Returns:
- Type
- undefined
-
(static) trigger(eventType) : {undefined}
-
Fire the given event type(s) for all registered handlers.
Parameters:
Name Type Description eventType
string Types of event handlers to fire (may be a single event type or a space-delimited set of event types). - Since:
- 1.0.0
Returns:
- Type
- undefined