ing
This commit is contained in:
parent
888fd0f23d
commit
88a2218e17
|
@ -1,15 +1,8 @@
|
||||||
const Path = require('path');
|
const Path = require('path');
|
||||||
const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
|
const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
|
||||||
const packages = require('../../package.json');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
target: 'web',
|
target: 'web',
|
||||||
entry: {
|
|
||||||
webapp: [
|
|
||||||
Path.resolve(__dirname, '../../src/ts/@overflow/webapp/index.tsx')
|
|
||||||
],
|
|
||||||
vendor: Object.keys(packages.dependencies)
|
|
||||||
},
|
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
path: Path.resolve(__dirname, '../../dist'),
|
path: Path.resolve(__dirname, '../../dist'),
|
||||||
|
|
|
@ -4,13 +4,16 @@ const WebpackMerge = require('webpack-merge');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const WebpackDashboardPlugin = require('webpack-dashboard/plugin');
|
const WebpackDashboardPlugin = require('webpack-dashboard/plugin');
|
||||||
const configBase = require('./webpack.config.base.js');
|
const configBase = require('./webpack.config.base.js');
|
||||||
|
const packages = require('../../package.json');
|
||||||
|
|
||||||
module.exports = WebpackMerge(configBase, {
|
module.exports = WebpackMerge(configBase, {
|
||||||
// entry: {
|
entry: {
|
||||||
// webapp: [
|
webapp: [
|
||||||
// 'react-hot-loader/patch'
|
'react-hot-loader/patch',
|
||||||
// ]
|
Path.resolve(__dirname, '../../src/ts/@overflow/webapp/index.tsx')
|
||||||
// },
|
],
|
||||||
|
vendor: Object.keys(packages.dependencies)
|
||||||
|
},
|
||||||
|
|
||||||
devtool: 'inline-source-map',
|
devtool: 'inline-source-map',
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,17 @@ const Path = require('path');
|
||||||
const Webpack = require('webpack');
|
const Webpack = require('webpack');
|
||||||
const WebpackMerge = require('webpack-merge');
|
const WebpackMerge = require('webpack-merge');
|
||||||
const configBase = require('./webpack.config.base.js');
|
const configBase = require('./webpack.config.base.js');
|
||||||
|
const packages = require('../../package.json');
|
||||||
|
|
||||||
|
|
||||||
module.exports = WebpackMerge(configBase, {
|
module.exports = WebpackMerge(configBase, {
|
||||||
|
entry: {
|
||||||
|
webapp: [
|
||||||
|
Path.resolve(__dirname, '../../src/ts/@overflow/webapp/index.tsx')
|
||||||
|
],
|
||||||
|
vendor: Object.keys(packages.dependencies)
|
||||||
|
},
|
||||||
|
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
|
|
||||||
module: {
|
module: {
|
||||||
|
|
|
@ -7,3 +7,17 @@ export interface Type<T> extends Function {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DecoratorParametersType = [any, string | symbol, number | PropertyDescriptor];
|
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',
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import {
|
import {
|
||||||
|
DecoratorType,
|
||||||
DecoratorParametersType,
|
DecoratorParametersType,
|
||||||
|
PrimitiveType,
|
||||||
PropertyKeyType,
|
PropertyKeyType,
|
||||||
} from './type';
|
} from './type';
|
||||||
|
|
||||||
|
@ -44,19 +46,19 @@ export function isPrimitiveOrPrimitiveClass(target: any): boolean {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param target
|
* @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)) {
|
if (isString(target)) {
|
||||||
return 'string';
|
return PrimitiveType.STRING;
|
||||||
}
|
}
|
||||||
if (isNumber(target)) {
|
if (isNumber(target)) {
|
||||||
return 'number';
|
return PrimitiveType.NUMBER;
|
||||||
}
|
}
|
||||||
if (isBoolean(target)) {
|
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
|
* @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;
|
const [, propertyKey, descriptor] = args;
|
||||||
|
|
||||||
if (typeof descriptor === 'number') {
|
if (typeof descriptor === 'number') {
|
||||||
return 'parameter';
|
return DecoratorType.PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyKey && descriptor === undefined || descriptor && (descriptor.get || descriptor.set)) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,10 +2,3 @@ export const ANNOTATION_HANDLER_CLASS: string = 'classDecorator';
|
||||||
export const ANNOTATION_HANDLER_PROPERTY: string = 'propertyDecorator';
|
export const ANNOTATION_HANDLER_PROPERTY: string = 'propertyDecorator';
|
||||||
export const ANNOTATION_HANDLER_METHOD: string = 'methodDecorator';
|
export const ANNOTATION_HANDLER_METHOD: string = 'methodDecorator';
|
||||||
export const ANNOTATION_HANDLER_PARAMETER: string = 'parameterDecorator';
|
export const ANNOTATION_HANDLER_PARAMETER: string = 'parameterDecorator';
|
||||||
|
|
||||||
export enum DecoratorType {
|
|
||||||
CLASS = 'Class',
|
|
||||||
PROPERTY = 'Property',
|
|
||||||
METHOD = 'Method',
|
|
||||||
PARAMETER = 'Parameter',
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
DecoratorType,
|
||||||
Type,
|
Type,
|
||||||
} from '@overflow/commons/core/type';
|
} from '@overflow/commons/core/type';
|
||||||
|
|
||||||
|
@ -17,18 +18,35 @@ export class Decorator {
|
||||||
let name: string = AnnotationClass.name;
|
let name: string = AnnotationClass.name;
|
||||||
|
|
||||||
return (...decoratorArgs: any[]) => {
|
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 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 DecoratorType.CLASS:
|
||||||
|
if (typeof(annotation.classDecorator) === 'undefined') {
|
||||||
|
throw new Error(`Cannot apply @${name} decorator on Class.`);
|
||||||
|
}
|
||||||
|
|
||||||
return annotation.classDecorator.call(annotation, decoratorArgs[0]);
|
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]);
|
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]);
|
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]);
|
return annotation.parameterDecorator.call(annotation, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
|
||||||
default:
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class WebApp extends React.Component<Props, State> {
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<b>Hello....</b>
|
<b>Hello...</b>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user