UNPKG

@intuitionrobotics/thunderstorm

Version:
92 lines 4.27 kB
"use strict"; /* * Thunderstorm is a full web app framework! * * Typescript & Express backend infrastructure that natively runs on firebase function * Typescript & React frontend infrastructure * * Copyright (C) 2020 Intuition Robotics * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Thunder = exports.SuccessHandler_Dispatch = exports.ErrorHandler_Dispatch = exports.SuccessHandler_Toast = exports.ErrorHandler_Toast = void 0; const AppWrapper_1 = require("./AppWrapper"); const ts_common_1 = require("@intuitionrobotics/ts-common"); const XhrHttpModule_1 = require("../modules/http/XhrHttpModule"); const ToasterModule_1 = require("../modules/toaster/ToasterModule"); const RoutingModule_1 = require("../modules/routing/RoutingModule"); const HistoryModule_1 = require("../modules/HistoryModule"); const StorageModule_1 = require("../modules/StorageModule"); const ResourcesModule_1 = require("../modules/ResourcesModule"); const AbstractThunder_1 = require("./AbstractThunder"); const ThunderstormModule_1 = require("../modules/ThunderstormModule"); const DialogModule_1 = require("../modules/dialog/DialogModule"); const thunder_dispatcher_1 = require("./thunder-dispatcher"); const ErrorHandler_Toast = (request, resError) => { const errorMessage = request.errorMessage || (resError === null || resError === void 0 ? void 0 : resError.debugMessage); return errorMessage && ToasterModule_1.ToastModule.toastError(errorMessage); }; exports.ErrorHandler_Toast = ErrorHandler_Toast; const SuccessHandler_Toast = (request) => request.successMessage && ToasterModule_1.ToastModule.toastSuccess(request.successMessage); exports.SuccessHandler_Toast = SuccessHandler_Toast; const ErrorHandler_Dispatch = (request) => AbstractThunder_1.dispatch_requestCompleted.dispatchUI(request.key, false, request.requestData); exports.ErrorHandler_Dispatch = ErrorHandler_Dispatch; const SuccessHandler_Dispatch = (request) => AbstractThunder_1.dispatch_requestCompleted.dispatchUI(request.key, true, request.requestData); exports.SuccessHandler_Dispatch = SuccessHandler_Dispatch; const modules = [ ThunderstormModule_1.ThunderstormModule, XhrHttpModule_1.XhrHttpModule, RoutingModule_1.RoutingModule, HistoryModule_1.BrowserHistoryModule, ToasterModule_1.ToastModule, DialogModule_1.DialogModule, StorageModule_1.StorageModule, ResourcesModule_1.ResourcesModule ]; class Thunder extends AbstractThunder_1.AbstractThunder { constructor() { super(); this.renderApp = () => { (0, AppWrapper_1.renderApp)(); }; this.addModules(...modules); } static getInstance() { return Thunder.instance; } init() { ts_common_1.BeLogged.addClient(ts_common_1.LogClient_Browser); super.init(); XhrHttpModule_1.XhrHttpModule.setErrorHandlers([exports.ErrorHandler_Toast, exports.ErrorHandler_Dispatch]); XhrHttpModule_1.XhrHttpModule.setSuccessHandlers([exports.SuccessHandler_Toast, exports.SuccessHandler_Dispatch]); XhrHttpModule_1.XhrHttpModule.addDefaultResponseHandler((request) => { if (request.getStatus() !== 401) return false; const unauthenticatedDispatcher = new thunder_dispatcher_1.ThunderDispatcher("onUnauthenticatedResponse"); unauthenticatedDispatcher.dispatchUI(); unauthenticatedDispatcher.dispatchModule(); return true; }); return this; } setMainApp(mainApp) { this.mainApp = mainApp; return this; } getMainApp() { return this.mainApp; } } exports.Thunder = Thunder; //# sourceMappingURL=Thunder.js.map