@supercat1337/event-emitter 1.0.2 → 1.0.4
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.
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
// version 1.0.3
|
|
2
|
+
|
|
1
3
|
// src/EventEmitter.js
|
|
2
4
|
var EventEmitter = class {
|
|
3
|
-
/** @type {Object.<string,
|
|
5
|
+
/** @type {Object.<string, Function[]>} */
|
|
4
6
|
events = {};
|
|
5
7
|
/**
|
|
6
8
|
* @param {string} event
|
|
7
|
-
* @param {
|
|
8
|
-
* @returns {
|
|
9
|
+
* @param {Function} listener
|
|
10
|
+
* @returns {()=>void}
|
|
9
11
|
*/
|
|
10
12
|
on(event, listener) {
|
|
11
13
|
if (typeof this.events[event] !== "object") {
|
|
@@ -20,7 +22,7 @@ var EventEmitter = class {
|
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* @param {string} event
|
|
23
|
-
* @param {
|
|
25
|
+
* @param {Function} listener
|
|
24
26
|
*/
|
|
25
27
|
removeListener(event, listener) {
|
|
26
28
|
var idx;
|
|
@@ -51,8 +53,8 @@ var EventEmitter = class {
|
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* @param {string} event
|
|
54
|
-
* @param {
|
|
55
|
-
* @returns {
|
|
56
|
+
* @param {Function} listener
|
|
57
|
+
* @returns {()=>void}
|
|
56
58
|
*/
|
|
57
59
|
once(event, listener) {
|
|
58
60
|
return this.on(event, function g() {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
+
// version 1.0.3
|
|
1
2
|
var i=class{events={};on(e,s){typeof this.events[e]!="object"&&(this.events[e]=[]),this.events[e].push(s);let t=this;return function(){t.removeListener(e,s)}}removeListener(e,s){var t;typeof this.events[e]=="object"&&(t=this.events[e].indexOf(s),t>-1&&this.events[e].splice(t,1))}emit(e){if(typeof this.events[e]=="object"){var s,t,r,o=[].slice.call(arguments,1);for(t=this.events[e].slice(),r=t.length,s=0;s<r;s++)try{t[s].apply(this,o)}catch(n){console.error(e,o),console.error(n)}}}once(e,s){return this.on(e,function t(){this.removeListener(e,t),s.apply(this,arguments)})}};export{i as EventEmitter};
|
package/package.json
CHANGED
package/scripts/build.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import * as esbuild from 'esbuild';
|
|
3
|
+
import * as esbuild from "./../node_modules/esbuild/lib/main.js";
|
|
7
4
|
|
|
8
5
|
import fs from 'fs';
|
|
9
6
|
|
|
@@ -69,7 +66,7 @@ async function main() {
|
|
|
69
66
|
minify: false,
|
|
70
67
|
outfile: filename_1,
|
|
71
68
|
platform: `neutral`,
|
|
72
|
-
|
|
69
|
+
banner: { "js": `// version ${packageInfo.version}` }
|
|
73
70
|
});
|
|
74
71
|
|
|
75
72
|
var filesize_1 = fs.statSync(filename_1).size;
|
|
@@ -81,7 +78,8 @@ async function main() {
|
|
|
81
78
|
bundle: true,
|
|
82
79
|
minify: true,
|
|
83
80
|
outfile: filename_2,
|
|
84
|
-
platform: `neutral
|
|
81
|
+
platform: `neutral`,
|
|
82
|
+
banner: { "js": `// version ${packageInfo.version}` }
|
|
85
83
|
});
|
|
86
84
|
|
|
87
85
|
|
package/src/EventEmitter.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
/** @module EventEmitter */
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {Function} TListener
|
|
5
|
-
* @typedef {()=>void} Unsubscriber
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @class
|
|
11
|
-
* */
|
|
12
4
|
class EventEmitter {
|
|
13
|
-
/** @type {Object.<string,
|
|
5
|
+
/** @type {Object.<string, Function[]>} */
|
|
14
6
|
events = {};
|
|
15
7
|
|
|
16
8
|
/**
|
|
9
|
+
* on is used to add a callback function that's going to be executed when the event is triggered
|
|
17
10
|
* @param {string} event
|
|
18
|
-
* @param {
|
|
19
|
-
* @returns {
|
|
11
|
+
* @param {Function} listener
|
|
12
|
+
* @returns {()=>void}
|
|
20
13
|
*/
|
|
21
14
|
on(event, listener) {
|
|
22
15
|
|
|
@@ -35,8 +28,9 @@ class EventEmitter {
|
|
|
35
28
|
return unsubscriber;
|
|
36
29
|
}
|
|
37
30
|
/**
|
|
31
|
+
* Remove an event listener from an event
|
|
38
32
|
* @param {string} event
|
|
39
|
-
* @param {
|
|
33
|
+
* @param {Function} listener
|
|
40
34
|
*/
|
|
41
35
|
removeListener(event, listener) {
|
|
42
36
|
var idx;
|
|
@@ -51,6 +45,7 @@ class EventEmitter {
|
|
|
51
45
|
|
|
52
46
|
}
|
|
53
47
|
/**
|
|
48
|
+
* emit is used to trigger an event
|
|
54
49
|
* @param {string} event
|
|
55
50
|
*/
|
|
56
51
|
emit(event) {
|
|
@@ -75,9 +70,10 @@ class EventEmitter {
|
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
/**
|
|
73
|
+
* Add a one-time listener
|
|
78
74
|
* @param {string} event
|
|
79
|
-
* @param {
|
|
80
|
-
* @returns {
|
|
75
|
+
* @param {Function} listener
|
|
76
|
+
* @returns {()=>void}
|
|
81
77
|
*/
|
|
82
78
|
once(event, listener) {
|
|
83
79
|
return this.on(event, function g() {
|