vision-embedded-web
Version:
Cubic Vision methods for embedded web content.
73 lines (72 loc) • 2.82 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLiteEvent = void 0;
var lite_auto_bind_1 = require("./lite-auto-bind");
function createLiteEvent() {
return new LiteEvent();
}
exports.createLiteEvent = createLiteEvent;
var LiteEvent = /** @class */ (function (_super) {
__extends(LiteEvent, _super);
function LiteEvent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.handlers = [];
_this.onceHandlers = [];
return _this;
}
LiteEvent.prototype.on = function (handler) {
var _this = this;
this.handlers.push(handler);
return function () {
_this.handlers = _this.handlers.filter(function (h) { return h !== handler; });
};
};
LiteEvent.prototype.off = function (handler) {
this.handlers = this.handlers.filter(function (h) { return h !== handler; });
this.onceHandlers = this.onceHandlers.filter(function (h) { return h !== handler; });
};
LiteEvent.prototype.execute = function (data, handlers) {
handlers.forEach(function (h) {
try {
h(data);
}
catch (err) {
/* tslint:disable-next-line */
console.error(err);
}
});
};
LiteEvent.prototype.emit = function (data) {
this.execute(data, this.handlers);
this.execute(data, this.onceHandlers);
this.onceHandlers = [];
};
LiteEvent.prototype.once = function (handler) {
var _this = this;
this.onceHandlers.push(handler);
return function () {
_this.onceHandlers = _this.onceHandlers.filter(function (h) { return h !== handler; });
};
};
LiteEvent.prototype.unsubscribeAll = function () {
this.handlers = [];
this.onceHandlers = [];
};
return LiteEvent;
}(lite_auto_bind_1.LiteAutoBind));
exports.default = LiteEvent;