This commit is contained in:
crusader 2017-12-29 19:28:57 +09:00
parent 57acc39ee2
commit fa37e1ba73
6 changed files with 55 additions and 28 deletions

View File

@ -65,6 +65,15 @@ export class InstanceFactory implements InstanceDefinitionRegistry {
return undefined;
}
/**
* applyInstance
*/
public injectByName(clazzType: ClassType, instance: any): void {
}
public injectByType(clazzType: ClassType, instance: any): void {
}
/**
* applyInstance
*/

View File

@ -1,6 +1,6 @@
export * from './injectables';
export * from './json_sources';
export * from './reducer_configuration';
export * from './redux_configuration';
export * from './rest_api_configuration';
export * from './rpc_api_configuration';
export * from './webapp_configuration';

View File

@ -1,17 +0,0 @@
import {
Store,
} from 'redux';
import {
Configuration,
Instance,
} from '@overflow/commons/application/decorators';
@Configuration()
export class ReducerConfiguration {
@Instance()
public store(): Store<any> {
return null;
}
}

View File

@ -0,0 +1,37 @@
import {
applyMiddleware,
compose,
createStore,
GenericStoreEnhancer,
Middleware,
Store,
} from 'redux';
import {
Inject,
} from '@overflow/commons/di/decorators';
import {
Configuration,
Instance,
} from '@overflow/commons/application/decorators';
import {WebAppDispatcherReducer} from '../redux';
@Configuration()
export class ReduxConfiguration {
private static isProduction:boolean = process.env.NODE_ENV === 'production' ? true : false;
private static useReduxDevTools:boolean = window.devToolsExtension && !ReduxConfiguration.isProduction ? true : false;
@Inject()
private dispatcherReducer: WebAppDispatcherReducer;
@Instance()
public store(): Store<any> {
return createStore(
this.dispatcherReducer.reducer,
{},
ReduxConfiguration.useReduxDevTools ? window.devToolsExtension() : undefined,
);
}
}

View File

@ -42,12 +42,11 @@ import {
import config, {
injectables,
jsonSources,
ReducerConfiguration,
ReduxConfiguration,
RestAPIConfiguration,
RpcAPIConfiguration,
WebAppConfiguration,
} from './config';
import {WebAppDispatcherReducer} from './redux';
import WebApp from './pages/webapp';
// declare let module: { hot: any };
@ -69,7 +68,7 @@ class B extends A {
injectables: injectables,
jsonSources: jsonSources,
configurations: [
ReducerConfiguration,
ReduxConfiguration,
RestAPIConfiguration,
RpcAPIConfiguration,
WebAppConfiguration,
@ -88,17 +87,11 @@ class WebAppApplication extends B {
@Resource()
private history: History;
@Inject()
private dispatcherReducer: WebAppDispatcherReducer;
@Runner()
public async run(): Promise<void> {
try {
this.container = await this.containerPromise;
this.renderLoading();
let reducer: WebAppDispatcherReducer = new WebAppDispatcherReducer();
reducer.registerReducers(config.redux.reducers);
this.store = createStore(reducer.reducer, config.redux.state);
this.renderApp();
} catch (e) {

View File

@ -1,11 +1,16 @@
import { ClassType } from '@overflow/commons/core/type';
import {
Injectable,
Injectable, Inject, Resource,
} from '@overflow/commons/di/decorators';
import {DispatcherReducer} from '@overflow/commons/redux';
@Injectable()
export class WebAppDispatcherReducer extends DispatcherReducer {
@Resource()
private reducers: ClassType[];
public constructor() {
super();
}