@base-web-kits/base-tools-ts 1.1.10 → 1.1.18-alpha.1
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/base-tools-ts.umd.global.js +1 -0
- package/dist/base-tools-ts.umd.global.js.map +1 -1
- package/dist/bean/EventBus.d.ts +13 -11
- package/dist/bean/EventBus.d.ts.map +1 -1
- package/dist/es-toolkit/index.d.ts +1 -2
- package/dist/es-toolkit/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +39 -36
- package/src/ts/bean/EventBus.ts +13 -10
- package/src/ts/es-toolkit/index.ts +1 -2
package/package.json
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"sideEffects": false,
|
|
5
|
-
"description": "Independent TS utilities package built from src/ts.",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"base-tools",
|
|
8
|
-
"ts",
|
|
9
|
-
"utilities"
|
|
10
|
-
],
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"main": "./dist/index.cjs",
|
|
13
|
-
"module": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"import": "./dist/index.js",
|
|
19
|
-
"require": "./dist/index.cjs"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist",
|
|
24
|
-
"README.md",
|
|
25
|
-
"src"
|
|
26
|
-
],
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"es-toolkit": "^1.42.0",
|
|
29
|
-
"bignumber.js": "^9.1.2",
|
|
30
|
-
"dayjs": "^1.11.19",
|
|
31
|
-
"mitt": "^3.0.1"
|
|
32
|
-
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
}
|
|
36
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
+
"version": "1.1.18-alpha.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"description": "Independent TS utilities package built from src/ts.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"base-tools",
|
|
8
|
+
"ts",
|
|
9
|
+
"utilities"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"src"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"es-toolkit": "^1.42.0",
|
|
29
|
+
"bignumber.js": "^9.1.2",
|
|
30
|
+
"dayjs": "^1.11.19",
|
|
31
|
+
"mitt": "^3.0.1"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"dayjs": "^1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"registry": "https://registry.npmjs.org"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/ts/bean/EventBus.ts
CHANGED
|
@@ -4,16 +4,7 @@ type Events = Record<EventType, unknown>;
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 总线式发布订阅
|
|
7
|
-
* @example
|
|
8
|
-
* const emitter = new EventBus(); // 支持链式调用
|
|
9
|
-
* emitter.on('xx', fn); // 订阅事件 xx
|
|
10
|
-
* emitter.once('xx', fn); // 订阅事件 xx 一次
|
|
11
|
-
* emitter.emit('xx', any); // 发布事件 xx,参数任意
|
|
12
|
-
* emitter.off('xx'); // 移除事件 xx 下全部监听
|
|
13
|
-
* emitter.off('xx', fn); // 移除事件 xx 下指定监听
|
|
14
|
-
* emitter.clear(); // 移除所有事件
|
|
15
|
-
*
|
|
16
|
-
* @example 类型约束
|
|
7
|
+
* @example 创建实例调用 (支持类型约束)
|
|
17
8
|
* type T = { a: number; b: string };
|
|
18
9
|
* const emitter = new EventBus<{ xx: T; yy: void }>();
|
|
19
10
|
* const fn = (arg: T) => {}
|
|
@@ -59,3 +50,15 @@ export class EventBus<T extends Events = Events> {
|
|
|
59
50
|
return this;
|
|
60
51
|
}
|
|
61
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 全局事件总线
|
|
56
|
+
* @example 静态调用 (支持链式)
|
|
57
|
+
* EventBus.on('xx', fn); // 订阅事件 xx
|
|
58
|
+
* EventBus.once('xx', fn); // 订阅事件 xx 一次
|
|
59
|
+
* EventBus.emit('xx', any); // 发布事件 xx,参数任意
|
|
60
|
+
* EventBus.off('xx'); // 移除事件 xx 下全部监听
|
|
61
|
+
* EventBus.off('xx', fn); // 移除事件 xx 下指定监听
|
|
62
|
+
* EventBus.clear(); // 移除所有事件
|
|
63
|
+
*/
|
|
64
|
+
export default new EventBus();
|