|
@@ -26,23 +26,32 @@ const EmitterMixin = {
|
|
|
*
|
|
*
|
|
|
* @param {String} event The name of the event.
|
|
* @param {String} event The name of the event.
|
|
|
* @param {Function} callback The function to be called on event.
|
|
* @param {Function} callback The function to be called on event.
|
|
|
- * @param {utils.PriorityString|Number} [priority='normal'] The priority of this event callback. The higher
|
|
|
|
|
|
|
+ * @param {Object} [options={}] Additional options.
|
|
|
|
|
+ * @param {utils.PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
|
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
|
* order they were added.
|
|
* order they were added.
|
|
|
- * @param {Object} [ctx] The object that represents `this` in the callback. Defaults to the object firing the
|
|
|
|
|
|
|
+ * @param {Object} [options.ctx] The object that represents `this` in the callback. Defaults to the object firing the
|
|
|
* event.
|
|
* event.
|
|
|
* @method utils.EmitterMixin#on
|
|
* @method utils.EmitterMixin#on
|
|
|
*/
|
|
*/
|
|
|
- on( event, callback, priority = 'normal', ctx = null ) {
|
|
|
|
|
|
|
+ on( event, callback, options = {} ) {
|
|
|
|
|
+ if ( options.priority === undefined ) {
|
|
|
|
|
+ options.priority = 'normal';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( options.ctx === undefined ) {
|
|
|
|
|
+ options.ctx = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
createEventNamespace( this, event );
|
|
createEventNamespace( this, event );
|
|
|
const lists = getCallbacksListsForNamespace( this, event );
|
|
const lists = getCallbacksListsForNamespace( this, event );
|
|
|
|
|
|
|
|
- priority = priorities.get( priority );
|
|
|
|
|
|
|
+ options.priority = priorities.get( options.priority );
|
|
|
|
|
|
|
|
callback = {
|
|
callback = {
|
|
|
callback: callback,
|
|
callback: callback,
|
|
|
- ctx: ctx || this,
|
|
|
|
|
- priority: priority
|
|
|
|
|
|
|
+ ctx: options.ctx || this,
|
|
|
|
|
+ priority: options.priority
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// Add the callback to all callbacks list.
|
|
// Add the callback to all callbacks list.
|
|
@@ -51,7 +60,7 @@ const EmitterMixin = {
|
|
|
let added = false;
|
|
let added = false;
|
|
|
|
|
|
|
|
for ( let i = 0; i < callbacks.length; i++ ) {
|
|
for ( let i = 0; i < callbacks.length; i++ ) {
|
|
|
- if ( callbacks[ i ].priority < priority ) {
|
|
|
|
|
|
|
+ if ( callbacks[ i ].priority < options.priority ) {
|
|
|
callbacks.splice( i, 0, callback );
|
|
callbacks.splice( i, 0, callback );
|
|
|
added = true;
|
|
added = true;
|
|
|
|
|
|
|
@@ -72,12 +81,15 @@ const EmitterMixin = {
|
|
|
*
|
|
*
|
|
|
* @param {String} event The name of the event.
|
|
* @param {String} event The name of the event.
|
|
|
* @param {Function} callback The function to be called on event.
|
|
* @param {Function} callback The function to be called on event.
|
|
|
- * @param {utils.EventPriority} [priority='normal'] The priority of this event callback.
|
|
|
|
|
- * @param {Object} [ctx] The object that represents `this` in the callback. Defaults to the object firing the
|
|
|
|
|
|
|
+ * @param {Object} [options={}] Additional options.
|
|
|
|
|
+ * @param {utils.PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
|
|
|
+ * the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
|
|
|
+ * order they were added.
|
|
|
|
|
+ * @param {Object} [options.ctx] The object that represents `this` in the callback. Defaults to the object firing the
|
|
|
* event.
|
|
* event.
|
|
|
* @method utils.EmitterMixin#once
|
|
* @method utils.EmitterMixin#once
|
|
|
*/
|
|
*/
|
|
|
- once( event, callback, priority, ctx ) {
|
|
|
|
|
|
|
+ once( event, callback, options ) {
|
|
|
const onceCallback = function( event ) {
|
|
const onceCallback = function( event ) {
|
|
|
// Go off() at the first call.
|
|
// Go off() at the first call.
|
|
|
event.off();
|
|
event.off();
|
|
@@ -87,7 +99,7 @@ const EmitterMixin = {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// Make a similar on() call, simply replacing the callback.
|
|
// Make a similar on() call, simply replacing the callback.
|
|
|
- this.on( event, onceCallback, priority, ctx );
|
|
|
|
|
|
|
+ this.on( event, onceCallback, options );
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -121,12 +133,15 @@ const EmitterMixin = {
|
|
|
* @param {utils.Emitter} emitter The object that fires the event.
|
|
* @param {utils.Emitter} emitter The object that fires the event.
|
|
|
* @param {String} event The name of the event.
|
|
* @param {String} event The name of the event.
|
|
|
* @param {Function} callback The function to be called on event.
|
|
* @param {Function} callback The function to be called on event.
|
|
|
- * @param {utils.EventPriority} [priority='normal'] The priority of this event callback.
|
|
|
|
|
- * @param {Object} [ctx] The object that represents `this` in the callback. Defaults to the object firing the
|
|
|
|
|
|
|
+ * @param {Object} [options={}] Additional options.
|
|
|
|
|
+ * @param {utils.PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
|
|
|
|
|
+ * the priority value the sooner the callback will be fired. Events having the same priority are called in the
|
|
|
|
|
+ * order they were added.
|
|
|
|
|
+ * @param {Object} [options.ctx] The object that represents `this` in the callback. Defaults to the object firing the
|
|
|
* event.
|
|
* event.
|
|
|
* @method utils.EmitterMixin#listenTo
|
|
* @method utils.EmitterMixin#listenTo
|
|
|
*/
|
|
*/
|
|
|
- listenTo( emitter, event, callback, priority, ctx ) {
|
|
|
|
|
|
|
+ listenTo( emitter, event, callback, options ) {
|
|
|
let emitters, emitterId, emitterInfo, eventCallbacks;
|
|
let emitters, emitterId, emitterInfo, eventCallbacks;
|
|
|
|
|
|
|
|
// _listeningTo contains a list of emitters that this object is listening to.
|
|
// _listeningTo contains a list of emitters that this object is listening to.
|
|
@@ -165,7 +180,7 @@ const EmitterMixin = {
|
|
|
eventCallbacks.push( callback );
|
|
eventCallbacks.push( callback );
|
|
|
|
|
|
|
|
// Finally register the callback to the event.
|
|
// Finally register the callback to the event.
|
|
|
- emitter.on( event, callback, priority, ctx );
|
|
|
|
|
|
|
+ emitter.on( event, callback, options );
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|