@studiometa/js-toolkit 2.2.0 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/index.cjs +3 -4
- package/Base/index.js +1 -2
- package/Base/managers/ServicesManager.cjs +4 -5
- package/Base/managers/ServicesManager.js +4 -5
- package/Base/utils.cjs +1 -5
- package/Base/utils.d.ts +0 -8
- package/Base/utils.js +1 -5
- package/package.json +1 -1
- package/services/drag.cjs +126 -148
- package/services/drag.d.ts +10 -10
- package/services/drag.js +125 -148
- package/services/index.cjs +3 -1
- package/services/index.d.ts +1 -0
- package/services/index.js +3 -1
- package/services/key.cjs +48 -63
- package/services/key.d.ts +0 -8
- package/services/key.js +47 -63
- package/services/load.cjs +24 -40
- package/services/load.d.ts +0 -8
- package/services/load.js +23 -37
- package/services/pointer.cjs +73 -103
- package/services/pointer.d.ts +1 -9
- package/services/pointer.js +72 -100
- package/services/raf.cjs +36 -53
- package/services/raf.d.ts +0 -8
- package/services/raf.js +36 -54
- package/services/resize.cjs +59 -68
- package/services/resize.d.ts +0 -7
- package/services/resize.js +58 -68
- package/services/scroll.cjs +49 -71
- package/services/scroll.js +48 -71
- package/services/service.cjs +68 -0
- package/services/service.d.ts +18 -0
- package/services/service.js +46 -0
- package/utils/css/animate.cjs +4 -8
- package/utils/css/animate.d.ts +16 -15
- package/utils/css/animate.js +3 -7
- package/utils/index.cjs +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/math/createEases.cjs +32 -0
- package/utils/math/createEases.d.ts +18 -0
- package/utils/math/createEases.js +10 -0
- package/utils/math/ease.cjs +15 -22
- package/utils/math/ease.d.ts +16 -33
- package/utils/math/ease.js +1 -8
- package/utils/math/index.cjs +1 -0
- package/utils/math/index.d.ts +1 -0
- package/utils/math/index.js +1 -0
- package/utils/noop.cjs +31 -0
- package/utils/noop.d.ts +12 -0
- package/utils/noop.js +9 -0
- package/services/Service.cjs +0 -76
- package/services/Service.d.ts +0 -76
- package/services/Service.js +0 -55
package/utils/math/ease.cjs
CHANGED
|
@@ -19,8 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// packages/js-toolkit/utils/math/ease.js
|
|
20
20
|
var ease_exports = {};
|
|
21
21
|
__export(ease_exports, {
|
|
22
|
-
createEaseInOut: () => createEaseInOut,
|
|
23
|
-
createEaseOut: () => createEaseOut,
|
|
24
22
|
easeInCirc: () => easeInCirc,
|
|
25
23
|
easeInCubic: () => easeInCubic,
|
|
26
24
|
easeInExpo: () => easeInExpo,
|
|
@@ -44,45 +42,40 @@ __export(ease_exports, {
|
|
|
44
42
|
easeOutSine: () => easeOutSine
|
|
45
43
|
});
|
|
46
44
|
module.exports = __toCommonJS(ease_exports);
|
|
47
|
-
|
|
48
|
-
return (progress) => 1 - easeIn(1 - progress);
|
|
49
|
-
}
|
|
50
|
-
function createEaseInOut(easeIn) {
|
|
51
|
-
return (progress) => progress === 0 ? 0 : progress === 1 ? 1 : progress < 0.5 ? easeIn(progress * 2) / 2 : 1 - easeIn((1 - progress) * 2) / 2;
|
|
52
|
-
}
|
|
45
|
+
var import_createEases = require("./createEases.cjs");
|
|
53
46
|
function easeInQuad(progress) {
|
|
54
47
|
return progress ** 2;
|
|
55
48
|
}
|
|
56
|
-
var easeOutQuad = createEaseOut(easeInQuad);
|
|
57
|
-
var easeInOutQuad = createEaseInOut(easeInQuad);
|
|
49
|
+
var easeOutQuad = (0, import_createEases.createEaseOut)(easeInQuad);
|
|
50
|
+
var easeInOutQuad = (0, import_createEases.createEaseInOut)(easeInQuad);
|
|
58
51
|
function easeInCubic(progress) {
|
|
59
52
|
return progress ** 3;
|
|
60
53
|
}
|
|
61
|
-
var easeOutCubic = createEaseOut(easeInCubic);
|
|
62
|
-
var easeInOutCubic = createEaseInOut(easeInCubic);
|
|
54
|
+
var easeOutCubic = (0, import_createEases.createEaseOut)(easeInCubic);
|
|
55
|
+
var easeInOutCubic = (0, import_createEases.createEaseInOut)(easeInCubic);
|
|
63
56
|
function easeInQuart(progress) {
|
|
64
57
|
return progress ** 4;
|
|
65
58
|
}
|
|
66
|
-
var easeOutQuart = createEaseOut(easeInQuart);
|
|
67
|
-
var easeInOutQuart = createEaseInOut(easeInQuart);
|
|
59
|
+
var easeOutQuart = (0, import_createEases.createEaseOut)(easeInQuart);
|
|
60
|
+
var easeInOutQuart = (0, import_createEases.createEaseInOut)(easeInQuart);
|
|
68
61
|
function easeInQuint(progress) {
|
|
69
62
|
return progress ** 5;
|
|
70
63
|
}
|
|
71
|
-
var easeOutQuint = createEaseOut(easeInQuint);
|
|
72
|
-
var easeInOutQuint = createEaseInOut(easeInQuint);
|
|
64
|
+
var easeOutQuint = (0, import_createEases.createEaseOut)(easeInQuint);
|
|
65
|
+
var easeInOutQuint = (0, import_createEases.createEaseInOut)(easeInQuint);
|
|
73
66
|
function easeInSine(progress) {
|
|
74
67
|
return progress === 1 ? 1 : -Math.cos(progress * Math.PI / 2) + 1;
|
|
75
68
|
}
|
|
76
|
-
var easeOutSine = createEaseOut(easeInSine);
|
|
77
|
-
var easeInOutSine = createEaseInOut(easeInSine);
|
|
69
|
+
var easeOutSine = (0, import_createEases.createEaseOut)(easeInSine);
|
|
70
|
+
var easeInOutSine = (0, import_createEases.createEaseInOut)(easeInSine);
|
|
78
71
|
function easeInCirc(progress) {
|
|
79
72
|
return -(Math.sqrt(1 - progress * progress) - 1);
|
|
80
73
|
}
|
|
81
|
-
var easeOutCirc = createEaseOut(easeInCirc);
|
|
82
|
-
var easeInOutCirc = createEaseInOut(easeInCirc);
|
|
74
|
+
var easeOutCirc = (0, import_createEases.createEaseOut)(easeInCirc);
|
|
75
|
+
var easeInOutCirc = (0, import_createEases.createEaseInOut)(easeInCirc);
|
|
83
76
|
function easeInExpo(progress) {
|
|
84
77
|
return 2 ** (10 * (progress - 1));
|
|
85
78
|
}
|
|
86
|
-
var easeOutExpo = createEaseOut(easeInExpo);
|
|
87
|
-
var easeInOutExpo = createEaseInOut(easeInExpo);
|
|
79
|
+
var easeOutExpo = (0, import_createEases.createEaseOut)(easeInExpo);
|
|
80
|
+
var easeInOutExpo = (0, import_createEases.createEaseInOut)(easeInExpo);
|
|
88
81
|
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/math/ease.d.ts
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create an out easing function.
|
|
6
|
-
*
|
|
7
|
-
* @param {EasingFunction} easeIn The ease in function.
|
|
8
|
-
* @returns {EasingFunction} The out function.
|
|
9
|
-
*/
|
|
10
|
-
export function createEaseOut(easeIn: EasingFunction): EasingFunction;
|
|
11
|
-
/**
|
|
12
|
-
* Create an in-out easing function.
|
|
13
|
-
*
|
|
14
|
-
* @param {EasingFunction} easeIn The ease in function.
|
|
15
|
-
* @returns {EasingFunction} The in-out function.
|
|
16
|
-
*/
|
|
17
|
-
export function createEaseInOut(easeIn: EasingFunction): EasingFunction;
|
|
18
|
-
/**
|
|
19
|
-
* @type {EasingFunction}
|
|
2
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
3
|
+
* @returns {number} Eased value between 0 and 1.
|
|
20
4
|
*/
|
|
21
5
|
export function easeInQuad(progress: number): number;
|
|
22
6
|
/**
|
|
@@ -61,18 +45,17 @@ export function easeInCirc(progress: number): number;
|
|
|
61
45
|
* @returns {number} Eased value between 0 and 1.
|
|
62
46
|
*/
|
|
63
47
|
export function easeInExpo(progress: number): number;
|
|
64
|
-
export
|
|
65
|
-
export
|
|
66
|
-
export
|
|
67
|
-
export
|
|
68
|
-
export
|
|
69
|
-
export
|
|
70
|
-
export
|
|
71
|
-
export
|
|
72
|
-
export
|
|
73
|
-
export
|
|
74
|
-
export
|
|
75
|
-
export
|
|
76
|
-
export
|
|
77
|
-
export
|
|
78
|
-
export type EasingFunction = (progress: number) => number;
|
|
48
|
+
export const easeOutQuad: import("./createEases.js").EasingFunction;
|
|
49
|
+
export const easeInOutQuad: import("./createEases.js").EasingFunction;
|
|
50
|
+
export const easeOutCubic: import("./createEases.js").EasingFunction;
|
|
51
|
+
export const easeInOutCubic: import("./createEases.js").EasingFunction;
|
|
52
|
+
export const easeOutQuart: import("./createEases.js").EasingFunction;
|
|
53
|
+
export const easeInOutQuart: import("./createEases.js").EasingFunction;
|
|
54
|
+
export const easeOutQuint: import("./createEases.js").EasingFunction;
|
|
55
|
+
export const easeInOutQuint: import("./createEases.js").EasingFunction;
|
|
56
|
+
export const easeOutSine: import("./createEases.js").EasingFunction;
|
|
57
|
+
export const easeInOutSine: import("./createEases.js").EasingFunction;
|
|
58
|
+
export const easeOutCirc: import("./createEases.js").EasingFunction;
|
|
59
|
+
export const easeInOutCirc: import("./createEases.js").EasingFunction;
|
|
60
|
+
export const easeOutExpo: import("./createEases.js").EasingFunction;
|
|
61
|
+
export const easeInOutExpo: import("./createEases.js").EasingFunction;
|
package/utils/math/ease.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return (progress) => 1 - easeIn(1 - progress);
|
|
3
|
-
}
|
|
4
|
-
function createEaseInOut(easeIn) {
|
|
5
|
-
return (progress) => progress === 0 ? 0 : progress === 1 ? 1 : progress < 0.5 ? easeIn(progress * 2) / 2 : 1 - easeIn((1 - progress) * 2) / 2;
|
|
6
|
-
}
|
|
1
|
+
import { createEaseOut, createEaseInOut } from "./createEases.js";
|
|
7
2
|
function easeInQuad(progress) {
|
|
8
3
|
return progress ** 2;
|
|
9
4
|
}
|
|
@@ -40,8 +35,6 @@ function easeInExpo(progress) {
|
|
|
40
35
|
const easeOutExpo = createEaseOut(easeInExpo);
|
|
41
36
|
const easeInOutExpo = createEaseInOut(easeInExpo);
|
|
42
37
|
export {
|
|
43
|
-
createEaseInOut,
|
|
44
|
-
createEaseOut,
|
|
45
38
|
easeInCirc,
|
|
46
39
|
easeInCubic,
|
|
47
40
|
easeInExpo,
|
package/utils/math/index.cjs
CHANGED
|
@@ -42,4 +42,5 @@ var import_map = __toESM(require("./map.cjs"), 1);
|
|
|
42
42
|
var import_round = __toESM(require("./round.cjs"), 1);
|
|
43
43
|
__reExport(math_exports, require("./ease.cjs"), module.exports);
|
|
44
44
|
var ease = __toESM(require("./ease.cjs"), 1);
|
|
45
|
+
__reExport(math_exports, require("./createEases.cjs"), module.exports);
|
|
45
46
|
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/math/index.d.ts
CHANGED
package/utils/math/index.js
CHANGED
package/utils/noop.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/utils/noop.js
|
|
20
|
+
var noop_exports = {};
|
|
21
|
+
__export(noop_exports, {
|
|
22
|
+
noop: () => noop,
|
|
23
|
+
noopValue: () => noopValue
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(noop_exports);
|
|
26
|
+
function noop() {
|
|
27
|
+
}
|
|
28
|
+
function noopValue(value) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/noop.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No operation function.
|
|
3
|
+
* @returns {void}
|
|
4
|
+
*/
|
|
5
|
+
export function noop(): void;
|
|
6
|
+
/**
|
|
7
|
+
* No operation function which return the given value unaltered.
|
|
8
|
+
* @template {any} T
|
|
9
|
+
* @param {T} value
|
|
10
|
+
* @returns {T}
|
|
11
|
+
*/
|
|
12
|
+
export function noopValue<T extends unknown>(value: T): T;
|
package/utils/noop.js
ADDED
package/services/Service.cjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __publicField = (obj, key, value) => {
|
|
20
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// packages/js-toolkit/services/Service.js
|
|
25
|
-
var Service_exports = {};
|
|
26
|
-
__export(Service_exports, {
|
|
27
|
-
default: () => Service
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(Service_exports);
|
|
30
|
-
var Service = class {
|
|
31
|
-
constructor() {
|
|
32
|
-
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
33
|
-
__publicField(this, "isInit", false);
|
|
34
|
-
__publicField(this, "props");
|
|
35
|
-
}
|
|
36
|
-
updateProps(...args) {
|
|
37
|
-
this.props = args;
|
|
38
|
-
throw new Error("The `updateProps` method must be implemented.");
|
|
39
|
-
}
|
|
40
|
-
init() {
|
|
41
|
-
throw new Error("The `init` method must be implemented.");
|
|
42
|
-
}
|
|
43
|
-
kill() {
|
|
44
|
-
throw new Error("The `kill` method must be implemented.");
|
|
45
|
-
}
|
|
46
|
-
add(key, callback) {
|
|
47
|
-
if (this.has(key)) {
|
|
48
|
-
throw new Error(`A callback with the key \`${key}\` has already been registered.`);
|
|
49
|
-
}
|
|
50
|
-
if (this.callbacks.size === 0 && !this.isInit) {
|
|
51
|
-
this.init();
|
|
52
|
-
this.isInit = true;
|
|
53
|
-
}
|
|
54
|
-
this.callbacks.set(key, callback);
|
|
55
|
-
}
|
|
56
|
-
has(key) {
|
|
57
|
-
return this.callbacks.has(key);
|
|
58
|
-
}
|
|
59
|
-
get(key) {
|
|
60
|
-
return this.callbacks.get(key);
|
|
61
|
-
}
|
|
62
|
-
remove(key) {
|
|
63
|
-
this.callbacks.delete(key);
|
|
64
|
-
if (this.callbacks.size === 0 && this.isInit) {
|
|
65
|
-
this.kill();
|
|
66
|
-
this.isInit = false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
trigger(...args) {
|
|
70
|
-
this.callbacks.forEach(function forEachCallback(callback) {
|
|
71
|
-
callback(...args);
|
|
72
|
-
});
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
if (module.exports.default) module.exports = module.exports.default;
|
package/services/Service.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Service abstract class
|
|
3
|
-
*/
|
|
4
|
-
export default class Service {
|
|
5
|
-
/**
|
|
6
|
-
* Map containing the callbacks.
|
|
7
|
-
* @type {Map<string, Function>}
|
|
8
|
-
*/
|
|
9
|
-
callbacks: Map<string, Function>;
|
|
10
|
-
/**
|
|
11
|
-
* State flag.
|
|
12
|
-
* @type {boolean}
|
|
13
|
-
*/
|
|
14
|
-
isInit: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* @type {unknown}
|
|
17
|
-
*/
|
|
18
|
-
props: unknown;
|
|
19
|
-
/**
|
|
20
|
-
* Method to update the services properties.
|
|
21
|
-
* This method MUST be implemented by the service extending this class.
|
|
22
|
-
*
|
|
23
|
-
* @param {...any} args
|
|
24
|
-
* @returns {this['props']}
|
|
25
|
-
*/
|
|
26
|
-
updateProps(...args: any[]): unknown;
|
|
27
|
-
/**
|
|
28
|
-
* Method to initialize the service behaviors.
|
|
29
|
-
* This method MUST be implemented by the service extending this class.
|
|
30
|
-
*
|
|
31
|
-
* @returns {void}
|
|
32
|
-
*/
|
|
33
|
-
init(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Method to kill the service behaviors.
|
|
36
|
-
* This method MUST be implemented by the service extending this class.
|
|
37
|
-
*
|
|
38
|
-
* @returns {void}
|
|
39
|
-
*/
|
|
40
|
-
kill(): void;
|
|
41
|
-
/**
|
|
42
|
-
* Add a callback.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} key The callback's identifier
|
|
45
|
-
* @param {Function} callback The callback function
|
|
46
|
-
* @returns {void}
|
|
47
|
-
*/
|
|
48
|
-
add(key: string, callback: Function): void;
|
|
49
|
-
/**
|
|
50
|
-
* Test if a callback with the given key has already been added.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} key The identifier to test
|
|
53
|
-
* @returns {boolean} Whether or not the identifier already exists
|
|
54
|
-
*/
|
|
55
|
-
has(key: string): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Get the callback tied to the given key.
|
|
58
|
-
*
|
|
59
|
-
* @param {string} key The identifier to get
|
|
60
|
-
* @returns {Function} The callback function
|
|
61
|
-
*/
|
|
62
|
-
get(key: string): Function;
|
|
63
|
-
/**
|
|
64
|
-
* Remove the callback tied to the given key.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} key The identifier to remove
|
|
67
|
-
*/
|
|
68
|
-
remove(key: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Trigger each added callback with the given arguments.
|
|
71
|
-
*
|
|
72
|
-
* @param {...any} args All the arguments to apply to the callback
|
|
73
|
-
* @returns {this} The current instance
|
|
74
|
-
*/
|
|
75
|
-
trigger(...args: any[]): this;
|
|
76
|
-
}
|
package/services/Service.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
class Service {
|
|
8
|
-
constructor() {
|
|
9
|
-
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
10
|
-
__publicField(this, "isInit", false);
|
|
11
|
-
__publicField(this, "props");
|
|
12
|
-
}
|
|
13
|
-
updateProps(...args) {
|
|
14
|
-
this.props = args;
|
|
15
|
-
throw new Error("The `updateProps` method must be implemented.");
|
|
16
|
-
}
|
|
17
|
-
init() {
|
|
18
|
-
throw new Error("The `init` method must be implemented.");
|
|
19
|
-
}
|
|
20
|
-
kill() {
|
|
21
|
-
throw new Error("The `kill` method must be implemented.");
|
|
22
|
-
}
|
|
23
|
-
add(key, callback) {
|
|
24
|
-
if (this.has(key)) {
|
|
25
|
-
throw new Error(`A callback with the key \`${key}\` has already been registered.`);
|
|
26
|
-
}
|
|
27
|
-
if (this.callbacks.size === 0 && !this.isInit) {
|
|
28
|
-
this.init();
|
|
29
|
-
this.isInit = true;
|
|
30
|
-
}
|
|
31
|
-
this.callbacks.set(key, callback);
|
|
32
|
-
}
|
|
33
|
-
has(key) {
|
|
34
|
-
return this.callbacks.has(key);
|
|
35
|
-
}
|
|
36
|
-
get(key) {
|
|
37
|
-
return this.callbacks.get(key);
|
|
38
|
-
}
|
|
39
|
-
remove(key) {
|
|
40
|
-
this.callbacks.delete(key);
|
|
41
|
-
if (this.callbacks.size === 0 && this.isInit) {
|
|
42
|
-
this.kill();
|
|
43
|
-
this.isInit = false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
trigger(...args) {
|
|
47
|
-
this.callbacks.forEach(function forEachCallback(callback) {
|
|
48
|
-
callback(...args);
|
|
49
|
-
});
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export {
|
|
54
|
-
Service as default
|
|
55
|
-
};
|