@drozdik.m/event
Version:
Object for handling events.
68 lines (67 loc) • 2.55 kB
JavaScript
exports.__esModule = true;
var double_linked_list_1 = require("@drozdik.m/double-linked-list");
var Event = /** @class */ (function () {
//--------------------------------------------------
//---------CONSTRUCTOR------------------------------
//--------------------------------------------------
function Event() {
//--------------------------------------------------
//----------VARIABLES-------------------------------
//--------------------------------------------------
this.callbacks = new double_linked_list_1.List();
}
//--------------------------------------------------
//---------EVENTS-----------------------------------
//--------------------------------------------------
/**
* Adds function to be called on event trigger
* @param item Function to add
*/
Event.prototype.Add = function (item) {
this.callbacks.InsertBack(item);
};
/**
* Removes functions to be triggered (only first occurence)
* @param item Function to remove
*/
Event.prototype.Remove = function (item) {
this.callbacks.Remove(item);
};
/**
* Calls all added functions
* @param caller Caller object
* @param args Arguments
*/
Event.prototype.Invoke = function (caller, args) {
for (var it = this.callbacks.First(); it.HasValue(); it.Next())
it.Value()(caller, args);
};
//--------------------------------------------------
//---------CLONE------------------------------------
//--------------------------------------------------
Event.prototype.Clone = function () {
var res = new Event();
res.callbacks = this.callbacks.Clone();
return res;
};
//--------------------------------------------------
//---------COUNTS-----------------------------------
//--------------------------------------------------
Event.prototype.Count = function () {
return this.callbacks.Count();
};
Event.prototype.IsEmpty = function () {
return this.Count() == 0;
};
//--------------------------------------------------
//---------CLEARS-----------------------------------
//--------------------------------------------------
Event.prototype.Dispose = function () {
this.callbacks.Dispose();
};
Event.prototype.Clear = function () {
this.callbacks.Clear();
};
return Event;
}());
exports.Event = Event;