@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 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
@@ -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
  /**
@@ -1,3 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRCdXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvRXZlbnRCdXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
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.4.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.1",
39
- "@eggjs/tegg-common-util": "^1.2.1",
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": "d5e18b9e9af115d0fe02e3b3190e364244b698ac"
51
+ "gitHead": "de0d2cd055cc6deca938b74aabb90ef5f9fc0dd7"
52
52
  }