@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.
- package/README.md +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +63 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +101 -0
- package/lib/app/app.js +171 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +69 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- 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>;
|