diff --git a/config/webpack/webpack.config.base.js b/config/webpack/webpack.config.base.js index 9e0db5e..9095e2b 100644 --- a/config/webpack/webpack.config.base.js +++ b/config/webpack/webpack.config.base.js @@ -1,15 +1,8 @@ const Path = require('path'); const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin; -const packages = require('../../package.json'); module.exports = { target: 'web', - entry: { - webapp: [ - Path.resolve(__dirname, '../../src/ts/@overflow/webapp/index.tsx') - ], - vendor: Object.keys(packages.dependencies) - }, output: { path: Path.resolve(__dirname, '../../dist'), diff --git a/config/webpack/webpack.config.dev.js b/config/webpack/webpack.config.dev.js index 302b9e5..fd7aab6 100644 --- a/config/webpack/webpack.config.dev.js +++ b/config/webpack/webpack.config.dev.js @@ -4,13 +4,16 @@ const WebpackMerge = require('webpack-merge'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const WebpackDashboardPlugin = require('webpack-dashboard/plugin'); const configBase = require('./webpack.config.base.js'); - +const packages = require('../../package.json'); + module.exports = WebpackMerge(configBase, { - // entry: { - // webapp: [ - // 'react-hot-loader/patch' - // ] - // }, + entry: { + webapp: [ + 'react-hot-loader/patch', + Path.resolve(__dirname, '../../src/ts/@overflow/webapp/index.tsx') + ], + vendor: Object.keys(packages.dependencies) + }, devtool: 'inline-source-map', @@ -29,7 +32,7 @@ module.exports = WebpackMerge(configBase, { ignored: /node_modules/, }, }, - + module: { loaders: [ // source-map diff --git a/config/webpack/webpack.config.prod.js b/config/webpack/webpack.config.prod.js index 853f0c0..cc6f853 100644 --- a/config/webpack/webpack.config.prod.js +++ b/config/webpack/webpack.config.prod.js @@ -2,9 +2,17 @@ const Path = require('path'); const Webpack = require('webpack'); const WebpackMerge = require('webpack-merge'); const configBase = require('./webpack.config.base.js'); - +const packages = require('../../package.json'); + module.exports = WebpackMerge(configBase, { + entry: { + webapp: [ + Path.resolve(__dirname, '../../src/ts/@overflow/webapp/index.tsx') + ], + vendor: Object.keys(packages.dependencies) + }, + devtool: 'source-map', module: { diff --git a/src/ts/@overflow/commons/core/type/type.ts b/src/ts/@overflow/commons/core/type/type.ts index 889f490..1dd8c5f 100644 --- a/src/ts/@overflow/commons/core/type/type.ts +++ b/src/ts/@overflow/commons/core/type/type.ts @@ -3,7 +3,21 @@ export type PropertyKeyType = IdentityType; export const Type = Function; export interface Type extends Function { - new (...args: any[]): T; + new (...args: any[]): T; } export type DecoratorParametersType = [any, string | symbol, number | PropertyDescriptor]; + +export enum PrimitiveType { + ANY = 'any', + STRING = 'string', + NUMBER = 'number', + BOOLEAN = 'boolean', +} + +export enum DecoratorType { + CLASS = 'class', + PROPERTY = 'property', + METHOD = 'method', + PARAMETER = 'parameter', +} diff --git a/src/ts/@overflow/commons/core/type/util.ts b/src/ts/@overflow/commons/core/type/util.ts index e05d287..c000388 100644 --- a/src/ts/@overflow/commons/core/type/util.ts +++ b/src/ts/@overflow/commons/core/type/util.ts @@ -1,5 +1,7 @@ import { + DecoratorType, DecoratorParametersType, + PrimitiveType, PropertyKeyType, } from './type'; @@ -44,19 +46,19 @@ export function isPrimitiveOrPrimitiveClass(target: any): boolean { /** * * @param target - * @returns {'string' | 'number' | 'boolean' | 'any'} + * @returns {PrimitiveType} */ -export function primitiveOf(target: any): 'string' | 'number' | 'boolean' | 'any' { +export function primitiveOf(target: any): PrimitiveType { if (isString(target)) { - return 'string'; + return PrimitiveType.STRING; } if (isNumber(target)) { - return 'number'; + return PrimitiveType.NUMBER; } if (isBoolean(target)) { - return 'boolean'; + return PrimitiveType.BOOLEAN; } - return 'any'; + return PrimitiveType.ANY; } /** @@ -293,19 +295,19 @@ export function getInheritedClass(target: any): any { /** * * @param {any[]} args - * @returns {'parameter' | 'property' | 'method' | 'class'} + * @returns {DecoratorType} */ -export function getDecoratorType(args: any[]): 'parameter' | 'property' | 'method' | 'class' { +export function getDecoratorType(args: any[]): DecoratorType { const [, propertyKey, descriptor] = args; if (typeof descriptor === 'number') { - return 'parameter'; + return DecoratorType.PARAMETER; } if (propertyKey && descriptor === undefined || descriptor && (descriptor.get || descriptor.set)) { - return 'property'; + return DecoratorType.PROPERTY; } - return (descriptor && descriptor.value) ? 'method' : 'class'; + return (descriptor && descriptor.value) ? DecoratorType.METHOD : DecoratorType.CLASS; } /** diff --git a/src/ts/@overflow/commons/decorator/constants.ts b/src/ts/@overflow/commons/decorator/constants.ts index b05925a..f063c4b 100644 --- a/src/ts/@overflow/commons/decorator/constants.ts +++ b/src/ts/@overflow/commons/decorator/constants.ts @@ -2,10 +2,3 @@ export const ANNOTATION_HANDLER_CLASS: string = 'classDecorator'; export const ANNOTATION_HANDLER_PROPERTY: string = 'propertyDecorator'; export const ANNOTATION_HANDLER_METHOD: string = 'methodDecorator'; export const ANNOTATION_HANDLER_PARAMETER: string = 'parameterDecorator'; - -export enum DecoratorType { - CLASS = 'Class', - PROPERTY = 'Property', - METHOD = 'Method', - PARAMETER = 'Parameter', -} diff --git a/src/ts/@overflow/commons/decorator/decorator.ts b/src/ts/@overflow/commons/decorator/decorator.ts index 2dd4261..e062245 100644 --- a/src/ts/@overflow/commons/decorator/decorator.ts +++ b/src/ts/@overflow/commons/decorator/decorator.ts @@ -1,4 +1,5 @@ import { + DecoratorType, Type, } from '@overflow/commons/core/type'; @@ -17,18 +18,35 @@ export class Decorator { let name: string = AnnotationClass.name; return (...decoratorArgs: any[]) => { - let decoratorType: Constants.DecoratorType = Decorator._detectDecoratorType(name, annotation, decoratorArgs); + let decoratorType: DecoratorType = TypeUtil.getDecoratorType(decoratorArgs); + // let type = typeof decoratorArgs[0] === 'function' ? decoratorArgs[0].prototype : decoratorArgs[0]; // let clazz = TypeUtil.getClass(decoratorArgs[0]); switch(decoratorType) { - case Constants.DecoratorType.CLASS: + case DecoratorType.CLASS: + if (typeof(annotation.classDecorator) === 'undefined') { + throw new Error(`Cannot apply @${name} decorator on Class.`); + } + return annotation.classDecorator.call(annotation, decoratorArgs[0]); - case Constants.DecoratorType.PROPERTY: + case DecoratorType.PROPERTY: + if (typeof(annotation.propertyDecorator) === 'undefined') { + throw new Error(`Cannot apply @${name} decorator on Property.`); + } + return annotation.propertyDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1]); - case Constants.DecoratorType.METHOD: + case DecoratorType.METHOD: + if (typeof(annotation.methodDecorator) === 'undefined') { + throw new Error(`Cannot apply @${name} decorator on Method.`); + } + return annotation.methodDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]); - case Constants.DecoratorType.PARAMETER: + case DecoratorType.PARAMETER: + if (typeof(annotation.parameterDecorator) === 'undefined') { + throw new Error(`Cannot apply @${name} decorator on Parameter.`); + } + return annotation.parameterDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]); default: } @@ -36,42 +54,4 @@ export class Decorator { }; } - private static _detectDecoratorType(name: string, annotation: any, args: any[]): Constants.DecoratorType { - let params = []; - for (let i = 0; i < args.length; i++) { - if (args[i]) { - params.push(args[i]); - } - } - const paramCount = params.length; - let decoratorType: Constants.DecoratorType; - - if (1 === paramCount) { - if (typeof(annotation.classDecorator) === 'undefined') { - throw new Error(`Cannot apply @${name} decorator on Class.`); - } - decoratorType = Constants.DecoratorType.CLASS; - } else if (2 === paramCount) { - if (typeof(annotation.propertyDecorator) === 'undefined') { - throw new Error(`Cannot apply @${name} decorator on Property.`); - } - decoratorType = Constants.DecoratorType.PROPERTY; - } else if (3 === paramCount) { - if(typeof args[2] === 'number') { - if (typeof(annotation.parameterDecorator) === 'undefined') { - throw new Error(`Cannot apply @${name} decorator on Parameter.`); - } - decoratorType = Constants.DecoratorType.PARAMETER; - } else { - if (typeof(annotation.methodDecorator) === 'undefined') { - throw new Error(`Cannot apply @${name} decorator on Method.`); - } - decoratorType = Constants.DecoratorType.METHOD; - } - } else { - throw new Error(`@${name} decorator is not valid here!`); - } - - return decoratorType; - } } diff --git a/src/ts/@overflow/webapp/pages/webapp.tsx b/src/ts/@overflow/webapp/pages/webapp.tsx index 4bbea26..b43b9bc 100644 --- a/src/ts/@overflow/webapp/pages/webapp.tsx +++ b/src/ts/@overflow/webapp/pages/webapp.tsx @@ -14,7 +14,7 @@ class WebApp extends React.Component { public render(): JSX.Element { return ( - Hello.... + Hello... ); } }