UNPKG

react-application-core

Version:

A react-based application core for the business applications.

173 lines 7.31 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WebBootstrapper = void 0; var inversify_1 = require("inversify"); var util_1 = require("../../util"); var di_1 = require("../../di"); var definition_1 = require("../../definition"); var WebBootstrapper = /** @class */ (function () { /** * @stable [09.01.2020] */ function WebBootstrapper() { var _this = this; this.asyncLibraries = new Map(); var _a = this.settings, asyncLibraries = _a.asyncLibraries, googleMaps = _a.googleMaps; var googleMapsKey = this.environment.googleMapsKey; util_1.ConditionUtils.ifNotNilThanValue(util_1.nvl(asyncLibraries, googleMapsKey), function () { util_1.ConditionUtils.ifNotNilThanValue(asyncLibraries.googleMaps, function (googleMapsLibCfg) { _this.registerAsyncLibrary({ url: util_1.appendUrlArgs(googleMapsLibCfg, { key: googleMapsKey, libraries: googleMaps.libraries, }), alias: definition_1.AsyncLibsEnum.GOOGLE_MAPS, }); }); }); } /** * @stable [09.01.2020] * @param {IAsyncLibConfigEntity} cfg * @returns {IBootstrapper} */ WebBootstrapper.prototype.registerAsyncLibrary = function (cfg) { this.asyncLibraries.set(cfg.alias || cfg.url, cfg); return this; }; /** * @stable [01.10.2019] * @param {() => void} callback */ WebBootstrapper.prototype.init = function (callback) { var _this = this; var environment = this.environment; var document = environment.document; var ready = function () { _this.applyClasses(); _this.addRootElement(); callback(); }; this.initGA(); this.initAsyncLibraries(); switch (document.readyState) { case 'loading': case 'interactive': // We cannot use DOMContentLoaded because fonts loading and UI blinking this.eventManager.add(environment.window, definition_1.EventsEnum.LOAD, ready); break; case 'complete': ready(); break; } }; /** * @stable [01.10.2019] */ WebBootstrapper.prototype.addRootElement = function () { this.domAccessor.addClassNames(this.domAccessor.addRootElement(), util_1.orNull(this.bSettings.flexEnabled, 'rac-flex') // TODO Drop later ); }; /** * @stable [01.10.2019] */ WebBootstrapper.prototype.initGA = function () { var environment = this.environment; if (environment.prodMode && environment.googleKey) { this.gtag('js', new Date()); this.gtag('config', environment.googleKey); if (util_1.TypeUtils.isFn(this.window.ga)) { this.window.ga('create', environment.googleKey, 'auto'); } } }; /** * @stable [09.01.2020] */ WebBootstrapper.prototype.initAsyncLibraries = function () { var _this = this; this.asyncLibraries.forEach(function (cfg) { return _this.asyncLibManager.registerLib(cfg); }); }; /** * @stable [01.10.2019] */ WebBootstrapper.prototype.applyClasses = function () { var environment = this.environment; var document = environment.document; this.domAccessor.addClassNames(document.body, definition_1.ComponentClassesEnum.RAC, environment.appProfile, environment.mobilePlatform ? definition_1.ComponentClassesEnum.MOBILE : definition_1.ComponentClassesEnum.DESKTOP, util_1.orNull(environment.androidPlatform, definition_1.ComponentClassesEnum.ANDROID), util_1.orNull(environment.iosPlatform, definition_1.ComponentClassesEnum.IOS), util_1.orNull(environment.macPlatform, definition_1.ComponentClassesEnum.MAC), util_1.orNull(environment.chromePlatform, definition_1.ComponentClassesEnum.CHROME), util_1.orNull(environment.safariPlatform, definition_1.ComponentClassesEnum.SAFARI)); }; /** * @stable [01.10.2019] * @param args */ WebBootstrapper.prototype.gtag = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var dL = this.window.dataLayer = this.window.dataLayer || []; dL.push(arguments); }; Object.defineProperty(WebBootstrapper.prototype, "bSettings", { /** * @stable [@stable [01.10.2019]] * @returns {IBootstrapSettings} */ get: function () { return this.settings.bootstrap || {}; }, enumerable: false, configurable: true }); Object.defineProperty(WebBootstrapper.prototype, "window", { /** * @stable [01.10.2019] * @returns {Window} */ get: function () { return this.environment.window; }, enumerable: false, configurable: true }); __decorate([ di_1.lazyInject(di_1.DI_TYPES.AsyncLibManager), __metadata("design:type", Object) ], WebBootstrapper.prototype, "asyncLibManager", void 0); __decorate([ di_1.lazyInject(di_1.DI_TYPES.DomAccessor), __metadata("design:type", Object) ], WebBootstrapper.prototype, "domAccessor", void 0); __decorate([ di_1.lazyInject(di_1.DI_TYPES.Environment), __metadata("design:type", Object) ], WebBootstrapper.prototype, "environment", void 0); __decorate([ di_1.lazyInject(di_1.DI_TYPES.EventManager), __metadata("design:type", Object) ], WebBootstrapper.prototype, "eventManager", void 0); __decorate([ di_1.lazyInject(di_1.DI_TYPES.Settings), __metadata("design:type", Object) ], WebBootstrapper.prototype, "settings", void 0); __decorate([ di_1.lazyInject(di_1.DI_TYPES.UiFactory), __metadata("design:type", Object) ], WebBootstrapper.prototype, "uiFactory", void 0); WebBootstrapper = __decorate([ inversify_1.injectable(), __metadata("design:paramtypes", []) ], WebBootstrapper); return WebBootstrapper; }()); exports.WebBootstrapper = WebBootstrapper; //# sourceMappingURL=web-bootstrapper.service.js.map