Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

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