Skip to content

Commit

Permalink
feat: remove context egg object factory (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu authored Feb 9, 2023
1 parent ec7bc2c commit e14bdb2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 56 deletions.
3 changes: 1 addition & 2 deletions core/dynamic-inject-runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './src/impl/EggContextObjectFactory';
export * from './src/impl/EggSingletonObjectFactory';
export * from './src/EggObjectFactory';

import './src/EggObjectFactoryPrototype';
import './src/EggObjectFactoryObject';
10 changes: 0 additions & 10 deletions core/dynamic-inject-runtime/src/AbstractEggObjectFactory.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { EggContainerFactory } from '@eggjs/tegg-runtime';
import { EggAbstractClazz, QualifierImplUtil } from '@eggjs/tegg-dynamic-inject';
import { EggAbstractClazz, EggObjectFactory as IEggObjectFactory, QualifierImplUtil } from '@eggjs/tegg-dynamic-inject';
import { AccessLevel, PrototypeUtil, QualifierValue, SingletonProto } from '@eggjs/core-decorator';
import { AbstractEggObjectFactory } from '../AbstractEggObjectFactory';
import { EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE } from '../EggObjectFactoryPrototype';
import { EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE } from './EggObjectFactoryPrototype';

@SingletonProto({
protoImplType: EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE,
name: 'eggObjectFactory',
accessLevel: AccessLevel.PUBLIC,
})
export class EggSingletonObjectFactory extends AbstractEggObjectFactory {
export class EggObjectFactory implements IEggObjectFactory {
eggContainerFactory: typeof EggContainerFactory;

async getEggObject<T extends object>(abstractClazz: EggAbstractClazz<T>, qualifierValue: QualifierValue) {
Expand Down
15 changes: 6 additions & 9 deletions core/dynamic-inject-runtime/src/EggObjectFactoryObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import {
EggContainerFactory,
EggContext,
EggObject,
EggObjectLifeCycleContext,
EggObjectFactory as TEggObjectFactory,
} from '@eggjs/tegg-runtime';
import { EggObjectFactoryPrototype } from './EggObjectFactoryPrototype';
import { EggObjectName } from '@eggjs/core-decorator';
import { IdenticalUtil } from '@eggjs/tegg-lifecycle';
import { EggPrototype } from '@eggjs/tegg-metadata';
import { AbstractEggObjectFactory } from './AbstractEggObjectFactory';
import { EggObjectFactory } from './EggObjectFactory';

const OBJ = Symbol('EggObjectFactoryObject#obj');

Expand All @@ -18,26 +17,24 @@ export class EggObjectFactoryObject implements EggObject {
readonly name: EggObjectName;
readonly ctx?: EggContext;
readonly id: string;
private [OBJ]: AbstractEggObjectFactory;
private [OBJ]: EggObjectFactory;

constructor(name: EggObjectName, proto: EggObjectFactoryPrototype, ctx?: EggContext) {
constructor(name: EggObjectName, proto: EggObjectFactoryPrototype) {
this.proto = proto;
this.name = name;
this.ctx = ctx;
this.id = IdenticalUtil.createObjectId(this.proto.id, this.ctx?.id);
}

get obj() {
if (!this[OBJ]) {
this[OBJ] = this.proto.constructEggObject() as AbstractEggObjectFactory;
this[OBJ] = this.proto.constructEggObject() as EggObjectFactory;
this[OBJ].eggContainerFactory = EggContainerFactory;
this[OBJ].eggContext = this.ctx;
}
return this[OBJ];
}

static async createObject(name: EggObjectName, proto: EggPrototype, _: EggObjectLifeCycleContext, ctx?: EggContext): Promise<EggObjectFactoryObject> {
return new EggObjectFactoryObject(name, proto as EggObjectFactoryPrototype, ctx);
static async createObject(name: EggObjectName, proto: EggPrototype): Promise<EggObjectFactoryObject> {
return new EggObjectFactoryObject(name, proto as EggObjectFactoryPrototype);
}

readonly isReady: true;
Expand Down
28 changes: 0 additions & 28 deletions core/dynamic-inject-runtime/src/impl/EggContextObjectFactory.ts

This file was deleted.

5 changes: 2 additions & 3 deletions plugin/tegg/lib/EggAppLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { ObjectUtils } from '@eggjs/tegg-common-util';
import { COMPATIBLE_PROTO_IMPLE_TYPE } from './EggCompatibleProtoImpl';
import { BackgroundTaskHelper } from '@eggjs/tegg-background-task';
import { EggContextObjectFactory, EggSingletonObjectFactory } from '@eggjs/tegg-dynamic-inject-runtime';
import { EggObjectFactory } from '@eggjs/tegg-dynamic-inject-runtime';

const APP_CLAZZ_BLACK_LIST = [ 'eggObjectFactory' ];
const DEFAULT_APP_CLAZZ = [];
Expand Down Expand Up @@ -142,8 +142,7 @@ export class EggAppLoader implements Loader {
// inner helper class list
// TODO: should auto the inner class
BackgroundTaskHelper,
EggContextObjectFactory,
EggSingletonObjectFactory,
EggObjectFactory,
];
}
}

0 comments on commit e14bdb2

Please sign in to comment.