@pisell/core 0.0.2

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.
Files changed (296) hide show
  1. package/README.md +1 -0
  2. package/es/app/app.d.ts +101 -0
  3. package/es/app/app.js +177 -0
  4. package/es/app/const.d.ts +4 -0
  5. package/es/app/const.js +6 -0
  6. package/es/app/index.d.ts +14 -0
  7. package/es/app/index.js +52 -0
  8. package/es/applicationManager/application.d.ts +197 -0
  9. package/es/applicationManager/application.js +469 -0
  10. package/es/applicationManager/index.d.ts +19 -0
  11. package/es/applicationManager/index.js +206 -0
  12. package/es/aws/index.d.ts +16 -0
  13. package/es/aws/index.js +76 -0
  14. package/es/cmd/const.d.ts +11 -0
  15. package/es/cmd/const.js +13 -0
  16. package/es/cmd/index.d.ts +13 -0
  17. package/es/cmd/index.js +91 -0
  18. package/es/cmd/type.d.ts +5 -0
  19. package/es/cmd/type.js +1 -0
  20. package/es/communicationManager/index.d.ts +59 -0
  21. package/es/communicationManager/index.js +174 -0
  22. package/es/config.d.ts +3 -0
  23. package/es/config.js +14 -0
  24. package/es/cookie/index.d.ts +13 -0
  25. package/es/cookie/index.js +47 -0
  26. package/es/css/global.less +73 -0
  27. package/es/css/index.less +31 -0
  28. package/es/css/variables.css +84 -0
  29. package/es/data/index.d.ts +8 -0
  30. package/es/data/index.js +16 -0
  31. package/es/history/config.d.ts +24 -0
  32. package/es/history/config.js +43 -0
  33. package/es/history/index.d.ts +26 -0
  34. package/es/history/index.js +80 -0
  35. package/es/history/type.d.ts +2 -0
  36. package/es/history/type.js +1 -0
  37. package/es/hooks/index.d.ts +12 -0
  38. package/es/hooks/index.js +13 -0
  39. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  40. package/es/hooks/useDelayedValue/index.js +26 -0
  41. package/es/hooks/useDispatch/index.d.ts +2 -0
  42. package/es/hooks/useDispatch/index.js +2 -0
  43. package/es/hooks/useLowCode/index.d.ts +13 -0
  44. package/es/hooks/useLowCode/index.js +74 -0
  45. package/es/hooks/useStore/index.d.ts +6 -0
  46. package/es/hooks/useStore/index.js +11 -0
  47. package/es/index.d.ts +8 -0
  48. package/es/index.js +10 -0
  49. package/es/indexDB/index.d.ts +296 -0
  50. package/es/indexDB/index.js +1619 -0
  51. package/es/locales/en.d.ts +3 -0
  52. package/es/locales/en.js +5 -0
  53. package/es/locales/index.d.ts +39 -0
  54. package/es/locales/index.js +199 -0
  55. package/es/locales/original.d.ts +3 -0
  56. package/es/locales/original.js +7 -0
  57. package/es/locales/type.d.ts +19 -0
  58. package/es/locales/type.js +1 -0
  59. package/es/locales/zh-CN.d.ts +3 -0
  60. package/es/locales/zh-CN.js +5 -0
  61. package/es/locales/zh-HK.d.ts +3 -0
  62. package/es/locales/zh-HK.js +5 -0
  63. package/es/logger/feishu.d.ts +11 -0
  64. package/es/logger/feishu.js +50 -0
  65. package/es/logger/index.d.ts +135 -0
  66. package/es/logger/index.js +870 -0
  67. package/es/menuManager/hooks.d.ts +17 -0
  68. package/es/menuManager/hooks.js +136 -0
  69. package/es/menuManager/index.d.ts +28 -0
  70. package/es/menuManager/index.js +165 -0
  71. package/es/models/global.d.ts +32 -0
  72. package/es/models/global.js +66 -0
  73. package/es/models/index.d.ts +45 -0
  74. package/es/models/index.js +65 -0
  75. package/es/models/type.d.ts +2 -0
  76. package/es/models/type.js +1 -0
  77. package/es/plugin/index.d.ts +0 -0
  78. package/es/plugin/index.js +0 -0
  79. package/es/pubsub/example.d.ts +5 -0
  80. package/es/pubsub/example.js +92 -0
  81. package/es/pubsub/index.d.ts +73 -0
  82. package/es/pubsub/index.js +166 -0
  83. package/es/render/index.d.ts +0 -0
  84. package/es/render/index.js +0 -0
  85. package/es/request/cache.d.ts +46 -0
  86. package/es/request/cache.js +372 -0
  87. package/es/request/cancelToken.d.ts +38 -0
  88. package/es/request/cancelToken.js +59 -0
  89. package/es/request/config.d.ts +3 -0
  90. package/es/request/config.js +63 -0
  91. package/es/request/constants.d.ts +2 -0
  92. package/es/request/constants.js +6 -0
  93. package/es/request/index.d.ts +24 -0
  94. package/es/request/index.js +267 -0
  95. package/es/request/pisell2Request.d.ts +6 -0
  96. package/es/request/pisell2Request.js +62 -0
  97. package/es/request/type.d.ts +57 -0
  98. package/es/request/type.js +10 -0
  99. package/es/request/utils.d.ts +46 -0
  100. package/es/request/utils.js +147 -0
  101. package/es/routes/config.d.ts +7 -0
  102. package/es/routes/config.js +17 -0
  103. package/es/routes/index.d.ts +28 -0
  104. package/es/routes/index.js +151 -0
  105. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  106. package/es/socket/components/SocketMonitorPage.js +485 -0
  107. package/es/socket/components/index.d.ts +2 -0
  108. package/es/socket/components/index.js +2 -0
  109. package/es/socket/constants.d.ts +33 -0
  110. package/es/socket/constants.js +39 -0
  111. package/es/socket/events.d.ts +31 -0
  112. package/es/socket/events.js +19 -0
  113. package/es/socket/heartbeat.d.ts +66 -0
  114. package/es/socket/heartbeat.js +184 -0
  115. package/es/socket/index.d.ts +61 -0
  116. package/es/socket/index.js +246 -0
  117. package/es/socket/monitor.d.ts +169 -0
  118. package/es/socket/monitor.js +448 -0
  119. package/es/socket/reconnect.d.ts +61 -0
  120. package/es/socket/reconnect.js +199 -0
  121. package/es/socket/socket.d.ts +130 -0
  122. package/es/socket/socket.js +613 -0
  123. package/es/socket/types.d.ts +85 -0
  124. package/es/socket/types.js +35 -0
  125. package/es/storage/index.d.ts +17 -0
  126. package/es/storage/index.js +46 -0
  127. package/es/tasks/index.d.ts +127 -0
  128. package/es/tasks/index.js +1119 -0
  129. package/es/tasks/scheduledTasksExample.d.ts +61 -0
  130. package/es/tasks/scheduledTasksExample.js +351 -0
  131. package/es/tasks/type.d.ts +100 -0
  132. package/es/tasks/type.js +1 -0
  133. package/es/tasks/useTasks.d.ts +5 -0
  134. package/es/tasks/useTasks.js +25 -0
  135. package/es/type.d.ts +2 -0
  136. package/es/type.js +1 -0
  137. package/es/utils/adaptiveThrottle/index.d.ts +36 -0
  138. package/es/utils/adaptiveThrottle/index.js +136 -0
  139. package/es/variables/VariablesProvider.d.ts +7 -0
  140. package/es/variables/VariablesProvider.js +12 -0
  141. package/es/variables/config.d.ts +3 -0
  142. package/es/variables/config.js +16 -0
  143. package/es/variables/index.d.ts +6 -0
  144. package/es/variables/index.js +5 -0
  145. package/es/variables/type.d.ts +2 -0
  146. package/es/variables/type.js +1 -0
  147. package/es/website/index.d.ts +6 -0
  148. package/es/website/index.js +65 -0
  149. package/lib/app/app.d.ts +101 -0
  150. package/lib/app/app.js +171 -0
  151. package/lib/app/const.d.ts +4 -0
  152. package/lib/app/const.js +33 -0
  153. package/lib/app/index.d.ts +14 -0
  154. package/lib/app/index.js +76 -0
  155. package/lib/applicationManager/application.d.ts +197 -0
  156. package/lib/applicationManager/application.js +280 -0
  157. package/lib/applicationManager/index.d.ts +19 -0
  158. package/lib/applicationManager/index.js +88 -0
  159. package/lib/aws/index.d.ts +16 -0
  160. package/lib/aws/index.js +67 -0
  161. package/lib/cmd/const.d.ts +11 -0
  162. package/lib/cmd/const.js +39 -0
  163. package/lib/cmd/index.d.ts +13 -0
  164. package/lib/cmd/index.js +96 -0
  165. package/lib/cmd/type.d.ts +5 -0
  166. package/lib/cmd/type.js +17 -0
  167. package/lib/communicationManager/index.d.ts +59 -0
  168. package/lib/communicationManager/index.js +102 -0
  169. package/lib/config.d.ts +3 -0
  170. package/lib/config.js +36 -0
  171. package/lib/cookie/index.d.ts +13 -0
  172. package/lib/cookie/index.js +62 -0
  173. package/lib/css/global.less +73 -0
  174. package/lib/css/index.less +31 -0
  175. package/lib/css/variables.css +84 -0
  176. package/lib/data/index.d.ts +8 -0
  177. package/lib/data/index.js +38 -0
  178. package/lib/history/config.d.ts +24 -0
  179. package/lib/history/config.js +41 -0
  180. package/lib/history/index.d.ts +26 -0
  181. package/lib/history/index.js +99 -0
  182. package/lib/history/type.d.ts +2 -0
  183. package/lib/history/type.js +17 -0
  184. package/lib/hooks/index.d.ts +12 -0
  185. package/lib/hooks/index.js +44 -0
  186. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  187. package/lib/hooks/useDelayedValue/index.js +36 -0
  188. package/lib/hooks/useDispatch/index.d.ts +2 -0
  189. package/lib/hooks/useDispatch/index.js +26 -0
  190. package/lib/hooks/useLowCode/index.d.ts +13 -0
  191. package/lib/hooks/useLowCode/index.js +75 -0
  192. package/lib/hooks/useStore/index.d.ts +6 -0
  193. package/lib/hooks/useStore/index.js +33 -0
  194. package/lib/index.d.ts +8 -0
  195. package/lib/index.js +58 -0
  196. package/lib/indexDB/index.d.ts +296 -0
  197. package/lib/indexDB/index.js +767 -0
  198. package/lib/locales/en.d.ts +3 -0
  199. package/lib/locales/en.js +29 -0
  200. package/lib/locales/index.d.ts +39 -0
  201. package/lib/locales/index.js +159 -0
  202. package/lib/locales/original.d.ts +3 -0
  203. package/lib/locales/original.js +31 -0
  204. package/lib/locales/type.d.ts +19 -0
  205. package/lib/locales/type.js +17 -0
  206. package/lib/locales/zh-CN.d.ts +3 -0
  207. package/lib/locales/zh-CN.js +29 -0
  208. package/lib/locales/zh-HK.d.ts +3 -0
  209. package/lib/locales/zh-HK.js +29 -0
  210. package/lib/logger/feishu.d.ts +11 -0
  211. package/lib/logger/feishu.js +52 -0
  212. package/lib/logger/index.d.ts +135 -0
  213. package/lib/logger/index.js +476 -0
  214. package/lib/menuManager/hooks.d.ts +17 -0
  215. package/lib/menuManager/hooks.js +135 -0
  216. package/lib/menuManager/index.d.ts +28 -0
  217. package/lib/menuManager/index.js +125 -0
  218. package/lib/models/global.d.ts +32 -0
  219. package/lib/models/global.js +62 -0
  220. package/lib/models/index.d.ts +45 -0
  221. package/lib/models/index.js +69 -0
  222. package/lib/models/type.d.ts +2 -0
  223. package/lib/models/type.js +17 -0
  224. package/lib/plugin/index.d.ts +0 -0
  225. package/lib/plugin/index.js +0 -0
  226. package/lib/pubsub/example.d.ts +5 -0
  227. package/lib/pubsub/example.js +61 -0
  228. package/lib/pubsub/index.d.ts +73 -0
  229. package/lib/pubsub/index.js +141 -0
  230. package/lib/render/index.d.ts +0 -0
  231. package/lib/render/index.js +0 -0
  232. package/lib/request/cache.d.ts +46 -0
  233. package/lib/request/cache.js +195 -0
  234. package/lib/request/cancelToken.d.ts +38 -0
  235. package/lib/request/cancelToken.js +59 -0
  236. package/lib/request/config.d.ts +3 -0
  237. package/lib/request/config.js +69 -0
  238. package/lib/request/constants.d.ts +2 -0
  239. package/lib/request/constants.js +34 -0
  240. package/lib/request/index.d.ts +24 -0
  241. package/lib/request/index.js +210 -0
  242. package/lib/request/pisell2Request.d.ts +6 -0
  243. package/lib/request/pisell2Request.js +75 -0
  244. package/lib/request/type.d.ts +57 -0
  245. package/lib/request/type.js +36 -0
  246. package/lib/request/utils.d.ts +46 -0
  247. package/lib/request/utils.js +113 -0
  248. package/lib/routes/config.d.ts +7 -0
  249. package/lib/routes/config.js +50 -0
  250. package/lib/routes/index.d.ts +28 -0
  251. package/lib/routes/index.js +121 -0
  252. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  253. package/lib/socket/components/SocketMonitorPage.js +340 -0
  254. package/lib/socket/components/index.d.ts +2 -0
  255. package/lib/socket/components/index.js +39 -0
  256. package/lib/socket/constants.d.ts +33 -0
  257. package/lib/socket/constants.js +62 -0
  258. package/lib/socket/events.d.ts +31 -0
  259. package/lib/socket/events.js +44 -0
  260. package/lib/socket/heartbeat.d.ts +66 -0
  261. package/lib/socket/heartbeat.js +157 -0
  262. package/lib/socket/index.d.ts +61 -0
  263. package/lib/socket/index.js +198 -0
  264. package/lib/socket/monitor.d.ts +169 -0
  265. package/lib/socket/monitor.js +350 -0
  266. package/lib/socket/reconnect.d.ts +61 -0
  267. package/lib/socket/reconnect.js +157 -0
  268. package/lib/socket/socket.d.ts +130 -0
  269. package/lib/socket/socket.js +426 -0
  270. package/lib/socket/types.d.ts +85 -0
  271. package/lib/socket/types.js +36 -0
  272. package/lib/storage/index.d.ts +17 -0
  273. package/lib/storage/index.js +64 -0
  274. package/lib/tasks/index.d.ts +127 -0
  275. package/lib/tasks/index.js +710 -0
  276. package/lib/tasks/scheduledTasksExample.d.ts +61 -0
  277. package/lib/tasks/scheduledTasksExample.js +267 -0
  278. package/lib/tasks/type.d.ts +100 -0
  279. package/lib/tasks/type.js +17 -0
  280. package/lib/tasks/useTasks.d.ts +5 -0
  281. package/lib/tasks/useTasks.js +37 -0
  282. package/lib/type.d.ts +2 -0
  283. package/lib/type.js +17 -0
  284. package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
  285. package/lib/utils/adaptiveThrottle/index.js +121 -0
  286. package/lib/variables/VariablesProvider.d.ts +7 -0
  287. package/lib/variables/VariablesProvider.js +51 -0
  288. package/lib/variables/config.d.ts +3 -0
  289. package/lib/variables/config.js +38 -0
  290. package/lib/variables/index.d.ts +6 -0
  291. package/lib/variables/index.js +29 -0
  292. package/lib/variables/type.d.ts +2 -0
  293. package/lib/variables/type.js +17 -0
  294. package/lib/website/index.d.ts +6 -0
  295. package/lib/website/index.js +75 -0
  296. package/package.json +49 -0
