expand event validation logic

This commit is contained in:
Tom 2024-01-29 13:12:01 -05:00
parent 024cee42f5
commit d490592b99

View File

@ -69,6 +69,7 @@ $.EventSource.prototype = {
* @param {Number} [times=1] - The number of times to handle the event * @param {Number} [times=1] - The number of times to handle the event
* before removing it. * before removing it.
* @param {Number} [priority=0] - Handler priority. By default, all priorities are 0. Higher number = priority. * @param {Number} [priority=0] - Handler priority. By default, all priorities are 0. Higher number = priority.
* @returns {Boolean} - True if the handler was added, false if it was rejected
*/ */
addOnceHandler: function(eventName, handler, userData, times, priority) { addOnceHandler: function(eventName, handler, userData, times, priority) {
var self = this; var self = this;
@ -81,7 +82,7 @@ $.EventSource.prototype = {
} }
return handler(event); return handler(event);
}; };
this.addHandler(eventName, onceHandler, userData, priority); return this.addHandler(eventName, onceHandler, userData, priority);
}, },
/** /**
@ -200,16 +201,22 @@ $.EventSource.prototype = {
* @function * @function
* @param {String} eventName - Name of event to register. * @param {String} eventName - Name of event to register.
* @param {Object} eventArgs - Event-specific data. * @param {Object} eventArgs - Event-specific data.
* @returns {Boolean} True if the event was fired, false if it was rejected because of rejectEventHandler(eventName)
*/ */
raiseEvent: function( eventName, eventArgs ) { raiseEvent: function( eventName, eventArgs ) {
//uncomment if you want to get a log of all events //uncomment if you want to get a log of all events
//$.console.log( eventName ); //$.console.log( eventName );
if(Object.prototype.hasOwnProperty.call(this._rejectedEventList, eventName)){
$.console.error(`Error adding handler for ${eventName}. ${this._rejectedEventList[eventName]}`);
return false;
}
var handler = this.getHandler( eventName ); var handler = this.getHandler( eventName );
if ( handler ) { if ( handler ) {
return handler( this, eventArgs || {} ); handler( this, eventArgs || {} );
} }
return undefined; return true;
}, },
/** /**