@base-web-kits/base-tools-ts 0.8.15 → 0.8.16
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/base-tools-ts.umd.global.js +10619 -0
- package/dist/base-tools-ts.umd.global.js +10619 -0
- package/dist/bean/EventBus.d.ts +9 -1
- package/dist/bean/EventBus.d.ts.map +1 -1
- package/dist/bean/index.d.ts +1 -1
- package/dist/bean/index.d.ts.map +1 -1
- package/dist/index.cjs +37 -0
- package/dist/index.js +36 -0
- package/package.json +3 -1
package/dist/bean/EventBus.d.ts
CHANGED
|
@@ -3,13 +3,21 @@ type Events = Record<EventType, unknown>;
|
|
|
3
3
|
/**
|
|
4
4
|
* 总线式发布订阅
|
|
5
5
|
* @example
|
|
6
|
-
* const emitter = new EventBus(); // 支持链式调用
|
|
6
|
+
* const emitter = new EventBus<any>(); // 支持链式调用
|
|
7
7
|
* emitter.on('xx', fn); // 订阅事件 xx
|
|
8
8
|
* emitter.once('xx', fn); // 订阅事件 xx 一次
|
|
9
9
|
* emitter.emit('xx', any); // 发布事件 xx,参数任意
|
|
10
10
|
* emitter.off('xx'); // 移除事件 xx 下全部监听
|
|
11
11
|
* emitter.off('xx', fn); // 移除事件 xx 下指定监听
|
|
12
12
|
* emitter.clear(); // 移除所有事件
|
|
13
|
+
*
|
|
14
|
+
* @example 类型约束
|
|
15
|
+
* type T = { a: number; b: string };
|
|
16
|
+
* const emitter = new EventBus<{ xx: T }>();
|
|
17
|
+
* const fn = (arg: T) => {}
|
|
18
|
+
* emitter.on('xx', fn);
|
|
19
|
+
* emitter.off('xx', fn);
|
|
20
|
+
* emitter.emit('xx', { a: 123, b: '123' });
|
|
13
21
|
*/
|
|
14
22
|
export default class EventBus<T extends Events = Events> {
|
|
15
23
|
private readonly _emitter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventBus.d.ts","sourceRoot":"","sources":["../../../src/ts/bean/EventBus.ts"],"names":[],"mappings":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as EventBus } from './EventBus';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/bean/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts/bean/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts/bean/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BigNumber: () => import_bignumber.default,
|
|
34
|
+
EventBus: () => EventBus,
|
|
34
35
|
add: () => add_default,
|
|
35
36
|
after: () => after_default,
|
|
36
37
|
appendUrlParam: () => appendUrlParam,
|
|
@@ -456,6 +457,41 @@ async function toAsync(p) {
|
|
|
456
457
|
}
|
|
457
458
|
}
|
|
458
459
|
|
|
460
|
+
// src/ts/bean/EventBus.ts
|
|
461
|
+
var import_mitt = __toESM(require("mitt"), 1);
|
|
462
|
+
var EventBus = class {
|
|
463
|
+
_emitter = (0, import_mitt.default)();
|
|
464
|
+
/** 订阅 */
|
|
465
|
+
on(type, fn) {
|
|
466
|
+
this._emitter.on(type, fn);
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
/** 订阅一次 */
|
|
470
|
+
once(type, fn) {
|
|
471
|
+
const wrap2 = (event) => {
|
|
472
|
+
this._emitter.off(type, wrap2);
|
|
473
|
+
fn(event);
|
|
474
|
+
};
|
|
475
|
+
this._emitter.on(type, wrap2);
|
|
476
|
+
return this;
|
|
477
|
+
}
|
|
478
|
+
/** 发布 */
|
|
479
|
+
emit(type, event) {
|
|
480
|
+
this._emitter.emit(type, event);
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
/** 移除 */
|
|
484
|
+
off(type, fn) {
|
|
485
|
+
this._emitter.off(type, fn);
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
/** 清空 */
|
|
489
|
+
clear() {
|
|
490
|
+
this._emitter.all.clear();
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
459
495
|
// src/ts/day/index.ts
|
|
460
496
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
461
497
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"), 1);
|
|
@@ -8531,6 +8567,7 @@ function isLongitude(s) {
|
|
|
8531
8567
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8532
8568
|
0 && (module.exports = {
|
|
8533
8569
|
BigNumber,
|
|
8570
|
+
EventBus,
|
|
8534
8571
|
add,
|
|
8535
8572
|
after,
|
|
8536
8573
|
appendUrlParam,
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,41 @@ async function toAsync(p) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// src/ts/bean/EventBus.ts
|
|
20
|
+
import mitt from "mitt";
|
|
21
|
+
var EventBus = class {
|
|
22
|
+
_emitter = mitt();
|
|
23
|
+
/** 订阅 */
|
|
24
|
+
on(type, fn) {
|
|
25
|
+
this._emitter.on(type, fn);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/** 订阅一次 */
|
|
29
|
+
once(type, fn) {
|
|
30
|
+
const wrap2 = (event) => {
|
|
31
|
+
this._emitter.off(type, wrap2);
|
|
32
|
+
fn(event);
|
|
33
|
+
};
|
|
34
|
+
this._emitter.on(type, wrap2);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/** 发布 */
|
|
38
|
+
emit(type, event) {
|
|
39
|
+
this._emitter.emit(type, event);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/** 移除 */
|
|
43
|
+
off(type, fn) {
|
|
44
|
+
this._emitter.off(type, fn);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/** 清空 */
|
|
48
|
+
clear() {
|
|
49
|
+
this._emitter.all.clear();
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
19
54
|
// src/ts/day/index.ts
|
|
20
55
|
import dayjs from "dayjs";
|
|
21
56
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
@@ -8090,6 +8125,7 @@ function isLongitude(s) {
|
|
|
8090
8125
|
}
|
|
8091
8126
|
export {
|
|
8092
8127
|
BigNumber,
|
|
8128
|
+
EventBus,
|
|
8093
8129
|
add_default as add,
|
|
8094
8130
|
after_default as after,
|
|
8095
8131
|
appendUrlParam,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.16",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "Independent TS utilities package built from src/ts.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"index.d.ts",
|
|
29
29
|
"index.js",
|
|
30
30
|
"index.cjs",
|
|
31
|
+
"base-tools-ts.umd.global.js",
|
|
32
|
+
"base-tools-ts.umd.global.js.map",
|
|
31
33
|
"README.md"
|
|
32
34
|
],
|
|
33
35
|
"dependencies": {
|