@pisell/pisellos 0.0.214 → 0.0.216
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/dist/core/index.js +2 -1
- package/dist/effects/index.d.ts +4 -3
- package/dist/effects/index.js +15 -6
- package/dist/modules/AccountList/index.d.ts +7 -1
- package/dist/modules/AccountList/index.js +81 -14
- package/dist/modules/AccountList/types.d.ts +28 -0
- package/dist/modules/AccountList/types.js +8 -0
- package/dist/modules/Customer/constants.d.ts +7 -0
- package/dist/modules/Customer/constants.js +12 -0
- package/dist/modules/Customer/index.d.ts +89 -0
- package/dist/modules/Customer/index.js +440 -0
- package/dist/modules/Customer/types.d.ts +130 -0
- package/dist/modules/Customer/types.js +39 -0
- package/dist/modules/ProductList/index.d.ts +12 -1
- package/dist/modules/ProductList/index.js +28 -4
- package/dist/modules/Rules/index.js +7 -5
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/window.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +8 -15
- package/dist/solution/BookingTicket/index.d.ts +134 -0
- package/dist/solution/BookingTicket/index.js +534 -0
- package/dist/solution/BookingTicket/types.d.ts +66 -0
- package/dist/solution/BookingTicket/types.js +41 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +19 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +182 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +59 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +201 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
- package/dist/solution/ShopDiscount/index.js +4 -2
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/utils/task.d.ts +31 -0
- package/dist/utils/task.js +150 -0
- package/dist/utils/watch.d.ts +102 -0
- package/dist/utils/watch.js +294 -0
- package/lib/core/index.js +1 -1
- package/lib/effects/index.d.ts +4 -3
- package/lib/effects/index.js +4 -1
- package/lib/modules/AccountList/index.d.ts +7 -1
- package/lib/modules/AccountList/index.js +27 -0
- package/lib/modules/AccountList/types.d.ts +28 -0
- package/lib/modules/Customer/constants.d.ts +7 -0
- package/lib/modules/Customer/constants.js +39 -0
- package/lib/modules/Customer/index.d.ts +89 -0
- package/lib/modules/Customer/index.js +305 -0
- package/lib/modules/Customer/types.d.ts +130 -0
- package/lib/modules/Customer/types.js +35 -0
- package/lib/modules/ProductList/index.d.ts +12 -1
- package/lib/modules/ProductList/index.js +30 -3
- package/lib/modules/Rules/index.js +4 -3
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -0
- package/lib/plugins/window.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +0 -7
- package/lib/solution/BookingTicket/index.d.ts +134 -0
- package/lib/solution/BookingTicket/index.js +331 -0
- package/lib/solution/BookingTicket/types.d.ts +66 -0
- package/lib/solution/BookingTicket/types.js +70 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +19 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +137 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +59 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +149 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +2 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/utils/task.d.ts +31 -0
- package/lib/utils/task.js +84 -0
- package/lib/utils/watch.d.ts +102 -0
- package/lib/utils/watch.js +217 -0
- package/package.json +1 -1
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/solution/BookingTicket/utils/scan/scanCache.ts
|
|
20
|
+
var scanCache_exports = {};
|
|
21
|
+
__export(scanCache_exports, {
|
|
22
|
+
default: () => scanCache_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(scanCache_exports);
|
|
25
|
+
var compressData = (data) => {
|
|
26
|
+
try {
|
|
27
|
+
if (data === void 0) {
|
|
28
|
+
return "undefined";
|
|
29
|
+
}
|
|
30
|
+
return JSON.stringify(data);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.warn("数据压缩失败:", error);
|
|
33
|
+
return JSON.stringify(data);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var decompressData = (compressedData) => {
|
|
37
|
+
try {
|
|
38
|
+
if (compressedData === "undefined") {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
return JSON.parse(compressedData);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.warn("数据解压缩失败:", error);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var LRUCache = class {
|
|
48
|
+
constructor(maxSize = 100) {
|
|
49
|
+
this.head = null;
|
|
50
|
+
// 最久未使用的节点
|
|
51
|
+
this.tail = null;
|
|
52
|
+
// 最近使用的节点
|
|
53
|
+
this.keyMap = /* @__PURE__ */ new Map();
|
|
54
|
+
this.maxSize = maxSize;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 将节点移动到链表尾部(最近使用)
|
|
58
|
+
* @param node 要移动的节点
|
|
59
|
+
*/
|
|
60
|
+
moveToTail(node) {
|
|
61
|
+
if (this.tail === node)
|
|
62
|
+
return;
|
|
63
|
+
if (node.prev) {
|
|
64
|
+
node.prev.next = node.next;
|
|
65
|
+
}
|
|
66
|
+
if (node.next) {
|
|
67
|
+
node.next.prev = node.prev;
|
|
68
|
+
}
|
|
69
|
+
if (this.head === node) {
|
|
70
|
+
this.head = node.next;
|
|
71
|
+
}
|
|
72
|
+
if (this.tail) {
|
|
73
|
+
this.tail.next = node;
|
|
74
|
+
}
|
|
75
|
+
node.prev = this.tail;
|
|
76
|
+
node.next = null;
|
|
77
|
+
this.tail = node;
|
|
78
|
+
if (!this.head) {
|
|
79
|
+
this.head = node;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 添加新节点到链表尾部
|
|
84
|
+
* @param key 缓存键
|
|
85
|
+
* @param compressedData 压缩后的数据
|
|
86
|
+
* @param timestamp 时间戳
|
|
87
|
+
*/
|
|
88
|
+
addToTail(key, compressedData, timestamp) {
|
|
89
|
+
const oldTail = this.tail;
|
|
90
|
+
const node = {
|
|
91
|
+
key,
|
|
92
|
+
compressedData,
|
|
93
|
+
timestamp,
|
|
94
|
+
prev: oldTail,
|
|
95
|
+
// 使用保存的引用,避免循环引用
|
|
96
|
+
next: null
|
|
97
|
+
};
|
|
98
|
+
this.keyMap.set(key, node);
|
|
99
|
+
if (oldTail) {
|
|
100
|
+
oldTail.next = node;
|
|
101
|
+
}
|
|
102
|
+
this.tail = node;
|
|
103
|
+
if (!this.head) {
|
|
104
|
+
this.head = node;
|
|
105
|
+
}
|
|
106
|
+
return node;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 从链表中移除节点
|
|
110
|
+
* @param node 要移除的节点
|
|
111
|
+
*/
|
|
112
|
+
removeNode(node) {
|
|
113
|
+
if (node.prev) {
|
|
114
|
+
node.prev.next = node.next;
|
|
115
|
+
}
|
|
116
|
+
if (node.next) {
|
|
117
|
+
node.next.prev = node.prev;
|
|
118
|
+
}
|
|
119
|
+
if (this.head === node) {
|
|
120
|
+
this.head = node.next;
|
|
121
|
+
}
|
|
122
|
+
if (this.tail === node) {
|
|
123
|
+
this.tail = node.prev;
|
|
124
|
+
}
|
|
125
|
+
this.keyMap.delete(node.key);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 移除最久未使用的节点(链表头部)
|
|
129
|
+
*/
|
|
130
|
+
removeOldest() {
|
|
131
|
+
if (this.head) {
|
|
132
|
+
this.removeNode(this.head);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 设置缓存
|
|
137
|
+
* @param key 缓存键
|
|
138
|
+
* @param data 缓存数据
|
|
139
|
+
*/
|
|
140
|
+
set(key, data) {
|
|
141
|
+
const compressedData = compressData(data);
|
|
142
|
+
const timestamp = Date.now();
|
|
143
|
+
const existingNode = this.keyMap.get(key);
|
|
144
|
+
if (existingNode) {
|
|
145
|
+
existingNode.compressedData = compressedData;
|
|
146
|
+
existingNode.timestamp = timestamp;
|
|
147
|
+
this.moveToTail(existingNode);
|
|
148
|
+
} else {
|
|
149
|
+
if (this.keyMap.size >= this.maxSize) {
|
|
150
|
+
this.removeOldest();
|
|
151
|
+
}
|
|
152
|
+
this.addToTail(key, compressedData, timestamp);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 获取缓存
|
|
157
|
+
* @param key 缓存键
|
|
158
|
+
* @returns 缓存数据或undefined
|
|
159
|
+
*/
|
|
160
|
+
get(key) {
|
|
161
|
+
const node = this.keyMap.get(key);
|
|
162
|
+
if (node) {
|
|
163
|
+
const decompressedData = decompressData(node.compressedData);
|
|
164
|
+
if (decompressedData !== null) {
|
|
165
|
+
node.timestamp = Date.now();
|
|
166
|
+
this.moveToTail(node);
|
|
167
|
+
return decompressedData;
|
|
168
|
+
} else {
|
|
169
|
+
this.removeNode(node);
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 检查是否存在缓存
|
|
177
|
+
* @param key 缓存键
|
|
178
|
+
* @returns 是否存在
|
|
179
|
+
*/
|
|
180
|
+
has(key) {
|
|
181
|
+
return this.keyMap.has(key);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 清除所有缓存
|
|
185
|
+
*/
|
|
186
|
+
clear() {
|
|
187
|
+
let current = this.head;
|
|
188
|
+
while (current) {
|
|
189
|
+
const next = current.next;
|
|
190
|
+
current.prev = null;
|
|
191
|
+
current.next = null;
|
|
192
|
+
current = next;
|
|
193
|
+
}
|
|
194
|
+
this.keyMap.clear();
|
|
195
|
+
this.head = null;
|
|
196
|
+
this.tail = null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 获取缓存大小
|
|
200
|
+
* @returns 当前缓存数量
|
|
201
|
+
*/
|
|
202
|
+
size() {
|
|
203
|
+
return this.keyMap.size;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 获取缓存统计信息
|
|
207
|
+
* @returns 缓存统计信息
|
|
208
|
+
*/
|
|
209
|
+
getStats() {
|
|
210
|
+
return {
|
|
211
|
+
size: this.keyMap.size,
|
|
212
|
+
maxSize: this.maxSize,
|
|
213
|
+
usage: Math.round(this.keyMap.size / this.maxSize * 100)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 删除指定的缓存项
|
|
218
|
+
* @param key 要删除的缓存键
|
|
219
|
+
* @returns 是否删除成功
|
|
220
|
+
*/
|
|
221
|
+
delete(key) {
|
|
222
|
+
const node = this.keyMap.get(key);
|
|
223
|
+
if (node) {
|
|
224
|
+
this.removeNode(node);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var scanCache = new LRUCache();
|
|
231
|
+
var scanCache_default = scanCache;
|
|
@@ -38,6 +38,7 @@ var import_types = require("./types");
|
|
|
38
38
|
var import_Discount = require("../../modules/Discount");
|
|
39
39
|
var import_Rules = require("../../modules/Rules");
|
|
40
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
|
+
var import_lodash_es = require("lodash-es");
|
|
41
42
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
42
43
|
constructor(name, version) {
|
|
43
44
|
super(name, version);
|
|
@@ -337,7 +338,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
337
338
|
var _a2;
|
|
338
339
|
const targetProduct = productList.find((n) => n.id === id);
|
|
339
340
|
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
340
|
-
return Number(product == null ? void 0 : product.total)
|
|
341
|
+
return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
|
|
341
342
|
};
|
|
342
343
|
const allUsedProductIds = newDiscountList.map((n) => {
|
|
343
344
|
var _a2;
|
package/lib/solution/index.d.ts
CHANGED
package/lib/solution/index.js
CHANGED
|
@@ -18,10 +18,12 @@ var solution_exports = {};
|
|
|
18
18
|
module.exports = __toCommonJS(solution_exports);
|
|
19
19
|
__reExport(solution_exports, require("./BuyTickets"), module.exports);
|
|
20
20
|
__reExport(solution_exports, require("./BookingByStep"), module.exports);
|
|
21
|
+
__reExport(solution_exports, require("./BookingTicket"), module.exports);
|
|
21
22
|
__reExport(solution_exports, require("./ShopDiscount"), module.exports);
|
|
22
23
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23
24
|
0 && (module.exports = {
|
|
24
25
|
...require("./BuyTickets"),
|
|
25
26
|
...require("./BookingByStep"),
|
|
27
|
+
...require("./BookingTicket"),
|
|
26
28
|
...require("./ShopDiscount")
|
|
27
29
|
});
|
package/lib/types/index.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ export interface PisellCore {
|
|
|
38
38
|
getModuleExports: <T = any>(name: string) => T | null;
|
|
39
39
|
hasModule: (name: string) => boolean;
|
|
40
40
|
effects: {
|
|
41
|
-
on: (event: string, callback: (payload: any) => void) => void;
|
|
41
|
+
on: (event: string, callback: (payload: any) => void) => () => void;
|
|
42
|
+
once: (event: string, callback: (payload: any) => void) => () => void;
|
|
43
|
+
off: (event: string, callback: (payload: any) => void) => void;
|
|
42
44
|
emit: (event: string, payload: any, value?: any) => Promise<{
|
|
43
45
|
status: boolean;
|
|
44
46
|
data: any;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type Action = (...args: any[]) => Promise<any>;
|
|
2
|
+
type Task = {
|
|
3
|
+
type: string;
|
|
4
|
+
actionParams?: Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
declare class Tasks {
|
|
7
|
+
private actions;
|
|
8
|
+
private taskQueue;
|
|
9
|
+
isRunning: boolean;
|
|
10
|
+
constructor(actions?: Map<string, Action>);
|
|
11
|
+
/**
|
|
12
|
+
* 清空任务队列
|
|
13
|
+
*/
|
|
14
|
+
clear(): void;
|
|
15
|
+
/**
|
|
16
|
+
* 添加action
|
|
17
|
+
* @param name action名称
|
|
18
|
+
* @param action action函数
|
|
19
|
+
*/
|
|
20
|
+
addAction(name: string, action: Action): void;
|
|
21
|
+
/**
|
|
22
|
+
* 添加任务
|
|
23
|
+
* @param task 任务
|
|
24
|
+
*/
|
|
25
|
+
addTask(task: Task): void;
|
|
26
|
+
/**
|
|
27
|
+
* 执行任务
|
|
28
|
+
*/
|
|
29
|
+
run(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export default Tasks;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/task.ts
|
|
20
|
+
var task_exports = {};
|
|
21
|
+
__export(task_exports, {
|
|
22
|
+
default: () => task_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(task_exports);
|
|
25
|
+
var Tasks = class {
|
|
26
|
+
constructor(actions) {
|
|
27
|
+
this.actions = /* @__PURE__ */ new Map();
|
|
28
|
+
this.taskQueue = [];
|
|
29
|
+
this.isRunning = false;
|
|
30
|
+
if (actions) {
|
|
31
|
+
this.actions = actions;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 清空任务队列
|
|
36
|
+
*/
|
|
37
|
+
clear() {
|
|
38
|
+
this.actions.clear();
|
|
39
|
+
this.taskQueue = [];
|
|
40
|
+
this.isRunning = false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 添加action
|
|
44
|
+
* @param name action名称
|
|
45
|
+
* @param action action函数
|
|
46
|
+
*/
|
|
47
|
+
addAction(name, action) {
|
|
48
|
+
this.actions.set(name, action);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 添加任务
|
|
52
|
+
* @param task 任务
|
|
53
|
+
*/
|
|
54
|
+
addTask(task) {
|
|
55
|
+
this.taskQueue.push(task);
|
|
56
|
+
this.run();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 执行任务
|
|
60
|
+
*/
|
|
61
|
+
async run() {
|
|
62
|
+
if (this.isRunning) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (this.taskQueue.length === 0) {
|
|
66
|
+
this.isRunning = false;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.isRunning = true;
|
|
70
|
+
while (this.taskQueue.length > 0) {
|
|
71
|
+
const task = this.taskQueue.shift();
|
|
72
|
+
if (!task) {
|
|
73
|
+
this.isRunning = false;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const action = this.actions.get(task.type);
|
|
77
|
+
if (action) {
|
|
78
|
+
await action((task == null ? void 0 : task.actionParams) || {});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.isRunning = false;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var task_default = Tasks;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 监听模块
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
export type WatchEventCallback = (...args: any[]) => void;
|
|
6
|
+
export type WatchEventItem = {
|
|
7
|
+
key: string;
|
|
8
|
+
callback: WatchEventCallback;
|
|
9
|
+
};
|
|
10
|
+
export interface WatchEventSubscription {
|
|
11
|
+
unsubscribe: () => void;
|
|
12
|
+
}
|
|
13
|
+
declare class Watch {
|
|
14
|
+
private events;
|
|
15
|
+
private enableListMap;
|
|
16
|
+
/**
|
|
17
|
+
* 订阅事件
|
|
18
|
+
* @param event 事件名称
|
|
19
|
+
* @param callback 回调函数
|
|
20
|
+
* @returns 订阅对象,可用于取消订阅
|
|
21
|
+
*/
|
|
22
|
+
subscribe(watchKey: string, event: WatchEventItem): WatchEventSubscription;
|
|
23
|
+
/**
|
|
24
|
+
* 启用事件
|
|
25
|
+
* @param watchKey 监听的key
|
|
26
|
+
* @param event 事件名称
|
|
27
|
+
*/
|
|
28
|
+
enableEvent(watchKey: string, eventKey: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* 禁用某个事件
|
|
31
|
+
* @param watchKey 监听的key
|
|
32
|
+
* @param eventKey 事件名称
|
|
33
|
+
*/
|
|
34
|
+
disableEvent(watchKey: string, eventKey: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* 冻结某个监听下的所有事件
|
|
37
|
+
* @param watchKey 监听的key
|
|
38
|
+
*/
|
|
39
|
+
disabledAllEventByWatchKey(watchKey: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* 启用某个监听下的所有事件
|
|
42
|
+
* @param watchKey 监听的key
|
|
43
|
+
*/
|
|
44
|
+
enableAllEventByWatchKey(watchKey: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 取消订阅事件
|
|
47
|
+
* @param event 事件名称
|
|
48
|
+
* @param callback 回调函数
|
|
49
|
+
* @returns 是否成功取消订阅
|
|
50
|
+
*/
|
|
51
|
+
unsubscribe(watchKey: string, event: WatchEventItem): void;
|
|
52
|
+
/**
|
|
53
|
+
* 发布事件
|
|
54
|
+
* @param event 事件名称
|
|
55
|
+
* @param args 事件参数
|
|
56
|
+
*/
|
|
57
|
+
publish(watchKey: string, ...args: any[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* 根据事件名称发布事件
|
|
60
|
+
* @param watchKey 监听的key
|
|
61
|
+
* @param eventKey 事件名称
|
|
62
|
+
* @param args 事件参数
|
|
63
|
+
*/
|
|
64
|
+
publishByEventKey(watchKey: string, eventKey: string, ...args: any[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* 获取最后一个启用的事件
|
|
67
|
+
* @param watchKey 监听的key
|
|
68
|
+
* @returns 最后一个启用的事件
|
|
69
|
+
*/
|
|
70
|
+
getLastEnableEventKey(watchKey: string): WatchEventItem['key'] | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* 移除某个事件的所有订阅
|
|
73
|
+
* @param event 事件名称
|
|
74
|
+
* @returns 是否成功移除
|
|
75
|
+
*/
|
|
76
|
+
clearEvent(watchKey: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* 移除所有事件订阅
|
|
79
|
+
*/
|
|
80
|
+
clearAllEvents(): void;
|
|
81
|
+
/**
|
|
82
|
+
* 获取事件的订阅数量
|
|
83
|
+
* @param event 事件名称
|
|
84
|
+
* @returns 订阅数量
|
|
85
|
+
*/
|
|
86
|
+
getSubscriberCount(event: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* 检查事件是否有订阅者
|
|
89
|
+
* @param event 事件名称
|
|
90
|
+
* @returns 是否有订阅者
|
|
91
|
+
*/
|
|
92
|
+
hasSubscribers(event: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* 一次性订阅事件,事件触发后自动取消订阅
|
|
95
|
+
* @param event 事件名称
|
|
96
|
+
* @param callback 回调函数
|
|
97
|
+
* @returns 订阅对象,可用于取消订阅
|
|
98
|
+
*/
|
|
99
|
+
once(watchKey: string, event: WatchEventItem): WatchEventSubscription;
|
|
100
|
+
}
|
|
101
|
+
declare const watch: Watch;
|
|
102
|
+
export default watch;
|