@@ -0,0 +1,92 @@
1
+ /**
2
+ * 发布订阅模块使用示例
3
+ * 此文件仅用于演示,不会被实际引入项目
4
+ */
5
+
6
+ import pubsub from "./index";
7
+
8
+ // ============= 示例1:基本使用 =============
9
+
10
+ // 定义事件类型(可选,但推荐)
11
+
12
+ // 订阅事件
13
+ var handleUserLogin = function handleUserLogin(userData) {
14
+ console.log("\u7528\u6237 ".concat(userData.username, " \u767B\u5F55\u6210\u529F"));
15
+ // 执行登录后的业务逻辑
16
+ };
17
+
18
+ // 保存订阅引用,方便后续取消订阅
19
+ var subscription = pubsub.subscribe('user:login', handleUserLogin);
20
+
21
+ // 模拟在其他组件中触发事件
22
+ setTimeout(function () {
23
+ pubsub.publish('user:login', {
24
+ userId: 'user_123',
25
+ username: '张三',
26
+ timestamp: Date.now()
27
+ });
28
+ }, 1000);
29
+
30
+ // 取消订阅(例如在组件销毁时)
31
+ // subscription.unsubscribe();
32
+
33
+ // ============= 示例2:一次性订阅 =============
34
+
35
+ pubsub.once('notification:welcome', function (message) {
36
+ console.log("\u6B22\u8FCE\u901A\u77E5: ".concat(message));
37
+ // 这个回调只会执行一次
38
+ });
39
+
40
+ // 连续触发两次事件,但回调只会执行一次
41
+ pubsub.publish('notification:welcome', '欢迎来到我们的平台!');
42
+ pubsub.publish('notification:welcome', '这条消息不会被处理'); // 这条不会触发回调
43
+
44
+ // ============= 示例3:多个参数 =============
45
+
46
+ pubsub.subscribe('cart:update', function (itemId, quantity, price) {
47
+ console.log("\u8D2D\u7269\u8F66\u66F4\u65B0: \u5546\u54C1ID=".concat(itemId, ", \u6570\u91CF=").concat(quantity, ", \u4EF7\u683C=").concat(price));
48
+ var subtotal = quantity * price;
49
+ console.log("\u5C0F\u8BA1: \xA5".concat(subtotal.toFixed(2)));
50
+ });
51
+
52
+ // 发布带有多个参数的事件
53
+ pubsub.publish('cart:update', 'product_456', 2, 99.5);
54
+
55
+ // ============= 示例4:错误处理 =============
56
+
57
+ // 订阅事件但包含可能出错的回调
58
+ pubsub.subscribe('data:process', function (data) {
59
+ console.log('处理数据...');
60
+ // 假设这里有一个错误
61
+ throw new Error('数据处理失败');
62
+ // 即使抛出错误,其他订阅者的回调仍会执行
63
+ });
64
+
65
+ // 另一个订阅同一事件的回调
66
+ pubsub.subscribe('data:process', function (data) {
67
+ console.log('第二个处理器仍然会执行');
68
+ });
69
+
70
+ // 触发事件,即使第一个回调出错,第二个回调仍会执行
71
+ pubsub.publish('data:process', {
72
+ id: 789
73
+ });
74
+
75
+ // ============= 示例5:检查订阅状态 =============
76
+
77
+ // 检查是否有订阅者
78
+ var hasLoginSubscribers = pubsub.hasSubscribers('user:login');
79
+ console.log("\u7528\u6237\u767B\u5F55\u4E8B\u4EF6\u662F\u5426\u6709\u8BA2\u9605\u8005: ".concat(hasLoginSubscribers));
80
+
81
+ // 获取订阅者数量
82
+ var loginSubscriberCount = pubsub.getSubscriberCount('user:login');
83
+ console.log("\u7528\u6237\u767B\u5F55\u4E8B\u4EF6\u7684\u8BA2\u9605\u8005\u6570\u91CF: ".concat(loginSubscriberCount));
84
+
85
+ // ============= 示例6:清除事件 =============
86
+
87
+ // 清除特定事件的所有订阅
88
+ pubsub.clearEvent('user:login');
89
+ console.log('已清除所有用户登录事件的订阅');
90
+
91
+ // 全局清除(慎用)
92
+ // pubsub.clearAllEvents();
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 发布订阅模块
3
+ * 用于组件/服务间的事件通信
4
+ */
5
+ declare type EventCallback = (...args: any[]) => void;
6
+ interface EventSubscription {
7
+ unsubscribe: () => void;
8
+ }
9
+ declare class PubSub {
10
+ private events;
11
+ /**
12
+ * 订阅事件
13
+ * @param event 事件名称
14
+ * @param callback 回调函数
15
+ * @returns 订阅对象,可用于取消订阅
16
+ */
17
+ subscribe(event: string, callback: EventCallback): EventSubscription;
18
+ /**
19
+ * 取消订阅事件
20
+ * @param event 事件名称
21
+ * @param callback 回调函数
22
+ * @returns 是否成功取消订阅
23
+ */
24
+ unsubscribe(event: string, callback: EventCallback): boolean;
25
+ /**
26
+ * 发布事件
27
+ * @param event 事件名称
28
+ * @param args 事件参数
29
+ */
30
+ publish(event: string, ...args: any[]): void;
31
+ /**
32
+ * @title: 异步发布, 某些事件需要延迟发布
33
+ * @description:
34
+ * @param {string} event
35
+ * @param {number} timeout
36
+ * @param {array} args
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ */
40
+ publishDelay(event: string, delay?: number, ...args: any[]): void;
41
+ /**
42
+ * 移除某个事件的所有订阅
43
+ * @param event 事件名称
44
+ * @returns 是否成功移除
45
+ */
46
+ clearEvent(event: string): boolean;
47
+ /**
48
+ * 移除所有事件订阅
49
+ */
50
+ clearAllEvents(): void;
51
+ /**
52
+ * 获取事件的订阅数量
53
+ * @param event 事件名称
54
+ * @returns 订阅数量
55
+ */
56
+ getSubscriberCount(event: string): number;
57
+ /**
58
+ * 检查事件是否有订阅者
59
+ * @param event 事件名称
60
+ * @returns 是否有订阅者
61
+ */
62
+ hasSubscribers(event: string): boolean;
63
+ /**
64
+ * 一次性订阅事件,事件触发后自动取消订阅
65
+ * @param event 事件名称
66
+ * @param callback 回调函数
67
+ * @returns 订阅对象,可用于取消订阅
68
+ */
69
+ once(event: string, callback: EventCallback): EventSubscription;
70
+ }
71
+ declare const pubsub: PubSub;
72
+ export default pubsub;
73
+ export { PubSub, type EventCallback, type EventSubscription };
@@ -0,0 +1,166 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ /**
9
+ * 发布订阅模块
10
+ * 用于组件/服务间的事件通信
11
+ */
12
+ var PubSub = /*#__PURE__*/function () {
13
+ function PubSub() {
14
+ _classCallCheck(this, PubSub);
15
+ _defineProperty(this, "events", new Map());
16
+ }
17
+ _createClass(PubSub, [{
18
+ key: "subscribe",
19
+ value:
20
+ /**
21
+ * 订阅事件
22
+ * @param event 事件名称
23
+ * @param callback 回调函数
24
+ * @returns 订阅对象,可用于取消订阅
25
+ */
26
+ function subscribe(event, callback) {
27
+ var _this = this;
28
+ if (!this.events.has(event)) {
29
+ this.events.set(event, new Set());
30
+ }
31
+ var callbacks = this.events.get(event);
32
+ callbacks.add(callback);
33
+ return {
34
+ unsubscribe: function unsubscribe() {
35
+ _this.unsubscribe(event, callback);
36
+ }
37
+ };
38
+ }
39
+
40
+ /**
41
+ * 取消订阅事件
42
+ * @param event 事件名称
43
+ * @param callback 回调函数
44
+ * @returns 是否成功取消订阅
45
+ */
46
+ }, {
47
+ key: "unsubscribe",
48
+ value: function unsubscribe(event, callback) {
49
+ var callbacks = this.events.get(event);
50
+ if (!callbacks) {
51
+ return false;
52
+ }
53
+ return callbacks.delete(callback);
54
+ }
55
+
56
+ /**
57
+ * 发布事件
58
+ * @param event 事件名称
59
+ * @param args 事件参数
60
+ */
61
+ }, {
62
+ key: "publish",
63
+ value: function publish(event) {
64
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
65
+ args[_key - 1] = arguments[_key];
66
+ }
67
+ var callbacks = this.events.get(event);
68
+ if (!callbacks) {
69
+ return;
70
+ }
71
+ callbacks.forEach(function (callback) {
72
+ try {
73
+ callback.apply(void 0, args);
74
+ } catch (error) {
75
+ console.error("\u6267\u884C\u4E8B\u4EF6\"".concat(event, "\"\u7684\u56DE\u8C03\u65F6\u51FA\u9519:"), error);
76
+ }
77
+ });
78
+ }
79
+
80
+ /**
81
+ * @title: 异步发布, 某些事件需要延迟发布
82
+ * @description:
83
+ * @param {string} event
84
+ * @param {number} timeout
85
+ * @param {array} args
86
+ * @return {*}
87
+ * @Author: zhiwei.Wang
88
+ */
89
+ }, {
90
+ key: "publishDelay",
91
+ value: function publishDelay(event) {
92
+ var _this2 = this;
93
+ var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
94
+ for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
95
+ args[_key2 - 2] = arguments[_key2];
96
+ }
97
+ setTimeout(function () {
98
+ _this2.publish.apply(_this2, [event].concat(args));
99
+ }, delay);
100
+ }
101
+
102
+ /**
103
+ * 移除某个事件的所有订阅
104
+ * @param event 事件名称
105
+ * @returns 是否成功移除
106
+ */
107
+ }, {
108
+ key: "clearEvent",
109
+ value: function clearEvent(event) {
110
+ return this.events.delete(event);
111
+ }
112
+
113
+ /**
114
+ * 移除所有事件订阅
115
+ */
116
+ }, {
117
+ key: "clearAllEvents",
118
+ value: function clearAllEvents() {
119
+ this.events.clear();
120
+ }
121
+
122
+ /**
123
+ * 获取事件的订阅数量
124
+ * @param event 事件名称
125
+ * @returns 订阅数量
126
+ */
127
+ }, {
128
+ key: "getSubscriberCount",
129
+ value: function getSubscriberCount(event) {
130
+ var callbacks = this.events.get(event);
131
+ return callbacks ? callbacks.size : 0;
132
+ }
133
+
134
+ /**
135
+ * 检查事件是否有订阅者
136
+ * @param event 事件名称
137
+ * @returns 是否有订阅者
138
+ */
139
+ }, {
140
+ key: "hasSubscribers",
141
+ value: function hasSubscribers(event) {
142
+ return this.getSubscriberCount(event) > 0;
143
+ }
144
+
145
+ /**
146
+ * 一次性订阅事件,事件触发后自动取消订阅
147
+ * @param event 事件名称
148
+ * @param callback 回调函数
149
+ * @returns 订阅对象,可用于取消订阅
150
+ */
151
+ }, {
152
+ key: "once",
153
+ value: function once(event, callback) {
154
+ var _this3 = this;
155
+ var wrappedCallback = function wrappedCallback() {
156
+ _this3.unsubscribe(event, wrappedCallback);
157
+ callback.apply(void 0, arguments);
158
+ };
159
+ return this.subscribe(event, wrappedCallback);
160
+ }
161
+ }]);
162
+ return PubSub;
163
+ }(); // 创建单例实例
164
+ var pubsub = new PubSub();
165
+ export default pubsub;
166
+ export { PubSub };
File without changes
File without changes
@@ -0,0 +1,46 @@
1
+ import { CacheProps } from './type';
2
+ export declare type CacheType = 'memory' | 'storage' | 'indexDB';
3
+ /**
4
+ * @title: 设置缓存
5
+ * @description:
6
+ * @return {*}
7
+ * @Author: zhiwei.Wang
8
+ */
9
+ export declare const setCache: (key: string, data: any, cache: CacheProps) => Promise<void>;
10
+ /**
11
+ * @title: 删除缓存数据
12
+ * @description:
13
+ * @return {*}
14
+ * @Author: zhiwei.Wang
15
+ */
16
+ export declare const removeCache: (key: string, cache: CacheProps) => void;
17
+ /**
18
+ * @title: 获取数据
19
+ * @description:
20
+ * @param {any} url
21
+ * @param {any} data
22
+ * @return {*}
23
+ * @Author: zhiwei.Wang
24
+ */
25
+ export declare const getCacheData: (url: string, data: any, cache: CacheProps) => Promise<any>;
26
+ /**
27
+ * @title: 设置缓存
28
+ * @description:
29
+ * @param {any} url 路径
30
+ * @param {any} data 参数
31
+ * @param {any} res 数据
32
+ * @return {*}
33
+ * @Author: zhiwei.Wang
34
+ */
35
+ export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
+ /**
37
+ * @title: 缓存函数包装器
38
+ * @description:
39
+ * @param {any} url
40
+ * @param {any} data
41
+ * @param {any} config
42
+ * @param {any} fn
43
+ * @return {*}
44
+ * @Author: zhiwei.Wang
45
+ */
46
+ export declare const cacheFn: (props: any, fn: any) => Promise<any>;