This commit is contained in:
crusader 2017-12-29 17:02:42 +09:00
parent 046ea0e6f2
commit 57acc39ee2
3 changed files with 21 additions and 18 deletions

View File

@ -28,7 +28,7 @@ export class InstanceFactory implements InstanceDefinitionRegistry {
* getInstance * getInstance
*/ */
public getInstance(name: InstanceNameType, requiredType: ClassType, ...args: any[]): any | undefined { public getInstance(name: InstanceNameType, requiredType: ClassType, ...args: any[]): any | undefined {
if (null === name) { if (undefined === name) {
name = requiredType.name; name = requiredType.name;
} }
@ -105,6 +105,7 @@ export class InstanceFactory implements InstanceDefinitionRegistry {
private getSingleton(name: InstanceNameType): any | undefined { private getSingleton(name: InstanceNameType): any | undefined {
let singletonObject = this._singletonObjects.get(name); let singletonObject = this._singletonObjects.get(name);
return singletonObject;
} }
/** /**

View File

@ -3,6 +3,10 @@ import {
Instance, Instance,
} from '@overflow/commons/application/decorators'; } from '@overflow/commons/application/decorators';
import { Value } from '@overflow/commons/di/decorators'; import { Value } from '@overflow/commons/di/decorators';
import {
createHashHistory,
History,
} from 'history';
@Configuration() @Configuration()
export class WebAppConfiguration { export class WebAppConfiguration {
@ -10,10 +14,10 @@ export class WebAppConfiguration {
private htmlContainerID: string; private htmlContainerID: string;
/** /**
* container * containerPromise
*/ */
@Instance() @Instance()
public container(): Promise<HTMLElement> { public containerPromise(): Promise<HTMLElement> {
function getContainer(containerID: string): Promise<HTMLElement> { function getContainer(containerID: string): Promise<HTMLElement> {
return new Promise<HTMLElement>(resolve => { return new Promise<HTMLElement>(resolve => {
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
@ -24,4 +28,13 @@ export class WebAppConfiguration {
return getContainer(this.htmlContainerID); return getContainer(this.htmlContainerID);
} }
/**
* history
*/
@Instance()
public history(): History {
return createHashHistory();
}
} }

View File

@ -79,12 +79,13 @@ class WebAppApplication extends B {
private static isProduction:boolean = process.env.NODE_ENV === 'production' ? true : false; private static isProduction:boolean = process.env.NODE_ENV === 'production' ? true : false;
private static useReduxDevTools:boolean = window.devToolsExtension && !WebAppApplication.isProduction ? true : false; private static useReduxDevTools:boolean = window.devToolsExtension && !WebAppApplication.isProduction ? true : false;
@Value('html.container.id') @Resource()
private htmlContainerID: string; private containerPromise: Promise<HTMLElement>;
private container: HTMLElement; private container: HTMLElement;
@Resource() @Resource()
private store: Store<any>; private store: Store<any>;
@Resource()
private history: History; private history: History;
@Inject() @Inject()
@ -93,7 +94,7 @@ class WebAppApplication extends B {
@Runner() @Runner()
public async run(): Promise<void> { public async run(): Promise<void> {
try { try {
this.container = await this.getContainer(); this.container = await this.containerPromise;
this.renderLoading(); this.renderLoading();
let reducer: WebAppDispatcherReducer = new WebAppDispatcherReducer(); let reducer: WebAppDispatcherReducer = new WebAppDispatcherReducer();
reducer.registerReducers(config.redux.reducers); reducer.registerReducers(config.redux.reducers);
@ -105,18 +106,6 @@ class WebAppApplication extends B {
} }
} }
private getContainer(): Promise<HTMLElement> {
function getContainer(containerID: string): Promise<HTMLElement> {
return new Promise<HTMLElement>(resolve => {
document.addEventListener('DOMContentLoaded', () => {
resolve(document.getElementById(containerID));
});
});
}
return getContainer(this.htmlContainerID);
}
private renderLoading(): void { private renderLoading(): void {
ReactDOM.render( ReactDOM.render(
<div style={{ <div style={{