ing
This commit is contained in:
parent
fec88d5f8e
commit
6b9ff2db2d
|
@ -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;
|
||||
|
|
3
src/ts/@overflow/commons/redux/decorators/index.ts
Normal file
3
src/ts/@overflow/commons/redux/decorators/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export * from './reducer';
|
||||
export * from './rest_api';
|
||||
export * from './rpc_api';
|
|
@ -30,5 +30,3 @@ export class ReducerAnnotation extends Annotation {
|
|||
}
|
||||
|
||||
export const Reducer = Decorator.create(ReducerAnnotation);
|
||||
|
||||
export default Reducer;
|
||||
|
|
|
@ -30,5 +30,3 @@ export class RestAPIAnnotation extends Annotation {
|
|||
}
|
||||
|
||||
export const RestAPI = Decorator.create(RestAPIAnnotation);
|
||||
|
||||
export default RestAPI;
|
||||
|
|
|
@ -30,5 +30,3 @@ export class RpcAPIAnnotation extends Annotation {
|
|||
}
|
||||
|
||||
export const RpcAPI = Decorator.create(RpcAPIAnnotation);
|
||||
|
||||
export default RpcAPI;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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,8 +128,7 @@ class WebAppApplication {
|
|||
this.container,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
ReactDOM.render(
|
||||
<AppContainer>
|
||||
<Provider store={this.store}>
|
||||
|
@ -135,6 +142,8 @@ class WebAppApplication {
|
|||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static main(): void {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user