assemblerjs 0.9.7 → 1.0.1
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 +193 -56
- package/dist/index.d.ts +700 -465
- package/dist/index.js +59 -1
- package/dist/index.mjs +21 -919
- package/dist/index10.js +8 -0
- package/dist/index10.mjs +4 -0
- package/dist/index11.js +27 -0
- package/dist/index11.mjs +23 -0
- package/dist/index12.js +16 -0
- package/dist/index12.mjs +12 -0
- package/dist/index13.js +94 -0
- package/dist/index13.mjs +90 -0
- package/dist/index14.js +22 -0
- package/dist/index14.mjs +18 -0
- package/dist/index15.js +22 -0
- package/dist/index15.mjs +18 -0
- package/dist/index16.js +22 -0
- package/dist/index16.mjs +18 -0
- package/dist/index17.js +22 -0
- package/dist/index17.mjs +18 -0
- package/dist/index18.js +31 -0
- package/dist/index18.mjs +26 -0
- package/dist/index19.js +31 -0
- package/dist/index19.mjs +26 -0
- package/dist/index2.js +22 -0
- package/dist/index2.mjs +17 -0
- package/dist/index20.js +31 -0
- package/dist/index20.mjs +27 -0
- package/dist/index21.js +33 -0
- package/dist/index21.mjs +25 -0
- package/dist/index22.js +53 -0
- package/dist/index22.mjs +48 -0
- package/dist/index23.js +46 -0
- package/dist/index23.mjs +41 -0
- package/dist/index24.js +20 -0
- package/dist/index24.mjs +14 -0
- package/dist/index25.js +19 -0
- package/dist/index25.mjs +13 -0
- package/dist/index26.js +100 -0
- package/dist/index26.mjs +94 -0
- package/dist/index27.js +69 -0
- package/dist/index27.mjs +65 -0
- package/dist/index28.js +37 -0
- package/dist/index28.mjs +33 -0
- package/dist/index29.js +71 -0
- package/dist/index29.mjs +67 -0
- package/dist/index3.js +20 -0
- package/dist/index3.mjs +14 -0
- package/dist/index30.js +37 -0
- package/dist/index30.mjs +33 -0
- package/dist/index31.js +37 -0
- package/dist/index31.mjs +33 -0
- package/dist/index32.js +28 -0
- package/dist/index32.mjs +24 -0
- package/dist/index33.js +54 -0
- package/dist/index33.mjs +50 -0
- package/dist/index34.js +14 -0
- package/dist/index34.mjs +10 -0
- package/dist/index35.js +34 -0
- package/dist/index35.mjs +29 -0
- package/dist/index36.js +117 -0
- package/dist/index36.mjs +113 -0
- package/dist/index37.js +19 -0
- package/dist/index37.mjs +15 -0
- package/dist/index38.js +31 -0
- package/dist/index38.mjs +27 -0
- package/dist/index39.js +55 -0
- package/dist/index39.mjs +50 -0
- package/dist/index4.js +81 -0
- package/dist/index4.mjs +77 -0
- package/dist/index5.js +94 -0
- package/dist/index5.mjs +90 -0
- package/dist/index6.js +114 -0
- package/dist/index6.mjs +110 -0
- package/dist/index7.js +9 -0
- package/dist/index7.mjs +5 -0
- package/dist/index8.js +10 -0
- package/dist/index8.mjs +6 -0
- package/dist/index9.js +8 -0
- package/dist/index9.mjs +4 -0
- package/package.json +8 -5
package/dist/index5.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { clearInstance, conditionally, isDefined, pipe, isOfType, forIn, forOf, proxifyIterable } from '@assemblerjs/core';
|
|
2
|
+
|
|
3
|
+
class ListenerCollection {
|
|
4
|
+
dispose() {
|
|
5
|
+
clearInstance(this, ListenerCollection);
|
|
6
|
+
}
|
|
7
|
+
add(...t) {
|
|
8
|
+
let e;
|
|
9
|
+
let l;
|
|
10
|
+
if (t.length === 2) {
|
|
11
|
+
e = t[0];
|
|
12
|
+
l = t[1];
|
|
13
|
+
} else {
|
|
14
|
+
const i = t[0];
|
|
15
|
+
e = i[0];
|
|
16
|
+
l = i[1];
|
|
17
|
+
}
|
|
18
|
+
if (!this.collection[e]) {
|
|
19
|
+
this.collection[e] = [];
|
|
20
|
+
}
|
|
21
|
+
this.collection[e].push(l);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
remove(t, l) {
|
|
25
|
+
const i = (e)=>this.collection[t].splice(e, 1);
|
|
26
|
+
const n = conditionally({
|
|
27
|
+
if: ()=>this.collection[t] && this.collection[t].length === 0,
|
|
28
|
+
then: ()=>delete this.collection[t]
|
|
29
|
+
});
|
|
30
|
+
const s = conditionally({
|
|
31
|
+
if: ()=>isDefined(l),
|
|
32
|
+
then: ()=>i(this.collection[t].indexOf(l)),
|
|
33
|
+
else: ()=>delete this.collection[t]
|
|
34
|
+
});
|
|
35
|
+
const r = conditionally({
|
|
36
|
+
if: (t)=>this.has(t),
|
|
37
|
+
then: (t)=>this.collection[t]
|
|
38
|
+
});
|
|
39
|
+
pipe(r, s, n)();
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
has(...t) {
|
|
43
|
+
if (isOfType('string')(t[0])) {
|
|
44
|
+
return Object.keys(this.collection).includes(t[0]);
|
|
45
|
+
} else if (isOfType('function')(t[0])) {
|
|
46
|
+
return Object.values(this.collection).flat().includes(t[0]);
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
get(...t) {
|
|
51
|
+
if (isOfType('string')(t[0])) {
|
|
52
|
+
return this.collection[t[0]];
|
|
53
|
+
} else if (isOfType('function')(t[0])) {
|
|
54
|
+
return Object.values(this.collection).flat().filter((e)=>e === t[0]);
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
clear() {
|
|
59
|
+
const t = forIn(this.collection);
|
|
60
|
+
const e = (t)=>forOf(this.collection[t])((e)=>this.remove(t, e));
|
|
61
|
+
t((t)=>e(t));
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
get listeners() {
|
|
65
|
+
return Object.values(this.collection).flat();
|
|
66
|
+
}
|
|
67
|
+
get channels() {
|
|
68
|
+
return Object.keys(this.collection);
|
|
69
|
+
}
|
|
70
|
+
get length() {
|
|
71
|
+
return Object.values(this.collection).flat().length;
|
|
72
|
+
}
|
|
73
|
+
[Symbol.iterator]() {
|
|
74
|
+
let t = -1;
|
|
75
|
+
const e = this.collection ? Object.keys(this.collection) : [];
|
|
76
|
+
return {
|
|
77
|
+
next: ()=>({
|
|
78
|
+
value: e[++t],
|
|
79
|
+
done: !(t in e)
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
constructor(){
|
|
84
|
+
this.collection = {};
|
|
85
|
+
const t = proxifyIterable(this, ListenerCollection);
|
|
86
|
+
return t;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { ListenerCollection };
|
package/dist/index6.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const core = require('@assemblerjs/core');
|
|
6
|
+
const listenerCollection = require('./index5.js');
|
|
7
|
+
|
|
8
|
+
class EventManager {
|
|
9
|
+
dispose() {
|
|
10
|
+
this.listeners.dispose();
|
|
11
|
+
this.channels.clear();
|
|
12
|
+
this.channelCache.clear();
|
|
13
|
+
core.clearInstance(this, EventManager);
|
|
14
|
+
}
|
|
15
|
+
addChannels(...e) {
|
|
16
|
+
const s = core.forOf(e);
|
|
17
|
+
s((e)=>{
|
|
18
|
+
const n = this.cleanChannel(e);
|
|
19
|
+
if (this.channels.has(n)) {
|
|
20
|
+
throw new Error(`Channel '${n}' already exists.`);
|
|
21
|
+
}
|
|
22
|
+
this.channels.add(n);
|
|
23
|
+
});
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
removeChannels(...e) {
|
|
27
|
+
const s = core.forOf(e);
|
|
28
|
+
s((e)=>{
|
|
29
|
+
const n = this.cleanChannel(e);
|
|
30
|
+
if (n !== '*' && this.channels.has(n)) {
|
|
31
|
+
this.channels.delete(n);
|
|
32
|
+
this.listeners.remove(n);
|
|
33
|
+
this.onceListeners.remove(n);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
on(e, n) {
|
|
39
|
+
const s = this.cleanChannel(e);
|
|
40
|
+
this.listeners.add(s, n);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
once(e, n) {
|
|
44
|
+
const s = this.cleanChannel(e);
|
|
45
|
+
this.onceListeners.add(s, n);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
off(e, n) {
|
|
49
|
+
const s = this.cleanChannel(e);
|
|
50
|
+
this.listeners.remove(s, n);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
emit(e, ...n) {
|
|
54
|
+
const s = this.cleanChannel(e);
|
|
55
|
+
if (!this.channels.has(s)) {
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
const t = [
|
|
59
|
+
...(this.onceListeners.get('*') || []).map((e)=>({
|
|
60
|
+
listener: e,
|
|
61
|
+
once: true,
|
|
62
|
+
channel: '*'
|
|
63
|
+
})),
|
|
64
|
+
...(this.listeners.get('*') || []).map((e)=>({
|
|
65
|
+
listener: e,
|
|
66
|
+
once: false,
|
|
67
|
+
channel: '*'
|
|
68
|
+
})),
|
|
69
|
+
...(this.onceListeners.get(s) || []).map((e)=>({
|
|
70
|
+
listener: e,
|
|
71
|
+
once: true,
|
|
72
|
+
channel: s
|
|
73
|
+
})),
|
|
74
|
+
...(this.listeners.get(s) || []).map((e)=>({
|
|
75
|
+
listener: e,
|
|
76
|
+
once: false,
|
|
77
|
+
channel: s
|
|
78
|
+
}))
|
|
79
|
+
];
|
|
80
|
+
for (const { listener: e, once: s, channel: h } of t){
|
|
81
|
+
this.run(e, ...n);
|
|
82
|
+
if (s) {
|
|
83
|
+
this.onceListeners.remove(h, e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
run(e, ...n) {
|
|
89
|
+
if (core.isAsync(e)) {
|
|
90
|
+
const s = e;
|
|
91
|
+
return s(...n).then(()=>Promise.resolve());
|
|
92
|
+
}
|
|
93
|
+
e(...n);
|
|
94
|
+
}
|
|
95
|
+
cleanChannel(e) {
|
|
96
|
+
if (this.channelCache.has(e)) {
|
|
97
|
+
return this.channelCache.get(e);
|
|
98
|
+
}
|
|
99
|
+
const n = core.onlyAlphanumeric(e, '*', ':', '.', '-', '_');
|
|
100
|
+
this.channelCache.set(e, n);
|
|
101
|
+
return n;
|
|
102
|
+
}
|
|
103
|
+
constructor(...e){
|
|
104
|
+
this.listeners = new listenerCollection.ListenerCollection();
|
|
105
|
+
this.onceListeners = new listenerCollection.ListenerCollection();
|
|
106
|
+
this.channelCache = new Map();
|
|
107
|
+
this.channels = new Set([
|
|
108
|
+
'*'
|
|
109
|
+
]);
|
|
110
|
+
this.addChannels(...e);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.EventManager = EventManager;
|
package/dist/index6.mjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { clearInstance, forOf, isAsync, onlyAlphanumeric } from '@assemblerjs/core';
|
|
2
|
+
import { ListenerCollection } from './index5.mjs';
|
|
3
|
+
|
|
4
|
+
class EventManager {
|
|
5
|
+
dispose() {
|
|
6
|
+
this.listeners.dispose();
|
|
7
|
+
this.channels.clear();
|
|
8
|
+
this.channelCache.clear();
|
|
9
|
+
clearInstance(this, EventManager);
|
|
10
|
+
}
|
|
11
|
+
addChannels(...e) {
|
|
12
|
+
const s = forOf(e);
|
|
13
|
+
s((e)=>{
|
|
14
|
+
const n = this.cleanChannel(e);
|
|
15
|
+
if (this.channels.has(n)) {
|
|
16
|
+
throw new Error(`Channel '${n}' already exists.`);
|
|
17
|
+
}
|
|
18
|
+
this.channels.add(n);
|
|
19
|
+
});
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
removeChannels(...e) {
|
|
23
|
+
const s = forOf(e);
|
|
24
|
+
s((e)=>{
|
|
25
|
+
const n = this.cleanChannel(e);
|
|
26
|
+
if (n !== '*' && this.channels.has(n)) {
|
|
27
|
+
this.channels.delete(n);
|
|
28
|
+
this.listeners.remove(n);
|
|
29
|
+
this.onceListeners.remove(n);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
on(e, n) {
|
|
35
|
+
const s = this.cleanChannel(e);
|
|
36
|
+
this.listeners.add(s, n);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
once(e, n) {
|
|
40
|
+
const s = this.cleanChannel(e);
|
|
41
|
+
this.onceListeners.add(s, n);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
off(e, n) {
|
|
45
|
+
const s = this.cleanChannel(e);
|
|
46
|
+
this.listeners.remove(s, n);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
emit(e, ...n) {
|
|
50
|
+
const s = this.cleanChannel(e);
|
|
51
|
+
if (!this.channels.has(s)) {
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
const t = [
|
|
55
|
+
...(this.onceListeners.get('*') || []).map((e)=>({
|
|
56
|
+
listener: e,
|
|
57
|
+
once: true,
|
|
58
|
+
channel: '*'
|
|
59
|
+
})),
|
|
60
|
+
...(this.listeners.get('*') || []).map((e)=>({
|
|
61
|
+
listener: e,
|
|
62
|
+
once: false,
|
|
63
|
+
channel: '*'
|
|
64
|
+
})),
|
|
65
|
+
...(this.onceListeners.get(s) || []).map((e)=>({
|
|
66
|
+
listener: e,
|
|
67
|
+
once: true,
|
|
68
|
+
channel: s
|
|
69
|
+
})),
|
|
70
|
+
...(this.listeners.get(s) || []).map((e)=>({
|
|
71
|
+
listener: e,
|
|
72
|
+
once: false,
|
|
73
|
+
channel: s
|
|
74
|
+
}))
|
|
75
|
+
];
|
|
76
|
+
for (const { listener: e, once: s, channel: h } of t){
|
|
77
|
+
this.run(e, ...n);
|
|
78
|
+
if (s) {
|
|
79
|
+
this.onceListeners.remove(h, e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
run(e, ...n) {
|
|
85
|
+
if (isAsync(e)) {
|
|
86
|
+
const s = e;
|
|
87
|
+
return s(...n).then(()=>Promise.resolve());
|
|
88
|
+
}
|
|
89
|
+
e(...n);
|
|
90
|
+
}
|
|
91
|
+
cleanChannel(e) {
|
|
92
|
+
if (this.channelCache.has(e)) {
|
|
93
|
+
return this.channelCache.get(e);
|
|
94
|
+
}
|
|
95
|
+
const n = onlyAlphanumeric(e, '*', ':', '.', '-', '_');
|
|
96
|
+
this.channelCache.set(e, n);
|
|
97
|
+
return n;
|
|
98
|
+
}
|
|
99
|
+
constructor(...e){
|
|
100
|
+
this.listeners = new ListenerCollection();
|
|
101
|
+
this.onceListeners = new ListenerCollection();
|
|
102
|
+
this.channelCache = new Map();
|
|
103
|
+
this.channels = new Set([
|
|
104
|
+
'*'
|
|
105
|
+
]);
|
|
106
|
+
this.addChannels(...e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { EventManager };
|
package/dist/index7.js
ADDED
package/dist/index7.mjs
ADDED
package/dist/index8.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const eventManager_abstract = require('./index10.js');
|
|
6
|
+
|
|
7
|
+
class AbstractAssembler extends eventManager_abstract.AbstractEventManager {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.AbstractAssembler = AbstractAssembler;
|
package/dist/index8.mjs
ADDED
package/dist/index9.js
ADDED
package/dist/index9.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblerjs",
|
|
3
3
|
"description": "A general purpose Dependency Injection library for node and browser.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"author": "Benoît LAHOZ <info@benoitlahoz.io>",
|
|
6
6
|
"bugs": "https://github.com/benoitlahoz/assemblerjs/issues",
|
|
7
7
|
"homepage": "https://github.com/benoitlahoz/assemblerjs#README",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"reflect-metadata"
|
|
29
29
|
],
|
|
30
30
|
"license": "MIT",
|
|
31
|
+
"sideEffects": false,
|
|
31
32
|
"main": "./dist/index.js",
|
|
32
33
|
"module": "./dist/index.mjs",
|
|
33
34
|
"types": "./dist/index.d.ts",
|
|
@@ -47,13 +48,15 @@
|
|
|
47
48
|
],
|
|
48
49
|
"scripts": {
|
|
49
50
|
"test": "vitest --coverage --passWithNoTests",
|
|
50
|
-
"
|
|
51
|
+
"bench": "vitest bench",
|
|
52
|
+
"coverage": "vitest run --coverage --passWithNoTests && istanbul-badges-readme && node scripts/update-performance-badges.mjs"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
|
-
"@assemblerjs/core": "0.9.
|
|
55
|
+
"@assemblerjs/core": "^0.9.6",
|
|
56
|
+
"reflect-metadata": "0.2.2"
|
|
54
57
|
},
|
|
55
58
|
"devDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
59
|
+
"istanbul-badges-readme": "^0.2.3",
|
|
60
|
+
"vitest": "^3.0.0"
|
|
58
61
|
}
|
|
59
62
|
}
|