diff --git a/src/ts/@overflow/commons/di/factory/instance_factory.ts b/src/ts/@overflow/commons/di/factory/instance_factory.ts index 910da5c..8ce31f5 100644 --- a/src/ts/@overflow/commons/di/factory/instance_factory.ts +++ b/src/ts/@overflow/commons/di/factory/instance_factory.ts @@ -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 */ diff --git a/src/ts/@overflow/webapp/config/index.ts b/src/ts/@overflow/webapp/config/index.ts index de89def..2c90a58 100644 --- a/src/ts/@overflow/webapp/config/index.ts +++ b/src/ts/@overflow/webapp/config/index.ts @@ -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'; diff --git a/src/ts/@overflow/webapp/config/reducer_configuration.ts b/src/ts/@overflow/webapp/config/reducer_configuration.ts deleted file mode 100644 index ba6e1d7..0000000 --- a/src/ts/@overflow/webapp/config/reducer_configuration.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { - Store, -} from 'redux'; - -import { - Configuration, - Instance, -} from '@overflow/commons/application/decorators'; - -@Configuration() -export class ReducerConfiguration { - - @Instance() - public store(): Store { - return null; - } -} diff --git a/src/ts/@overflow/webapp/config/redux_configuration.ts b/src/ts/@overflow/webapp/config/redux_configuration.ts new file mode 100644 index 0000000..d4ebed0 --- /dev/null +++ b/src/ts/@overflow/webapp/config/redux_configuration.ts @@ -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 { + return createStore( + this.dispatcherReducer.reducer, + {}, + ReduxConfiguration.useReduxDevTools ? window.devToolsExtension() : undefined, + ); + } +} diff --git a/src/ts/@overflow/webapp/index.tsx b/src/ts/@overflow/webapp/index.tsx index 29b74c0..02b4d5b 100644 --- a/src/ts/@overflow/webapp/index.tsx +++ b/src/ts/@overflow/webapp/index.tsx @@ -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 { 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) { diff --git a/src/ts/@overflow/webapp/redux/webapp_dispatch_reducer.ts b/src/ts/@overflow/webapp/redux/webapp_dispatch_reducer.ts index 7293861..3c52199 100644 --- a/src/ts/@overflow/webapp/redux/webapp_dispatch_reducer.ts +++ b/src/ts/@overflow/webapp/redux/webapp_dispatch_reducer.ts @@ -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(); }