Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/loadable / dist / loadable.js
Size: Mime:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const LoadableContext_1 = require("./LoadableContext");
function loadable(asyncRequire) {
    const scoped = new LoadableContext_1.LoadableContext(asyncRequire);
    if (typeof window !== 'object') {
        console.debug('[code-splitting] loading ssr ' + scoped.componentName);
        scoped.init();
    }
    /**
     * @todo could simply scope this
     * & pass in the loading as a prop for better @@perf?
     */
    return class LoadableCodeSplit extends react_1.default.PureComponent {
        componentDidMount() {
            if (scoped.isLoaded === false) {
                console.debug('[code-splitting] componentWillMount: ', scoped.componentName);
                // @note - this only happens once
                const onLoad = () => {
                    console.debug('[code-splitting] onLoad: ', scoped.componentName);
                    this.forceUpdate();
                };
                scoped.wait().then(onLoad);
            }
        }
        render() {
            console.debug('[code-splitting] render');
            if (scoped.isLoaded === false) {
                return 'loading';
            }
            else if (!scoped.resolved) {
                console.log(this);
                return 'error!';
            }
            else {
                return react_1.default.createElement(scoped.resolved, this.props);
            }
        }
    };
}
exports.loadable = loadable;
exports.default = loadable;
//# sourceMappingURL=loadable.js.map