ts-ioc-container 32.5.0 → 32.6.0
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 +2 -2
- package/typings/hooks/hook.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1195,7 +1195,6 @@ import {
|
|
|
1195
1195
|
by,
|
|
1196
1196
|
Container,
|
|
1197
1197
|
key,
|
|
1198
|
-
getHooks,
|
|
1199
1198
|
hook,
|
|
1200
1199
|
inject,
|
|
1201
1200
|
provider,
|
|
@@ -1217,6 +1216,10 @@ class LogsRepo {
|
|
|
1217
1216
|
|
|
1218
1217
|
@register(key('logger'))
|
|
1219
1218
|
class Logger {
|
|
1219
|
+
@hook('onDispose', ({ instance, methodName }) => {
|
|
1220
|
+
// @ts-ignore
|
|
1221
|
+
instance[methodName].push('world');
|
|
1222
|
+
}) // <--- or extract it to @onDispose
|
|
1220
1223
|
private messages: string[] = [];
|
|
1221
1224
|
|
|
1222
1225
|
constructor(@inject(by.key('logsRepo')) private logsRepo: LogsRepo) {}
|
|
@@ -1225,10 +1228,13 @@ class Logger {
|
|
|
1225
1228
|
this.messages.push(message);
|
|
1226
1229
|
}
|
|
1227
1230
|
|
|
1231
|
+
size(): number {
|
|
1232
|
+
return this.messages.length;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1228
1235
|
@hook('onDispose', (c) => c.invokeMethod({ args: [] })) // <--- or extract it to @onDispose
|
|
1229
1236
|
async save(): Promise<void> {
|
|
1230
1237
|
this.logsRepo.saveLogs(this.messages);
|
|
1231
|
-
this.messages = [];
|
|
1232
1238
|
}
|
|
1233
1239
|
}
|
|
1234
1240
|
|
|
@@ -1243,7 +1249,7 @@ describe('onDispose', function () {
|
|
|
1243
1249
|
executeHooks(instance as object, 'onDispose', { scope: container });
|
|
1244
1250
|
}
|
|
1245
1251
|
|
|
1246
|
-
expect(container.resolve<LogsRepo>('logsRepo').savedLogs).
|
|
1252
|
+
expect(container.resolve<LogsRepo>('logsRepo').savedLogs.join(',')).toBe('Hello,world');
|
|
1247
1253
|
});
|
|
1248
1254
|
});
|
|
1249
1255
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "32.
|
|
3
|
+
"version": "32.6.0",
|
|
4
4
|
"description": "Typescript IoC container",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"ts-node": "^10.9.1",
|
|
60
60
|
"typescript": "5.4.3"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "991c10cb1fc85ecb8ac3b918ffcdd6bae3f100d4"
|
|
63
63
|
}
|
package/typings/hooks/hook.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IContainer } from '../container/IContainer';
|
|
2
2
|
import { ExecutionContext } from './ExecutionContext';
|
|
3
3
|
export type Execution = <T extends ExecutionContext>(context: T) => void;
|
|
4
|
-
export declare const hook: (key: string | symbol, ...fns: Execution[]) =>
|
|
4
|
+
export declare const hook: (key: string | symbol, ...fns: Execution[]) => (target: object, propertyKey: string | symbol) => void;
|
|
5
5
|
export declare function getHooks(target: object, key: string | symbol): Map<string, Execution[]>;
|
|
6
6
|
export declare function hasHooks(target: object, key: string | symbol): boolean;
|
|
7
7
|
export declare const executeHooks: <Context extends ExecutionContext>(target: object, key: string | symbol, { scope, createContext, }: {
|