import React, {Component} from 'react';

import * as types from 'reduxes/actionTypes';

export function asyncComponent(store, getComponent) {

    return class AsyncComponent extends Component {

        static Component = null;

        constructor(props) {

            super(props);

            this.state = {
                Component: AsyncComponent.Component
            };

        }

        componentWillMount() {

            if (!this.state.Component) {

                store.dispatch({type: types.LOAD_COMPONENT_START});

                getComponent().then(({default: Component}) => {
                    AsyncComponent.Component = Component;
                    this.setState({
                        Component
                    }, () => {
                        store.dispatch({type: types.LOAD_COMPONENT_COMPLETE});
                    });
                });

            }

        }

        render() {
            const {Component} = this.state;
            if (Component) {
                return <Component {...this.props} />;
            }
            return null;
        }

    };

}
@@ -398,139 +398,437 @@
     
-componentWillMount() %7B%0A%0A            if (!this.state.Component) %7B%0A%0A                store.dispatch(%7Btype: types.LOAD_COMPONENT_START%7D
+loadStartCallback() %7B%0A            setTimeout(() =%3E %7B%0A                store.dispatch(%7Btype: types.LOAD_COMPONENT_START%7D);%0A            %7D, 0);%0A        %7D%0A%0A        loadCompleteCallback() %7B%0A            setTimeout(() =%3E %7B%0A                store.dispatch(%7Btype: types.LOAD_COMPONENT_COMPLETE%7D);%0A            %7D, 0);%0A        %7D%0A%0A        componentWillMount() %7B%0A%0A            if (!this.state.Component) %7B%0A%0A                this.loadStartCallback(
 );%0A%0A
@@ -1078,60 +1078,34 @@
     
-store.dispatch(%7Btype: types.LOAD_COMPONENT_COMPLETE%7D
+this.loadCompleteCallback(
 );%0A 

optimize code