@x-oasis/emitter 0.0.15

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @x-oasis/emitter
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ npm i @x-oasis/emitter
7
+ ```
8
+
9
+ ## How to use
10
+
11
+ ```typescript
12
+ import Emitter from '@x-oasis/emitter'
13
+ ```
14
+
15
+ ## How to run test
16
+
17
+ ```bash
18
+ $ pnpm test
19
+ ```
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Emitter = /*#__PURE__*/function () {
6
+ function Emitter() {
7
+ this.subscriptions = {};
8
+ }
9
+ var _proto = Emitter.prototype;
10
+ _proto.fire = function fire(event) {
11
+ var cbs = this.subscriptions[event] || [];
12
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13
+ rest[_key - 1] = arguments[_key];
14
+ }
15
+ for (var i = 0; i < cbs.length; i++) {
16
+ cbs[i].apply(this, rest);
17
+ }
18
+ };
19
+ _proto.on = function on(event, cb) {
20
+ var _this = this;
21
+ if (!this.subscriptions[event]) this.subscriptions[event] = [cb];else this.subscriptions[event].push(cb);
22
+ return function () {
23
+ var subscriptions = _this.subscriptions[event];
24
+ var index = subscriptions.indexOf(cb);
25
+ if (index !== -1) subscriptions.splice(index, 1);
26
+ };
27
+ };
28
+ _proto.off = function off(event) {
29
+ delete this.subscriptions[event];
30
+ };
31
+ return Emitter;
32
+ }();
33
+
34
+ exports.default = Emitter;
35
+ //# sourceMappingURL=emitter.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["class Emitter {\n public subscriptions: {\n [key: string]: any;\n } = {};\n\n fire(event, ...rest) {\n const cbs = this.subscriptions[event] || [];\n for (let i = 0; i < cbs.length; i++) {\n cbs[i].apply(this, rest); // eslint-disable-line\n }\n }\n\n on(event, cb) {\n if (!this.subscriptions[event]) this.subscriptions[event] = [cb];\n else this.subscriptions[event].push(cb);\n\n return () => {\n const subscriptions = this.subscriptions[event];\n const index = subscriptions.indexOf(cb);\n if (index !== -1) subscriptions.splice(index, 1);\n };\n }\n\n off(event) {\n delete this.subscriptions[event];\n }\n}\n\nexport default Emitter;\n"],"names":["Emitter","_proto","prototype","fire","event","cbs","subscriptions","_len","arguments","length","rest","Array","_key","i","apply","on","cb","push","_this","index","indexOf","splice","off"],"mappings":";;;;IAAMA,OAAO;EAAb,SAAAA;IACS,kBAAa,GAEhB,EAAE;;EAuBP,IAAAC,MAAA,GAAAD,OAAA,CAAAE,SAAA;EAAAD,MAAA,CArBCE,IAAI,GAAJ,SAAAA,KAAKC,KAAK;IACR,IAAMC,GAAG,GAAG,IAAI,CAACC,aAAa,CAACF,KAAK,CAAC,IAAI,EAAE;IAAC,SAAAG,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAD/BC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;;IAEjB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGR,GAAG,CAACI,MAAM,EAAEI,CAAC,EAAE,EAAE;MACnCR,GAAG,CAACQ,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,EAAEJ,IAAI,CAAC;;GAE3B;EAAAT,MAAA,CAEDc,EAAE,GAAF,SAAAA,GAAGX,KAAK,EAAEY,EAAE;;IACV,IAAI,CAAC,IAAI,CAACV,aAAa,CAACF,KAAK,CAAC,EAAE,IAAI,CAACE,aAAa,CAACF,KAAK,CAAC,GAAG,CAACY,EAAE,CAAC,CAAC,KAC5D,IAAI,CAACV,aAAa,CAACF,KAAK,CAAC,CAACa,IAAI,CAACD,EAAE,CAAC;IAEvC,OAAO;MACL,IAAMV,aAAa,GAAGY,KAAI,CAACZ,aAAa,CAACF,KAAK,CAAC;MAC/C,IAAMe,KAAK,GAAGb,aAAa,CAACc,OAAO,CAACJ,EAAE,CAAC;MACvC,IAAIG,KAAK,KAAK,CAAC,CAAC,EAAEb,aAAa,CAACe,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;KACjD;GACF;EAAAlB,MAAA,CAEDqB,GAAG,GAAH,SAAAA,IAAIlB,KAAK;IACP,OAAO,IAAI,CAACE,aAAa,CAACF,KAAK,CAAC;GACjC;EAAA,OAAAJ,OAAA;AAAA;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(){function s(){this.subscriptions={}}var t=s.prototype;return t.fire=function(s){for(var t=this.subscriptions[s]||[],i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];for(var e=0;e<t.length;e++)t[e].apply(this,n)},t.on=function(s,t){var i=this;return this.subscriptions[s]?this.subscriptions[s].push(t):this.subscriptions[s]=[t],function(){var n=i.subscriptions[s],r=n.indexOf(t);-1!==r&&n.splice(r,1)}},t.off=function(s){delete this.subscriptions[s]},s}();
2
+ //# sourceMappingURL=emitter.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["class Emitter {\n public subscriptions: {\n [key: string]: any;\n } = {};\n\n fire(event, ...rest) {\n const cbs = this.subscriptions[event] || [];\n for (let i = 0; i < cbs.length; i++) {\n cbs[i].apply(this, rest); // eslint-disable-line\n }\n }\n\n on(event, cb) {\n if (!this.subscriptions[event]) this.subscriptions[event] = [cb];\n else this.subscriptions[event].push(cb);\n\n return () => {\n const subscriptions = this.subscriptions[event];\n const index = subscriptions.indexOf(cb);\n if (index !== -1) subscriptions.splice(index, 1);\n };\n }\n\n off(event) {\n delete this.subscriptions[event];\n }\n}\n\nexport default Emitter;\n"],"names":["Emitter","this","_proto","prototype","fire","event","cbs","subscriptions","_len","arguments","length","rest","Array","_key","i","apply","on","cb","push","_this","index","indexOf","splice","off"],"mappings":"+FAAA,SAAAA,IACSC,mBAEH,GAuBL,IAAAC,EAAAF,EAAAG,UADE,OACFD,EArBCE,KAAA,SAAKC,GACyC,IAA5C,IAAMC,EAAML,KAAKM,cAAcF,IAAU,GAAGG,EAAAC,UAAAC,OAD/BC,MAAIC,MAAAJ,IAAAA,OAAAK,IAAAA,EAAAL,EAAAK,IAAJF,EAAIE,KAAAJ,UAAAI,GAEjB,IAAK,IAAIC,EAAI,EAAGA,EAAIR,EAAII,OAAQI,IAC9BR,EAAIQ,GAAGC,MAAMd,KAAMU,IAEtBT,EAEDc,GAAA,SAAGX,EAAOY,cAIR,OAHKhB,KAAKM,cAAcF,GACnBJ,KAAKM,cAAcF,GAAOa,KAAKD,GADJhB,KAAKM,cAAcF,GAAS,CAACY,GAGtD,WACL,IAAMV,EAAgBY,EAAKZ,cAAcF,GACnCe,EAAQb,EAAcc,QAAQJ,IACrB,IAAXG,GAAcb,EAAce,OAAOF,EAAO,KAEjDlB,EAEDqB,IAAA,SAAIlB,UACKJ,KAAKM,cAAcF,IAC3BL"}
@@ -0,0 +1,31 @@
1
+ var Emitter = /*#__PURE__*/function () {
2
+ function Emitter() {
3
+ this.subscriptions = {};
4
+ }
5
+ var _proto = Emitter.prototype;
6
+ _proto.fire = function fire(event) {
7
+ var cbs = this.subscriptions[event] || [];
8
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
9
+ rest[_key - 1] = arguments[_key];
10
+ }
11
+ for (var i = 0; i < cbs.length; i++) {
12
+ cbs[i].apply(this, rest);
13
+ }
14
+ };
15
+ _proto.on = function on(event, cb) {
16
+ var _this = this;
17
+ if (!this.subscriptions[event]) this.subscriptions[event] = [cb];else this.subscriptions[event].push(cb);
18
+ return function () {
19
+ var subscriptions = _this.subscriptions[event];
20
+ var index = subscriptions.indexOf(cb);
21
+ if (index !== -1) subscriptions.splice(index, 1);
22
+ };
23
+ };
24
+ _proto.off = function off(event) {
25
+ delete this.subscriptions[event];
26
+ };
27
+ return Emitter;
28
+ }();
29
+
30
+ export default Emitter;
31
+ //# sourceMappingURL=emitter.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.esm.js","sources":["../src/index.ts"],"sourcesContent":["class Emitter {\n public subscriptions: {\n [key: string]: any;\n } = {};\n\n fire(event, ...rest) {\n const cbs = this.subscriptions[event] || [];\n for (let i = 0; i < cbs.length; i++) {\n cbs[i].apply(this, rest); // eslint-disable-line\n }\n }\n\n on(event, cb) {\n if (!this.subscriptions[event]) this.subscriptions[event] = [cb];\n else this.subscriptions[event].push(cb);\n\n return () => {\n const subscriptions = this.subscriptions[event];\n const index = subscriptions.indexOf(cb);\n if (index !== -1) subscriptions.splice(index, 1);\n };\n }\n\n off(event) {\n delete this.subscriptions[event];\n }\n}\n\nexport default Emitter;\n"],"names":["Emitter","_proto","prototype","fire","event","cbs","subscriptions","_len","arguments","length","rest","Array","_key","i","apply","on","cb","push","_this","index","indexOf","splice","off"],"mappings":"IAAMA,OAAO;EAAb,SAAAA;IACS,kBAAa,GAEhB,EAAE;;EAuBP,IAAAC,MAAA,GAAAD,OAAA,CAAAE,SAAA;EAAAD,MAAA,CArBCE,IAAI,GAAJ,SAAAA,KAAKC,KAAK;IACR,IAAMC,GAAG,GAAG,IAAI,CAACC,aAAa,CAACF,KAAK,CAAC,IAAI,EAAE;IAAC,SAAAG,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAD/BC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;;IAEjB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGR,GAAG,CAACI,MAAM,EAAEI,CAAC,EAAE,EAAE;MACnCR,GAAG,CAACQ,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,EAAEJ,IAAI,CAAC;;GAE3B;EAAAT,MAAA,CAEDc,EAAE,GAAF,SAAAA,GAAGX,KAAK,EAAEY,EAAE;;IACV,IAAI,CAAC,IAAI,CAACV,aAAa,CAACF,KAAK,CAAC,EAAE,IAAI,CAACE,aAAa,CAACF,KAAK,CAAC,GAAG,CAACY,EAAE,CAAC,CAAC,KAC5D,IAAI,CAACV,aAAa,CAACF,KAAK,CAAC,CAACa,IAAI,CAACD,EAAE,CAAC;IAEvC,OAAO;MACL,IAAMV,aAAa,GAAGY,KAAI,CAACZ,aAAa,CAACF,KAAK,CAAC;MAC/C,IAAMe,KAAK,GAAGb,aAAa,CAACc,OAAO,CAACJ,EAAE,CAAC;MACvC,IAAIG,KAAK,KAAK,CAAC,CAAC,EAAEb,aAAa,CAACe,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;KACjD;GACF;EAAAlB,MAAA,CAEDqB,GAAG,GAAH,SAAAA,IAAIlB,KAAK;IACP,OAAO,IAAI,CAACE,aAAa,CAACF,KAAK,CAAC;GACjC;EAAA,OAAAJ,OAAA;AAAA;;;;"}
@@ -0,0 +1,9 @@
1
+ declare class Emitter {
2
+ subscriptions: {
3
+ [key: string]: any;
4
+ };
5
+ fire(event: any, ...rest: any[]): void;
6
+ on(event: any, cb: any): () => void;
7
+ off(event: any): void;
8
+ }
9
+ export default Emitter;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./emitter.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./emitter.cjs.development.js')
8
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@x-oasis/emitter",
3
+ "version": "0.0.15",
4
+ "description": "emitter function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/emitter.esm.js",
8
+ "files": [
9
+ "dist",
10
+ "index.ts",
11
+ "src"
12
+ ],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "devDependencies": {
16
+ "tsdx": "^0.14.1"
17
+ },
18
+ "scripts": {
19
+ "build": "tsdx build --tsconfig tsconfig.build.json",
20
+ "clean": "rimraf ./dist",
21
+ "test": "vitest",
22
+ "compile": "tsc -p tsconfig.build.json"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ class Emitter {
2
+ public subscriptions: {
3
+ [key: string]: any;
4
+ } = {};
5
+
6
+ fire(event, ...rest) {
7
+ const cbs = this.subscriptions[event] || [];
8
+ for (let i = 0; i < cbs.length; i++) {
9
+ cbs[i].apply(this, rest); // eslint-disable-line
10
+ }
11
+ }
12
+
13
+ on(event, cb) {
14
+ if (!this.subscriptions[event]) this.subscriptions[event] = [cb];
15
+ else this.subscriptions[event].push(cb);
16
+
17
+ return () => {
18
+ const subscriptions = this.subscriptions[event];
19
+ const index = subscriptions.indexOf(cb);
20
+ if (index !== -1) subscriptions.splice(index, 1);
21
+ };
22
+ }
23
+
24
+ off(event) {
25
+ delete this.subscriptions[event];
26
+ }
27
+ }
28
+
29
+ export default Emitter;