ng2-events
Version:
Supercharge your Angular2+ event handling
62 lines (61 loc) • 2.81 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.OnceEventPlugin = void 0;
var core_1 = require("@angular/core");
var common_1 = require("@angular/common");
var event_manager_plugin_1 = require("../__util/event-manager-plugin");
var i0 = require("@angular/core");
/**
* Automatically unregister an event listener after the event fired once
*
* Usage:
* <button (once.click)="foo()">...</button>
*
*/
var OnceEventPlugin = /** @class */ (function (_super) {
__extends(OnceEventPlugin, _super);
function OnceEventPlugin(doc) {
return _super.call(this, doc) || this;
}
OnceEventPlugin.prototype.supports = function (eventName) {
return eventName.indexOf('once.') === 0;
};
OnceEventPlugin.prototype.addEventListener = function (element, eventName, handler) {
var realEventName = eventName.slice(5);
var active = true;
var eventListener = this.manager.addEventListener(element, realEventName, function ($event) {
eventListener();
active = false;
handler($event);
});
return function () {
if (active)
eventListener();
};
};
OnceEventPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.2", ngImport: i0, type: OnceEventPlugin, deps: [{ token: common_1.DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
OnceEventPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.2", ngImport: i0, type: OnceEventPlugin });
return OnceEventPlugin;
}(event_manager_plugin_1.MyEventManagerPlugin));
exports.OnceEventPlugin = OnceEventPlugin;
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.2", ngImport: i0, type: OnceEventPlugin, decorators: [{
type: core_1.Injectable
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
type: core_1.Inject,
args: [common_1.DOCUMENT]
}] }]; } });