UNPKG

ajsfw

Version:
110 lines (109 loc) 7.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils = require("ajsfw/utils"); var resources = require("ajsfw/resources"); var resources_1 = require("ajsfw/resources"); var exceptions = require("./exceptions"); var Application = (function () { function Application(container, resourceManager, templateManager, navigator, router, viewComponentManager, config) { var _this = this; this.__container = container; this.__resourceManager = resourceManager; this.__templateManager = templateManager; this.__navigator = navigator; this.__router = router; this.__viewComponentManager = viewComponentManager; this.__config = config; this.__resources = {}; this.__templates = {}; if (config.hasOwnProperty("resourcesLoadingPreference")) { this._resourcesLoadingPreference = config.resourcesLoadingPreference; } else { this._resourcesLoadingPreference = resources_1.LoadingPreference.Server; } window.addEventListener("error", function (e) { return _this._onError(e); }); window.addEventListener("beforeunload", function (e) { return _this.__finalize(e); }); } Object.defineProperty(Application.prototype, "_config", { get: function () { return this.__config; }, enumerable: true, configurable: true }); Application.prototype.initialize = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { this._onConfigure(this.__container, this.__resources, this.__templates, this.__navigator.redirections, this.__router.routes, this.__viewComponentManager); return [2, this._onInitialize()]; }); }); }; Application.prototype.run = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, Promise.all([ this.__loadresources(), this.__loadTemplates() ])]; case 1: _a.sent(); this.__navigator.canNavigate = true; this.__navigator.navigated(); return [2]; } }); }); }; Application.prototype._onError = function (e) { utils.errorHandler(e); }; Application.prototype._onConfigure = function (container, resources, templates, redirections, routes, viewComponentManager) { return; }; Application.prototype._onInitialize = function () { return Promise.resolve(); }; Application.prototype._onFinalize = function (e) { return; }; Application.prototype.__finalize = function (e) { return this._onFinalize(e); }; Application.prototype.__loadresources = function () { var _resourcesLoadingInfo = [ this.__resourceManager.getMultipleResources(this.__resources.localPermanent, resources.StorageType.Local, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.localLastRecentlyUsed, resources.StorageType.Local, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.sessionPermanent, resources.StorageType.Session, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.sessionLastRecentlyUsed, resources.StorageType.Session, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.indexedDbPermanent, resources.StorageType.IndexedDb, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.indexedDbLastRecentlyUsed, resources.StorageType.IndexedDb, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.memoryPermanent, resources.StorageType.Memory, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.memoryLastRecentlyUsed, resources.StorageType.Memory, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__resourceManager.getMultipleResources(this.__resources.direct, undefined, undefined) ]; return Promise.all(_resourcesLoadingInfo) .catch(function (reason) { throw new exceptions.FailedToLoadApplicationResourcesException(reason); }); }; Application.prototype.__loadTemplates = function () { var _resourcesLoadingInfo = [ this.__templateManager.loadTemplates(this.__templates.localPermanent, resources.StorageType.Local, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.localLastRecentlyUsed, resources.StorageType.Local, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.sessionPermanent, resources.StorageType.Session, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.sessionLastRecentlyUsed, resources.StorageType.Session, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.indexedDbPermanent, resources.StorageType.IndexedDb, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.indexedDbLastRecentlyUsed, resources.StorageType.IndexedDb, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.memoryPermanent, resources.StorageType.Memory, resources.CachePolicy.Permanent, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.memoryLastRecentlyUsed, resources.StorageType.Memory, resources.CachePolicy.LastRecentlyUsed, this._resourcesLoadingPreference), this.__templateManager.loadTemplates(this.__templates.direct, undefined, undefined) ]; return Promise.all(_resourcesLoadingInfo) .catch(function (reason) { throw new exceptions.FailedToLoadApplicationTemplatesException(reason); }); }; return Application; }()); exports.Application = Application;