@nu-art/thunder
Version:
Thunder - React & Typescript based frontend framework
48 lines • 1.9 kB
JavaScript
;
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 SimpleScriptInjector = /** @class */ (function (_super) {
__extends(SimpleScriptInjector, _super);
function SimpleScriptInjector() {
return _super !== null && _super.apply(this, arguments) || this;
}
SimpleScriptInjector.prototype.componentDidMount = function () {
var _this = this;
if (SimpleScriptInjector.injected[this.props.src]) {
setTimeout(function () {
_this.props.onLoaded(_this.props.src);
});
return;
}
var script = document.createElement("script");
script.type = "text/javascript";
script.src = this.props.src;
script.async = true;
script.id = this.props.src;
script.onload = function () {
_this.props.onLoaded(_this.props.src);
};
document.body.appendChild(script);
SimpleScriptInjector.injected[this.props.src] = script;
};
SimpleScriptInjector.prototype.render = function () {
return "";
};
SimpleScriptInjector.injected = {};
return SimpleScriptInjector;
}(React.Component));
exports.SimpleScriptInjector = SimpleScriptInjector;
//# sourceMappingURL=SimpleScriptInjector.js.map