@eggjs/tegg-aop-plugin 4.0.0-beta.2 → 4.0.0-beta.4
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 +9 -3
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -14,11 +14,15 @@ export.aopModule = {
|
|
|
14
14
|
|
|
15
15
|
使用 `@Advice` 注解来申明一个实现,可以用来监听、拦截方法执行。
|
|
16
16
|
|
|
17
|
-
**注意:Advice 也是一种 Prototype,可以通过 initType
|
|
17
|
+
**注意:Advice 也是一种 Prototype,可以通过 initType 来指定不同的生命周期,默认为 Singleton。**
|
|
18
|
+
|
|
19
|
+
如需在调用过程中保存状态,可以将状态通过 `AdviceContext` 的 get/set 来保存。
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
import { Advice, IAdvice } from '@eggjs/tegg/aop';
|
|
21
23
|
|
|
24
|
+
const FOO_STATE_SYMBOL = Symbol('AdviceExample#state');
|
|
25
|
+
|
|
22
26
|
@Advice()
|
|
23
27
|
export class AdviceExample implements IAdvice {
|
|
24
28
|
// Advice 中可以正常的注入其他的对象
|
|
@@ -28,11 +32,13 @@ export class AdviceExample implements IAdvice {
|
|
|
28
32
|
// 在函数执行前执行
|
|
29
33
|
async beforeCall(ctx: AdviceContext): Promise<void> {
|
|
30
34
|
// ...
|
|
35
|
+
ctx.set(FOO_STATE_SYMBOL, 23333);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
// 在函数成功后执行
|
|
34
39
|
async afterReturn(ctx: AdviceContext, result: any): Promise<void> {
|
|
35
|
-
//
|
|
40
|
+
// 将会打印 23333
|
|
41
|
+
console.log(ctx.get(FOO_STATE_SYMBOL));
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
// 在函数成功后执行
|
|
@@ -113,7 +119,7 @@ export class CrosscutNameAdviceExample implements IAdvice {
|
|
|
113
119
|
}
|
|
114
120
|
})
|
|
115
121
|
@Advice()
|
|
116
|
-
|
|
122
|
+
export class CrosscutCustomAdviceExample implements IAdvice {
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-aop-plugin",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.4",
|
|
4
4
|
"eggPlugin": {
|
|
5
5
|
"name": "aopModule",
|
|
6
6
|
"dependencies": [
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
"node": ">=20.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@eggjs/aop-decorator": "^4.0.0-beta.
|
|
52
|
-
"@eggjs/egg-module-common": "^4.0.0-beta.
|
|
53
|
-
"@eggjs/tegg": "^4.0.0-beta.
|
|
54
|
-
"@eggjs/tegg-aop-runtime": "^4.0.0-beta.
|
|
55
|
-
"@eggjs/tegg-metadata": "^4.0.0-beta.
|
|
51
|
+
"@eggjs/aop-decorator": "^4.0.0-beta.4",
|
|
52
|
+
"@eggjs/egg-module-common": "^4.0.0-beta.4",
|
|
53
|
+
"@eggjs/tegg": "^4.0.0-beta.4",
|
|
54
|
+
"@eggjs/tegg-aop-runtime": "^4.0.0-beta.4",
|
|
55
|
+
"@eggjs/tegg-metadata": "^4.0.0-beta.4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@eggjs/bin": "7",
|
|
59
59
|
"@eggjs/mock": "6",
|
|
60
|
-
"@eggjs/tegg-config": "^4.0.0-beta.
|
|
61
|
-
"@eggjs/tegg-plugin": "^4.0.0-beta.
|
|
60
|
+
"@eggjs/tegg-config": "^4.0.0-beta.4",
|
|
61
|
+
"@eggjs/tegg-plugin": "^4.0.0-beta.4",
|
|
62
62
|
"@types/mocha": "10",
|
|
63
63
|
"@types/node": "20",
|
|
64
64
|
"egg": "4",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9ba90bed3ab9f641ceaa6a7db560095817b7e52c"
|
|
72
72
|
}
|