This commit is contained in:
crusader 2017-12-20 22:46:21 +09:00
parent e987227a37
commit fec88d5f8e
10 changed files with 88 additions and 25 deletions

View File

@ -3,11 +3,11 @@ import {
} from '@overflow/commons/core/type'; } from '@overflow/commons/core/type';
export interface Annotation { export interface Annotation {
classDecorator?: <TFunction extends Function>(target: TFunction) => TFunction | void; classDecorator?<TFunction extends Function>(target: TFunction): TFunction | void;
propertyDecorator?: (target: Object, propertyKey: PropertyKeyType) => void; propertyDecorator?(target: Object, propertyKey: PropertyKeyType): void;
methodDecorator?: <T>(target: Object, propertyKey: PropertyKeyType, methodDecorator?<T>(target: Object, propertyKey: PropertyKeyType,
descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void; descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;
parameterDecorator?: (target: Object, propertyKey: PropertyKeyType, parameterIndex: number) => void; parameterDecorator?(target: Object, propertyKey: PropertyKeyType, parameterIndex: number): void;
} }
export abstract class Annotation { export abstract class Annotation {

View File

@ -18,17 +18,17 @@ export class Decorator {
return (...decoratorArgs: any[]) => { return (...decoratorArgs: any[]) => {
let decoratorType: Constants.DecoratorType = Decorator._detectDecoratorType(name, annotation, decoratorArgs); let decoratorType: Constants.DecoratorType = Decorator._detectDecoratorType(name, annotation, decoratorArgs);
// let type = typeof decoratorArgs[0] === 'function' ? decoratorArgs[0].prototype : decoratorArgs[0]; // let type = typeof decoratorArgs[0] === 'function' ? decoratorArgs[0].prototype : decoratorArgs[0];
let clazz = TypeUtil.getClass(decoratorArgs[0]); // let clazz = TypeUtil.getClass(decoratorArgs[0]);
switch(decoratorType) { switch(decoratorType) {
case Constants.DecoratorType.CLASS: case Constants.DecoratorType.CLASS:
return annotation.classDecorator.call(annotation, clazz, decoratorArgs[0]); return annotation.classDecorator.call(annotation, decoratorArgs[0]);
case Constants.DecoratorType.PROPERTY: case Constants.DecoratorType.PROPERTY:
return annotation.propertyDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1]); return annotation.propertyDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1]);
case Constants.DecoratorType.METHOD: case Constants.DecoratorType.METHOD:
return annotation.methodDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]); return annotation.methodDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
case Constants.DecoratorType.PARAMETER: case Constants.DecoratorType.PARAMETER:
return annotation.parameterDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]); return annotation.parameterDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
default: default:
} }
}; };

View File

@ -7,7 +7,7 @@ import {
export interface ReducerAnnotationAttributes { export interface ReducerAnnotationAttributes {
name?: string; name: string;
} }
export class ReducerAnnotation extends Annotation { export class ReducerAnnotation extends Annotation {
@ -24,7 +24,7 @@ export class ReducerAnnotation extends Annotation {
} }
} }
public classDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => { public classDecorator<TFunction extends Function>(target: TFunction): TFunction | void {
console.log('Reducer'); console.log('Reducer');
} }
} }

View File

@ -1,6 +0,0 @@
export function Rest(path: string): Function {
return Use(...['get', path].concat(args));
}

View File

@ -0,0 +1,34 @@
import * as TypeUtil from '@overflow/commons/core/type/util';
import {
Annotation,
Decorator,
} from '@overflow/commons/decorator';
import { PropertyKeyType } from '@overflow/commons/core/type';
export interface RestAPIAnnotationAttributes {
entryPath: string;
}
export class RestAPIAnnotation extends Annotation {
public readonly attributes: RestAPIAnnotationAttributes;
public constructor(entryPath: string | RestAPIAnnotationAttributes) {
super();
if (TypeUtil.isString(entryPath)) {
this.attributes = {
entryPath: <string>entryPath,
};
} else {
this.attributes = <RestAPIAnnotationAttributes>entryPath;
}
}
public methodDecorator<T>(target: Object, propertyKey: PropertyKeyType,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void {
console.log('RestAPI');
}
}
export const RestAPI = Decorator.create(RestAPIAnnotation);
export default RestAPI;

View File

@ -1,6 +0,0 @@
export function RPC(method: string): Function {
return Use(...['get', path].concat(args));
}

View File

@ -0,0 +1,34 @@
import * as TypeUtil from '@overflow/commons/core/type/util';
import {
Annotation,
Decorator,
} from '@overflow/commons/decorator';
import { PropertyKeyType } from '@overflow/commons/core/type';
export interface RpcAPIAnnotationAttributes {
method: string;
}
export class RpcAPIAnnotation extends Annotation {
public readonly attributes: RpcAPIAnnotationAttributes;
public constructor(method: string | RpcAPIAnnotationAttributes) {
super();
if (TypeUtil.isString(method)) {
this.attributes = {
method: <string>method,
};
} else {
this.attributes = <RpcAPIAnnotationAttributes>method;
}
}
public methodDecorator<T>(target: Object, propertyKey: PropertyKeyType,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void {
console.log('RestAPI');
}
}
export const RpcAPI = Decorator.create(RpcAPIAnnotation);
export default RpcAPI;

View File

@ -31,5 +31,12 @@ class LPCReducer {
return null; return null;
} }
/**
* registerReducer
*/
public registerReducer(reducerType: any): void {
console.log(``);
}
} }

View File

@ -51,7 +51,7 @@
"no-inferrable-types": [false], "no-inferrable-types": [false],
"no-internal-module": true, "no-internal-module": true,
"no-require-imports": false, "no-require-imports": false,
"no-string-literal": true, "no-string-literal": false,
"no-switch-case-fall-through": true, "no-switch-case-fall-through": true,
"no-trailing-whitespace": true, "no-trailing-whitespace": true,
"no-unused-expression": true, "no-unused-expression": true,