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; return undefined;
} }
/**
* applyInstance
*/
public injectByName(clazzType: ClassType, instance: any): void {
}
public injectByType(clazzType: ClassType, instance: any): void {
}
/** /**
* applyInstance * applyInstance
*/ */

View File

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

View File

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