-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.js
63 lines (63 loc) · 2.02 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Plugin = /** @class */ (function () {
function Plugin() {
this.on = {};
this.once = {};
}
Plugin.prototype.enable = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (!this.handle) {
throw new Error("You have to register the plugin in Webcheck first");
}
this.handle.emit("enablePlugin", this);
for (var hash in this.on) {
if (this.on.hasOwnProperty(hash)) {
this.handle.on(hash, this.on[hash]);
}
}
for (var hash in this.once) {
if (this.once.hasOwnProperty(hash)) {
this.handle.once(hash, this.once[hash]);
}
}
if (this.middleware) {
this.handle.middlewares.push(this.middleware);
}
if (typeof this.init === "function") {
this.init.apply(this, args);
}
return this;
};
Plugin.prototype.disable = function () {
if (!this.handle) {
throw new Error("You have to register the plugin in Webcheck first");
}
this.handle.emit("disablePlugin", this);
for (var hash in this.on) {
if (this.on.hasOwnProperty(hash)) {
this.handle.removeListener(hash, this.on[hash]);
}
}
for (var hash in this.once) {
if (this.once.hasOwnProperty(hash)) {
this.handle.removeListener(hash, this.once[hash]);
}
}
if (this.middleware) {
this.handle.middlewares.splice(this.handle.middlewares.indexOf(this.middleware), 1);
}
return this;
};
Plugin.prototype.register = function (handle) {
this.handle = handle;
this.handle.emit("registerPlugin", this);
return this;
};
return Plugin;
}());
exports.Plugin = Plugin;
//# sourceMappingURL=plugin.js.map