This commit is contained in:
crusader 2017-12-20 23:54:26 +09:00
parent fec88d5f8e
commit 6b9ff2db2d
10 changed files with 85 additions and 43 deletions

View File

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

View File

@ -0,0 +1,3 @@
export * from './reducer';
export * from './rest_api';
export * from './rpc_api';

View File

@ -30,5 +30,3 @@ export class ReducerAnnotation extends Annotation {
}
export const Reducer = Decorator.create(ReducerAnnotation);
export default Reducer;

View File

@ -30,5 +30,3 @@ export class RestAPIAnnotation extends Annotation {
}
export const RestAPI = Decorator.create(RestAPIAnnotation);
export default RestAPI;

View File

@ -30,5 +30,3 @@ export class RpcAPIAnnotation extends Annotation {
}
export const RpcAPI = Decorator.create(RpcAPIAnnotation);
export default RpcAPI;

View File

@ -2,33 +2,33 @@ import {
Action,
} from './action';
class LPCReducer {
export default class LPCReducer {
private reducerMap: Map<string, any[]>;
private constructor() {
protected constructor() {
this.reducerMap = new Map();
}
public reducer<State>(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;
}
/**

View File

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

View File

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

View File

@ -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<void> {
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(
<AppContainer>
<Provider store={this.store}>
@ -120,19 +128,20 @@ class WebAppApplication {
this.container,
);
});
} else {
ReactDOM.render(
<AppContainer>
<Provider store={this.store}>
<ConnectedRouter history={this.history}>
</ConnectedRouter>
</Provider>
</AppContainer>
,
this.container,
);
}
ReactDOM.render(
<AppContainer>
<Provider store={this.store}>
<ConnectedRouter history={this.history}>
</ConnectedRouter>
</Provider>
</AppContainer>
,
this.container,
);
}

View File

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