From 6b9ff2db2dacd28f9b3a1dbfadce13e297fd6a35 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 20 Dec 2017 23:54:26 +0900 Subject: [PATCH] ing --- .../@overflow/commons/decorator/decorator.ts | 9 ++--- .../commons/redux/decorators/index.ts | 3 ++ .../commons/redux/decorators/reducer.ts | 2 -- .../commons/redux/decorators/rest_api.ts | 2 -- .../commons/redux/decorators/rpc_api.ts | 2 -- src/ts/@overflow/commons/redux/lpc_reducer.ts | 32 ++++++++--------- .../modules/member/reducer/member_reducer.ts | 6 ++++ src/ts/@overflow/webapp/config/index.ts | 31 ++++++++++++++++ src/ts/@overflow/webapp/index.tsx | 35 ++++++++++++------- .../@overflow/webapp/redux/webapp_reducer.ts | 6 ++-- 10 files changed, 85 insertions(+), 43 deletions(-) create mode 100644 src/ts/@overflow/commons/redux/decorators/index.ts diff --git a/src/ts/@overflow/commons/decorator/decorator.ts b/src/ts/@overflow/commons/decorator/decorator.ts index c631774..2dd4261 100644 --- a/src/ts/@overflow/commons/decorator/decorator.ts +++ b/src/ts/@overflow/commons/decorator/decorator.ts @@ -14,6 +14,7 @@ export class Decorator { return (...handlerArgs: any[]) => { let annotation: Annotation = new AnnotationClass(...handlerArgs); + let name: string = AnnotationClass.name; return (...decoratorArgs: any[]) => { let decoratorType: Constants.DecoratorType = Decorator._detectDecoratorType(name, annotation, decoratorArgs); @@ -46,23 +47,23 @@ export class Decorator { let decoratorType: Constants.DecoratorType; if (1 === paramCount) { - if (Constants.ANNOTATION_HANDLER_CLASS in annotation) { + if (typeof(annotation.classDecorator) === 'undefined') { throw new Error(`Cannot apply @${name} decorator on Class.`); } decoratorType = Constants.DecoratorType.CLASS; } else if (2 === paramCount) { - if (Constants.ANNOTATION_HANDLER_PROPERTY in annotation) { + 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 (Constants.ANNOTATION_HANDLER_PARAMETER in annotation) { + if (typeof(annotation.parameterDecorator) === 'undefined') { throw new Error(`Cannot apply @${name} decorator on Parameter.`); } decoratorType = Constants.DecoratorType.PARAMETER; } else { - if (Constants.ANNOTATION_HANDLER_METHOD in annotation) { + if (typeof(annotation.methodDecorator) === 'undefined') { throw new Error(`Cannot apply @${name} decorator on Method.`); } decoratorType = Constants.DecoratorType.METHOD; diff --git a/src/ts/@overflow/commons/redux/decorators/index.ts b/src/ts/@overflow/commons/redux/decorators/index.ts new file mode 100644 index 0000000..895421b --- /dev/null +++ b/src/ts/@overflow/commons/redux/decorators/index.ts @@ -0,0 +1,3 @@ +export * from './reducer'; +export * from './rest_api'; +export * from './rpc_api'; diff --git a/src/ts/@overflow/commons/redux/decorators/reducer.ts b/src/ts/@overflow/commons/redux/decorators/reducer.ts index a0257e4..480513a 100644 --- a/src/ts/@overflow/commons/redux/decorators/reducer.ts +++ b/src/ts/@overflow/commons/redux/decorators/reducer.ts @@ -30,5 +30,3 @@ export class ReducerAnnotation extends Annotation { } export const Reducer = Decorator.create(ReducerAnnotation); - -export default Reducer; diff --git a/src/ts/@overflow/commons/redux/decorators/rest_api.ts b/src/ts/@overflow/commons/redux/decorators/rest_api.ts index bf0850e..35fbbe2 100644 --- a/src/ts/@overflow/commons/redux/decorators/rest_api.ts +++ b/src/ts/@overflow/commons/redux/decorators/rest_api.ts @@ -30,5 +30,3 @@ export class RestAPIAnnotation extends Annotation { } export const RestAPI = Decorator.create(RestAPIAnnotation); - -export default RestAPI; diff --git a/src/ts/@overflow/commons/redux/decorators/rpc_api.ts b/src/ts/@overflow/commons/redux/decorators/rpc_api.ts index 73bb59a..95d1b79 100644 --- a/src/ts/@overflow/commons/redux/decorators/rpc_api.ts +++ b/src/ts/@overflow/commons/redux/decorators/rpc_api.ts @@ -30,5 +30,3 @@ export class RpcAPIAnnotation extends Annotation { } export const RpcAPI = Decorator.create(RpcAPIAnnotation); - -export default RpcAPI; diff --git a/src/ts/@overflow/commons/redux/lpc_reducer.ts b/src/ts/@overflow/commons/redux/lpc_reducer.ts index 8b942f0..38630c5 100644 --- a/src/ts/@overflow/commons/redux/lpc_reducer.ts +++ b/src/ts/@overflow/commons/redux/lpc_reducer.ts @@ -2,33 +2,33 @@ import { Action, } from './action'; -class LPCReducer { +export default class LPCReducer { private reducerMap: Map; - private constructor() { + protected constructor() { this.reducerMap = new Map(); } public reducer(state: State, action: Action): State { - let rm: string[] = action.type.split('.'); - if (null == rm || 2 !== rm.length) { - console.log(`Method[${action.type}] is not valid.`); - return null; - } + // let rm: string[] = action.type.split('.'); + // if (null == rm || 2 !== rm.length) { + // console.log(`Method[${action.type}] is not valid.`); + // return null; + // } - const reducerName: string = rm[0]; - const methodName: string = rm[1]; + // const reducerName: string = rm[0]; + // const methodName: string = rm[1]; - if (this.reducerMap.has(reducerName)) { - let reducers = this.reducerMap.get(reducerName); - for (let reducer of reducers) { + // if (this.reducerMap.has(reducerName)) { + // let reducers = this.reducerMap.get(reducerName); + // for (let reducer of reducers) { - state = reducer(state, action); - } - } + // state = reducer(state, action); + // } + // } - return null; + return state; } /** diff --git a/src/ts/@overflow/modules/member/reducer/member_reducer.ts b/src/ts/@overflow/modules/member/reducer/member_reducer.ts index 1c979a3..a3de460 100644 --- a/src/ts/@overflow/modules/member/reducer/member_reducer.ts +++ b/src/ts/@overflow/modules/member/reducer/member_reducer.ts @@ -1,8 +1,14 @@ +import { + Reducer, + RestAPI, +} from '@overflow/commons/redux/decorators'; +@Reducer('@overflow/modules/member/MemberReducer') export default class MemberReducer { /** * signin */ + @RestAPI('/account/signin') public signin(state: any, result: any, error: any): any { return state; diff --git a/src/ts/@overflow/webapp/config/index.ts b/src/ts/@overflow/webapp/config/index.ts index e69de29..ac40ef1 100644 --- a/src/ts/@overflow/webapp/config/index.ts +++ b/src/ts/@overflow/webapp/config/index.ts @@ -0,0 +1,31 @@ +import MemberReducer from '@overflow/modules/member/reducer/member_reducer'; + + +const reducers: any[] = [ + MemberReducer, +]; + +const state: any = { + +}; + +export interface ReduxConfig { + state: any; + reducers: any[]; +} + +const reduxConfig: ReduxConfig = { + state: state, + reducers: reducers, +}; + +// Configuration +export interface WebAppConfig { + redux: ReduxConfig; +} + +const config: WebAppConfig = { + redux: reduxConfig, +}; + +export default config; diff --git a/src/ts/@overflow/webapp/index.tsx b/src/ts/@overflow/webapp/index.tsx index 0202bf6..95fcaa8 100644 --- a/src/ts/@overflow/webapp/index.tsx +++ b/src/ts/@overflow/webapp/index.tsx @@ -28,12 +28,17 @@ import { AppContainer, } from 'react-hot-loader'; -declare let module: { hot: any }; +import config from './config'; +import WebAppReducer from '@overflow/webapp/redux/webapp_reducer'; + +// declare let module: { hot: any }; declare global { interface Window { devToolsExtension: () => any; } + const process: any; + const module: { hot: any }; } class WebAppApplication { @@ -52,6 +57,9 @@ class WebAppApplication { public async run(): Promise { try { this.renderLoading(); + let reducer: WebAppReducer = WebAppReducer.getInstance(); + this.store = createStore(reducer.reducer, config.redux.state); + this.renderApp(); } catch (e) { console.error(e); @@ -107,7 +115,7 @@ class WebAppApplication { private rederDevelopment(): void { if (module.hot) { module.hot.accept('./pages/webapp', async () => { - const NextApp = (await require('./pages/webapp')).default; + const NextApp = (await import('./pages/webapp')).default; ReactDOM.render( @@ -120,19 +128,20 @@ class WebAppApplication { this.container, ); }); + } else { + ReactDOM.render( + + + + + + + + , + this.container, + ); } - ReactDOM.render( - - - - - - - - , - this.container, - ); } diff --git a/src/ts/@overflow/webapp/redux/webapp_reducer.ts b/src/ts/@overflow/webapp/redux/webapp_reducer.ts index fd44f48..da592d3 100644 --- a/src/ts/@overflow/webapp/redux/webapp_reducer.ts +++ b/src/ts/@overflow/webapp/redux/webapp_reducer.ts @@ -1,8 +1,6 @@ -import { - LPCReducer, -} from '@overflow/commons/redux/lpc_reducer'; +import LPCReducer from '@overflow/commons/redux/lpc_reducer'; -class WebAppReducer extends LPCReducer { +export default class WebAppReducer extends LPCReducer { private static readonly instance: WebAppReducer = new WebAppReducer(); public static getInstance(): WebAppReducer { return WebAppReducer.instance;