This commit is contained in:
crusader 2017-12-21 15:58:35 +09:00
parent 888fd0f23d
commit 88a2218e17
8 changed files with 71 additions and 78 deletions

View File

@ -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'),

View File

@ -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',

View File

@ -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: {

View File

@ -7,3 +7,17 @@ export interface Type<T> extends Function {
}
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',
}

View File

@ -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;
}
/**

View File

@ -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',
}

View File

@ -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;
}
}

View File

@ -14,7 +14,7 @@ class WebApp extends React.Component<Props, State> {
public render(): JSX.Element {
return (
<b>Hello....</b>
<b>Hello...</b>
);
}
}