@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 CHANGED
@@ -235,8 +235,7 @@ export declare class Hook {
235
235
  * trigger event
236
236
  */
237
237
  static trigger: (
238
- label: string,
239
- options?: QueryOperatorOptions,
238
+ paths: string[],
240
239
  ...args: any[]
241
240
  ) => void
242
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.6.0",
3
+ "version": "0.6.3",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/hook.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const EventEmitter = require('events');
4
4
 
5
- const events = new Map(); // event tree
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.has(curr_key)) {
19
- curr.set(curr_key, new Map());
18
+ if (!curr[curr_key]) {
19
+ curr[curr_key] = {};
20
20
  }
21
- curr = curr.get(curr_key);
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[t], trace, step + 1, paths, args);
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;