mirror of
https://github.com/sern-handler/tools
synced 2026-06-06 01:16:59 +00:00
ioc proto
This commit is contained in:
8
packages/ioc/node_modules/.vitest/deps/_metadata.json
generated
vendored
8
packages/ioc/node_modules/.vitest/deps/_metadata.json
generated
vendored
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"hash": "577958af",
|
||||
"configHash": "94f40ccb",
|
||||
"lockfileHash": "9b10afd2",
|
||||
"browserHash": "79b250d2",
|
||||
"optimized": {},
|
||||
"chunks": {}
|
||||
}
|
||||
3
packages/ioc/node_modules/.vitest/deps/package.json
generated
vendored
3
packages/ioc/node_modules/.vitest/deps/package.json
generated
vendored
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
1
packages/ioc/node_modules/.vitest/results.json
generated
vendored
1
packages/ioc/node_modules/.vitest/results.json
generated
vendored
@@ -1 +0,0 @@
|
||||
{"version":"1.2.2","results":[[":test/index.test.ts",{"duration":15,"failed":true}]]}
|
||||
@@ -21,8 +21,9 @@ export class Container {
|
||||
}
|
||||
private registerHooks(hookname: string, insert: object) {
|
||||
if(hasCallableMethod(insert, hookname)) {
|
||||
console.log(insert)
|
||||
//@ts-ignore
|
||||
this.addHook('init', async () => await insert[hookname]())
|
||||
this.addHook(hookname, () => insert[hookname]())
|
||||
}
|
||||
}
|
||||
addSingleton(key: string, insert: object) {
|
||||
@@ -65,6 +66,7 @@ export class Container {
|
||||
|
||||
async executeHooks(name: string) {
|
||||
const hookFunctions = this.hooks.get(name) || [];
|
||||
console.log(hookFunctions)
|
||||
for (const hookFunction of hookFunctions) {
|
||||
await hookFunction();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
export function hasCallableMethod(obj: object, name: PropertyKey) {
|
||||
//@ts-ignore
|
||||
return Object.hasOwn(obj, name) && typeof obj.init == 'function';
|
||||
return Object.hasOwn(obj, name) && typeof obj[name] == 'function';
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
|
||||
import { CoreContainer } from '../src/container';
|
||||
import { Container } from '../src/container';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
|
||||
describe('CoreContainer Tests', () => {
|
||||
let coreContainer: CoreContainer;
|
||||
let coreContainer: Container;
|
||||
|
||||
beforeEach(() => {
|
||||
coreContainer = new CoreContainer({ autowire: false });
|
||||
coreContainer = new Container({ autowire: false });
|
||||
});
|
||||
|
||||
it('Adding and getting singletons', () => {
|
||||
@@ -76,7 +76,7 @@ describe('CoreContainer Tests', () => {
|
||||
|
||||
it('wired singleton', async () => {
|
||||
let fn = vi.fn()
|
||||
const wiredSingletonFn = (container: CoreContainer) => {
|
||||
const wiredSingletonFn = (container: Container) => {
|
||||
return { value: 'wiredSingletonValue', init: fn };
|
||||
};
|
||||
const added = coreContainer.addWiredSingleton('wiredSingletonKey', wiredSingletonFn);
|
||||
@@ -90,10 +90,9 @@ describe('CoreContainer Tests', () => {
|
||||
})
|
||||
|
||||
it('dispose', async () => {
|
||||
let dfn = vi.fn()
|
||||
const wiredSingletonFn = { value: 'wiredSingletonValue', dispose: vi.fn() };
|
||||
let dfn = vi.fn();
|
||||
const wiredSingletonFn = { value: 'wiredSingletonValue', dispose: dfn };
|
||||
coreContainer.addSingleton('sk', wiredSingletonFn);
|
||||
|
||||
//@ts-ignore
|
||||
await coreContainer.disposeAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user