abb-core
Version:
Application Build Butler Core
60 lines (59 loc) • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var index_1 = require("../../index");
var React = require("react");
var react_redux_1 = require("react-redux");
var ABBCore = /** @class */ (function (_super) {
tslib_1.__extends(ABBCore, _super);
function ABBCore(props) {
var _this = _super.call(this, props) || this;
// register core plugin
_this.props.CoreAPI.Store.dispatch(index_1.ABBCoreAPI.addPluginAction(ABBCore.corePluginName, Promise.resolve(_this), _this.props.CoreActionCreator || new index_1.ABBCoreActionCreator()));
// If no translator is provided set it to undefined and resolve initialization promise
if (!_this.props.Translator) {
_this.props.CoreAPI.translatorIsInitializedPromise.resolve(undefined);
}
else {
// register translator plugin
_this.props.CoreAPI.Store.dispatch(index_1.ABBCoreAPI.addPluginAction(ABBCore.translatorPluginName, _this.props.CoreAPI.translatorIsInitializedPromise, _this.props.TranslatorActionCreator || new index_1.ABBTranslatorActionCreator()));
}
// register router plugin
_this.props.CoreAPI.Store.dispatch(index_1.ABBCoreAPI.addPluginAction(ABBCore.routerPluginName, _this.props.CoreAPI.routerIsInitializedPromise, _this.props.RouterActionCreator || new index_1.ABBRouterActionCreator()));
// core is ready to use
Promise.all([
_this.props.CoreAPI.routerIsInitializedPromise,
_this.props.CoreAPI.translatorIsInitializedPromise
]).then(function () {
_this.props.CoreAPI.coreIsInitializedPromise.resolve(_this);
});
return _this;
}
ABBCore.prototype.render = function () {
var _this = this;
var _a = this.props, Translator = _a.Translator, Router = _a.Router;
return (React.createElement(react_redux_1.Provider, { store: this.props.CoreAPI.Store }, Translator
?
React.createElement(Translator, { CoreAPI: this.props.CoreAPI, ref: function (translator) {
if (translator) {
_this.props.CoreAPI.translatorIsInitializedPromise.resolve(translator);
}
} },
React.createElement(Router, { CoreAPI: this.props.CoreAPI, Header: this.props.Header || index_1.RCABBHeader, ref: function (router) {
if (router) {
_this.props.CoreAPI.routerIsInitializedPromise.resolve(router);
}
} }))
:
React.createElement(Router, { CoreAPI: this.props.CoreAPI, Header: this.props.Header || index_1.RCABBHeader, ref: function (router) {
if (router) {
_this.props.CoreAPI.routerIsInitializedPromise.resolve(router);
}
} })));
};
ABBCore.routerPluginName = 'Router';
ABBCore.translatorPluginName = 'Translator';
ABBCore.corePluginName = 'Core';
return ABBCore;
}(React.Component));
exports.ABBCore = ABBCore;