Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add desc field sent by cocos creator #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function _proxyGetter(
proto: any,
key: string,
resolve: () => any,
doCache: boolean
doCache: boolean,
desc : any
) {
function getter() {
if (doCache && !Reflect.hasMetadata(INJECTION, this, key)) {
Expand All @@ -23,65 +24,67 @@ function _proxyGetter(
Reflect.defineMetadata(INJECTION, newVal, this, key);
}

Object.defineProperty(proto, key, {
Object.assign(desc,{
configurable: true,
enumerable: true,
get: getter,
set: setter
});

Object.defineProperty(proto, key, desc``);
}

function makePropertyInjectDecorator(container: interfaces.Container, doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(proto: any, key: string): void {
return function(proto: any, key: string, desc: any): void {

let resolve = () => {
return container.get(serviceIdentifier);
};

_proxyGetter(proto, key, resolve, doCache);
_proxyGetter(proto, key, resolve, doCache,desc);

};
};
}

function makePropertyInjectNamedDecorator(container: interfaces.Container, doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>, named: string) {
return function(proto: any, key: string): void {
return function(proto: any, key: string,desc:any): void {

let resolve = () => {
return container.getNamed(serviceIdentifier, named);
};

_proxyGetter(proto, key, resolve, doCache);
_proxyGetter(proto, key, resolve, doCache,desc);

};
};
}

function makePropertyInjectTaggedDecorator(container: interfaces.Container, doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string, value: any) {
return function(proto: any, propertyName: string): void {
return function(proto: any, propertyName: string,desc:any): void {

let resolve = () => {
return container.getTagged(serviceIdentifier, key, value);
};

_proxyGetter(proto, propertyName , resolve, doCache);
_proxyGetter(proto, propertyName , resolve, doCache,desc);

};
};
}

function makePropertyMultiInjectDecorator(container: interfaces.Container, doCache: boolean) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(proto: any, key: string): void {
return function(proto: any, key: string, desc:any): void {

let resolve = () => {
return container.getAll(serviceIdentifier);
};

_proxyGetter(proto, key, resolve, doCache);
_proxyGetter(proto, key, resolve, doCache,desc);

};
};
Expand Down