alemonjs 2.1.0-alpha.47 → 2.1.0-alpha.48

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.
@@ -6,7 +6,7 @@
6
6
  const lazy = (fnc) => {
7
7
  return async () => (await fnc()).default;
8
8
  };
9
- const defineResponse = (responses) => {
9
+ const defineResponse = responses => {
10
10
  return {
11
11
  current: responses
12
12
  };
@@ -5,7 +5,7 @@ import 'yaml';
5
5
  import { showErrorModule } from '../core/utils.js';
6
6
  import { useMessage } from './hook-use-api.js';
7
7
 
8
- const createCallHandler = (valueEvent) => {
8
+ const createCallHandler = valueEvent => {
9
9
  const [message] = useMessage(valueEvent);
10
10
  // 开始处理 heandler
11
11
  const callHandler = (currents, nextEvent) => {
@@ -33,6 +33,13 @@ const expendEventRoute = (valueEvent, select, nextCycle) => {
33
33
  return;
34
34
  }
35
35
  const node = nodes[idx - 1];
36
+ if (node?.selects) {
37
+ const selects = Array.isArray(node.selects) ? node.selects : [node.selects];
38
+ if (!selects.includes(select)) {
39
+ void nextNode();
40
+ return;
41
+ }
42
+ }
36
43
  // 正则匹配
37
44
  if (EventMessageText.includes(select) && node.regular) {
38
45
  const reg = new RegExp(node.regular);
@@ -57,7 +64,7 @@ const expendEventRoute = (valueEvent, select, nextCycle) => {
57
64
  try {
58
65
  const currents = [];
59
66
  for (const item of currentsAndMiddleware) {
60
- const app = isAsyncFunction(item) ? (await item()) : item();
67
+ const app = isAsyncFunction(item) ? await item() : item();
61
68
  // 没有 default。因为是 import x from './';
62
69
  // 中间件也有 selects。
63
70
  // 如果 发现 和当前要处理的 selects 不匹配。
@@ -90,10 +97,6 @@ const expendEventRoute = (valueEvent, select, nextCycle) => {
90
97
  };
91
98
  void nextNode();
92
99
  };
93
- if (routes.length === 0) {
94
- nextCycle();
95
- return;
96
- }
97
100
  void processChildren(routes, [], nextCycle);
98
101
  };
99
102
 
package/lib/app/load.js CHANGED
@@ -89,7 +89,6 @@ const loadChildren = async (mainPath, appName) => {
89
89
  catch (e) {
90
90
  void unMounted(e);
91
91
  }
92
- ;
93
92
  };
94
93
  const fileMounted = async () => {
95
94
  const appsDir = join(mainDir, 'apps');
@@ -12,17 +12,17 @@ type ChildrenCycle = {
12
12
  * 创建时
13
13
  * @returns
14
14
  */
15
- onCreated?: () => (void | Promise<void>);
15
+ onCreated?: () => void | Promise<void>;
16
16
  /**
17
17
  * 挂载时。得到属于自己的 store
18
18
  * @returns
19
19
  */
20
- onMounted?: (store: StroreParam) => (void | Promise<void>);
20
+ onMounted?: (store: StroreParam) => void | Promise<void>;
21
21
  /**
22
22
  * 卸载时
23
23
  * @returns
24
24
  */
25
- unMounted?: (error: any) => (void | Promise<void>);
25
+ unMounted?: (error: any) => void | Promise<void>;
26
26
  };
27
27
  /**
28
28
  * 控制生命周期
@@ -52,6 +52,7 @@ type OnMiddlewareValue<C, T extends EventKeys> = {
52
52
  };
53
53
  type ResponseRoute = {
54
54
  regular?: RegExp;
55
+ selects?: EventKeys | EventKeys[];
55
56
  handler: () => Promise<any>;
56
57
  children?: ResponseRoute[];
57
58
  };
@@ -62,7 +63,7 @@ type childrenCallbackRes = {
62
63
  response?: ReturnType<DefineResponseFunc>;
63
64
  };
64
65
  type childrenCallback = ChildrenCycle & {
65
- register?: () => ((childrenCallbackRes | void)) | Promise<(childrenCallbackRes | void)>;
66
+ register?: () => (childrenCallbackRes | void) | Promise<childrenCallbackRes | void>;
66
67
  };
67
68
  type DefineChildrenCallback = (() => Promise<childrenCallback> | childrenCallback) | childrenCallback;
68
69
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.0-alpha.47",
3
+ "version": "2.1.0-alpha.48",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",