@eggjs/eventbus-decorator 1.4.1 → 1.5.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/README.md +21 -0
- package/dist/src/EventBus.d.ts +7 -0
- package/dist/src/EventBus.js +3 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -24,6 +24,27 @@ class Foo {
|
|
|
24
24
|
}
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
### cork events
|
|
28
|
+
|
|
29
|
+
Cache events in memory until uncork.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
class Foo {
|
|
33
|
+
@Inject()
|
|
34
|
+
private readonly eventBus: ContextEventBus;
|
|
35
|
+
|
|
36
|
+
bar() {
|
|
37
|
+
this.eventBus.cork();
|
|
38
|
+
// ...do something
|
|
39
|
+
this.eventBus.emit('hello', '01');
|
|
40
|
+
// ...do other things
|
|
41
|
+
|
|
42
|
+
// emit all cached events
|
|
43
|
+
this.eventBus.uncork();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
27
48
|
### handle event
|
|
28
49
|
|
|
29
50
|
```ts
|
package/dist/src/EventBus.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ export type EventName = string | symbol;
|
|
|
5
5
|
* use `emit` to emit a event
|
|
6
6
|
*/
|
|
7
7
|
export interface EventBus extends Pick<TypedEventEmitter<Events>, 'emit'> {
|
|
8
|
+
cork(corkId: string): any;
|
|
9
|
+
uncork(corkId: string): any;
|
|
10
|
+
}
|
|
11
|
+
export declare const CORK_ID: unique symbol;
|
|
12
|
+
export interface ContextEventBus extends EventBus {
|
|
13
|
+
cork(): any;
|
|
14
|
+
uncork(): any;
|
|
8
15
|
}
|
|
9
16
|
export type EventKeys = keyof Events;
|
|
10
17
|
/**
|
package/dist/src/EventBus.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.CORK_ID = void 0;
|
|
4
|
+
exports.CORK_ID = Symbol.for('eventBus#corkId');
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRCdXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvRXZlbnRCdXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBZWEsUUFBQSxPQUFPLEdBQUcsTUFBTSxDQUFDLEdBQUcsQ0FBQyxpQkFBaUIsQ0FBQyxDQUFDIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/eventbus-decorator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "tegg eventbus decorator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"directory": "core/eventbus-decorator"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@eggjs/core-decorator": "^1.4.
|
|
39
|
-
"@eggjs/tegg-common-util": "^1.2.
|
|
38
|
+
"@eggjs/core-decorator": "^1.4.2",
|
|
39
|
+
"@eggjs/tegg-common-util": "^1.2.2",
|
|
40
40
|
"typed-emitter": "^1.3.1"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "de0d2cd055cc6deca938b74aabb90ef5f9fc0dd7"
|
|
52
52
|
}
|