abb-core
Version:
Application Build Butler Core
58 lines (57 loc) • 3.15 kB
JavaScript
import * as tslib_1 from "tslib";
import { ABBRouterActionCreator, ABBTranslatorActionCreator, ABBCoreAPI, RCABBHeader, ABBCoreActionCreator } from "../../index";
import * as React from 'react';
import { Provider } from '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(ABBCoreAPI.addPluginAction(ABBCore.corePluginName, Promise.resolve(_this), _this.props.CoreActionCreator || new 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(ABBCoreAPI.addPluginAction(ABBCore.translatorPluginName, _this.props.CoreAPI.translatorIsInitializedPromise, _this.props.TranslatorActionCreator || new ABBTranslatorActionCreator()));
}
// register router plugin
_this.props.CoreAPI.Store.dispatch(ABBCoreAPI.addPluginAction(ABBCore.routerPluginName, _this.props.CoreAPI.routerIsInitializedPromise, _this.props.RouterActionCreator || new 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(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 || RCABBHeader, ref: function (router) {
if (router) {
_this.props.CoreAPI.routerIsInitializedPromise.resolve(router);
}
} }))
:
React.createElement(Router, { CoreAPI: this.props.CoreAPI, Header: this.props.Header || 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));
export { ABBCore };