diff --git a/package.json b/package.json index d532a3c..593a9c6 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test": "yarn run jest", "test:watch": "yarn run jest -- --watch", "jest": "PWD=$(pwd) NODE_ENV=test ./node_modules/.bin/jest -w 1 --coverage", + "build:dev": "set NODE_ENV=production && ./node_modules/.bin/webpack-dashboard -m -- ./node_modules/.bin/webpack --progress --profile --colors --config ./config/webpack/webpack.config.dev.js", "build": "set NODE_ENV=production && ./node_modules/.bin/webpack-dashboard -m -- ./node_modules/.bin/webpack --progress --profile --colors --config ./config/webpack/webpack.config.prod.js", "lint": "./node_modules/.bin/tslint -c tslint.json 'src/ts/**/*.{ts,tsx}' && ./node_modules/.bin/sass-lint 'src/**/*.scss'", "stats": "set NODE_ENV=production && webpack --progress --config ./config/webpack/webpack.config.stats.js --profile --json > ./config/webpack/stats/stats.json" diff --git a/src/ts/@overflow/commons/core/reflect/class.ts b/src/ts/@overflow/commons/core/reflect/class.ts index 1ab6c39..cccc2e4 100644 --- a/src/ts/@overflow/commons/core/reflect/class.ts +++ b/src/ts/@overflow/commons/core/reflect/class.ts @@ -11,6 +11,7 @@ import {Method} from './method'; export class Class extends AccessibleObject { private _clazzType: ClassType; + private _constructor: Constructor; private _fields: Map; private _methods: Map; @@ -31,6 +32,13 @@ export class Class extends AccessibleObject { Metadata.set(LOAFER_CLASS, clazz, clazzType); } + if (null === clazz._constructor) { + let parameterTypes = Metadata.getOwnParamTypes(clazzType); + if (undefined !== parameterTypes) { + clazz._constructor = new Constructor(clazz, parameterTypes); + } + } + return clazz; } @@ -39,6 +47,19 @@ export class Class extends AccessibleObject { this._clazzType = clazzType; this._fields = new Map(); this._methods = new Map(); + this._constructor = null; + } + + /** + * _defineField + */ + public _defineConstructor(parameterTypes: any[]): Constructor { + let cons: Constructor = this._constructor; + if (undefined === cons) { + cons = new Constructor(this, parameterTypes); + this._constructor = cons; + } + return cons; } /** @@ -65,6 +86,9 @@ export class Class extends AccessibleObject { return method; } + public getConstructor(): Constructor { + return this._constructor; + } public getOwnField(propertyKey: PropertyKeyType): Field { return this._fields.get(propertyKey); diff --git a/src/ts/@overflow/commons/core/type/metadata.ts b/src/ts/@overflow/commons/core/type/metadata.ts index ba5540b..0fc4446 100644 --- a/src/ts/@overflow/commons/core/type/metadata.ts +++ b/src/ts/@overflow/commons/core/type/metadata.ts @@ -458,7 +458,7 @@ export class Metadata { * */ public static getParamTypes(target: any, propertyKey?: PropertyKeyType): any[] { - return Reflect.getMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || []; + return Reflect.getMetadata(DESIGN_PARAM_TYPES, target, propertyKey!); } /** @@ -490,7 +490,7 @@ export class Metadata { * */ public static getOwnParamTypes(target: any, propertyKey?: PropertyKeyType): any[] { - return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || []; + return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!); } } diff --git a/src/ts/@overflow/commons/decorator/decorator.ts b/src/ts/@overflow/commons/decorator/decorator.ts index 835ef68..96daf7b 100644 --- a/src/ts/@overflow/commons/decorator/decorator.ts +++ b/src/ts/@overflow/commons/decorator/decorator.ts @@ -34,12 +34,14 @@ export class Decorator { let field: Field = null; let method: Method = null; let parameter: Parameter = null; + let cons: Constructor = null; switch(decoratorType) { case DecoratorType.CLASS: if (typeof(annotation.classDecorator) === 'undefined') { throw new Error(`Cannot apply @${name} decorator on Class.`); } + cons = clazz._defineConstructor(Metadata.getOwnParamTypes(target)); clazz._addAnnotation(annotation); @@ -57,7 +59,6 @@ export class Decorator { if (typeof(annotation.methodDecorator) === 'undefined') { throw new Error(`Cannot apply @${name} decorator on Method.`); } - method = clazz._defineMethod(propertyKey, Metadata.getOwnParamTypes(target, propertyKey), Metadata.getOwnReturnType(target, propertyKey)); @@ -69,10 +70,15 @@ export class Decorator { throw new Error(`Cannot apply @${name} decorator on Parameter.`); } - method = clazz._defineMethod(propertyKey, - Metadata.getOwnParamTypes(target, propertyKey), - Metadata.getOwnReturnType(target, propertyKey)); - parameter = method.getParameter(descriptorOrParameterIndex); + if (undefined === propertyKey) { + cons = clazz.getConstructor(); + parameter = cons.getParameter(descriptorOrParameterIndex); + } else { + method = clazz._defineMethod(propertyKey, + Metadata.getOwnParamTypes(target, propertyKey), + Metadata.getOwnReturnType(target, propertyKey)); + parameter = method.getParameter(descriptorOrParameterIndex); + } parameter._addAnnotation(annotation); return annotation.parameterDecorator.call(annotation, target, propertyKey, descriptorOrParameterIndex); diff --git a/src/ts/@overflow/modules/member/reducer/member_reducer.ts b/src/ts/@overflow/modules/member/reducer/member_reducer.ts index 6a684ab..20c0c25 100644 --- a/src/ts/@overflow/modules/member/reducer/member_reducer.ts +++ b/src/ts/@overflow/modules/member/reducer/member_reducer.ts @@ -9,7 +9,7 @@ import { @ActionMapping('@overflow/modules/member/MemberReducer') export default class MemberReducer { private name: string; - public constructor(@Parameter() name: string) { + public constructor(count: number, @Parameter() name: string) { this.name = name; }