@axiosleo/orm-mysql 0.6.0 → 0.6.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/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/hook.js +17 -9
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/hook.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
|
|
5
|
-
const events =
|
|
5
|
+
const events = {}; // event tree
|
|
6
6
|
const hook = new EventEmitter();
|
|
7
7
|
|
|
8
8
|
const push = (callback, trace = []) => {
|
|
@@ -15,10 +15,10 @@ const push = (callback, trace = []) => {
|
|
|
15
15
|
curr_key = '*';
|
|
16
16
|
}
|
|
17
17
|
event_name_items.push(curr_key);
|
|
18
|
-
if (!curr
|
|
19
|
-
curr
|
|
18
|
+
if (!curr[curr_key]) {
|
|
19
|
+
curr[curr_key] = {};
|
|
20
20
|
}
|
|
21
|
-
curr = curr
|
|
21
|
+
curr = curr[curr_key];
|
|
22
22
|
step++;
|
|
23
23
|
}
|
|
24
24
|
let event_name = event_name_items.join('::');
|
|
@@ -33,6 +33,14 @@ const pushEvent = (options = {}) => {
|
|
|
33
33
|
return { event_name, label, table, opt, callback };
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @param {Map} curr
|
|
38
|
+
* @param {*} trace
|
|
39
|
+
* @param {*} step
|
|
40
|
+
* @param {*} paths
|
|
41
|
+
* @param {*} args
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
36
44
|
const eventRecur = (curr, trace, step, paths, args) => {
|
|
37
45
|
if (step === trace.length) {
|
|
38
46
|
hook.emit(paths.join('::'), ...args);
|
|
@@ -41,7 +49,7 @@ const eventRecur = (curr, trace, step, paths, args) => {
|
|
|
41
49
|
const t = trace[step];
|
|
42
50
|
if (curr['*']) {
|
|
43
51
|
paths[step] = '*';
|
|
44
|
-
eventRecur(curr[
|
|
52
|
+
eventRecur(curr['*'], trace, step + 1, paths, args);
|
|
45
53
|
}
|
|
46
54
|
if (curr[t]) {
|
|
47
55
|
paths[step] = t;
|
|
@@ -65,15 +73,15 @@ class Hook {
|
|
|
65
73
|
});
|
|
66
74
|
}
|
|
67
75
|
|
|
76
|
+
static register(callback, ...paths) {
|
|
77
|
+
push(callback, paths);
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
static listen(options = {}, ...args) {
|
|
69
81
|
const { label, table, opt } = options;
|
|
70
82
|
Hook.trigger([label, table, opt], ...args);
|
|
71
83
|
}
|
|
72
84
|
|
|
73
|
-
static register(callback, ...paths) {
|
|
74
|
-
push(callback, paths);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
85
|
static trigger(paths = [], ...args) {
|
|
78
86
|
let curr = events;
|
|
79
87
|
let step = 0;
|