@nu-art/thunder
Version:
Thunder - React & Typescript based frontend framework
81 lines • 3.74 kB
JavaScript
;
/*
* Thunder is a typescript & react frontend foundation that natively
* runs on firebase function and is a part of the Thunderstorm larger project
*
* Copyright (C) 2018 Adam van der Kruk aka TacB0sS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var index_1 = require("../../index");
var entry_component_loading_module_1 = require("./entry-component-loading-module");
var ReactEntryComponentInjector = /** @class */ (function (_super) {
__extends(ReactEntryComponentInjector, _super);
function ReactEntryComponentInjector(props) {
var _this = _super.call(this, props) || this;
_this.myRef = React.createRef();
_this.onRequestCompleted = function (key, success) {
if (key !== _this.props.src)
return;
if (!success)
// Need to add error handling here...
return;
_this.injectComponent(entry_component_loading_module_1.EntryComponentLoadingModule.getNode(key));
};
_this.state = { loading: false, progress: 0 };
return _this;
}
ReactEntryComponentInjector.prototype.injectComponent = function (node) {
var _a;
(_a = this.myRef.current) === null || _a === void 0 ? void 0 : _a.appendChild(node);
this.setState({ loading: false });
};
ReactEntryComponentInjector.prototype.componentDidMount = function () {
var _this = this;
var src = this.props.src;
var node = entry_component_loading_module_1.EntryComponentLoadingModule.getNode(src);
if (node)
return this.injectComponent(node);
entry_component_loading_module_1.EntryComponentLoadingModule.loadScript(src, function (progress) { return _this.setState({ progress: progress }); });
this.setState({ loading: true });
};
ReactEntryComponentInjector.prototype.render = function () {
return React.createElement("div", { ref: this.myRef, id: this.props.src }, this.extracted());
};
ReactEntryComponentInjector.prototype.extracted = function () {
var Loader = this.props.loader;
if (Loader)
return React.createElement(Loader, { progress: this.state.progress });
return React.createElement("div", { style: { width: "100%", height: "100%" } },
this.state.progress,
" %");
};
return ReactEntryComponentInjector;
}(index_1.BaseComponent));
exports.ReactEntryComponentInjector = ReactEntryComponentInjector;
//# sourceMappingURL=ReactEntryComponentInjector.js.map