gristlabs_grist-core/app/client/app.js
Jarosław Sadziński 5219932a1f (core) i18
Summary:
Adding initial work for localization support.

Summary in https://grist.quip.com/OtZKA6RHdQ6T/Internationalization-and-Localization

Test Plan: Not yet

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3633
2022-09-29 18:02:09 +02:00

60 lines
2.3 KiB
JavaScript

/* global $, window */
// This is the entry point into loading the whole of Grist frontend application. Some extensions
// attempt to load it more than once (e.g. "Lingvanex"). This leads to duplicated work and errors.
// At least some of such interference can be neutralized by simply ignoring repeated loads.
if (window._gristAppLoaded) {
return;
}
window._gristAppLoaded = true;
const {setupLocale} = require('./lib/localization');
const {App} = require('./ui/App');
// Disable longStackTraces, which seem to be enabled in the browser by default.
var bluebird = require('bluebird');
bluebird.config({ longStackTraces: false });
// Set up integration between grainjs and knockout disposal.
const {setupKoDisposal} = require('grainjs');
const ko = require('knockout');
setupKoDisposal(ko);
$(function() {
// Manually disable the bfcache. We dispose some components in App.ts on unload, and
// leaving the cache on causes problems when the browser back/forward buttons are pressed.
// Some browsers automatically disable it when the 'beforeunload' or 'unload' events
// have listeners, but not all do (Safari).
window.onpageshow = function(event) {
if (event.persisted) { window.location.reload(); }
};
const localeSetup = setupLocale();
// By the time dom ready is fired, resource files should already be loaded, but
// if that is not the case, we will redirect to an error page by throwing an error.
localeSetup.then(() => {
window.gristApp = App.create(null);
}).catch(error => {
throw new Error(`Failed to load locale: ${error?.message || 'Unknown error'}`);
})
// Set from the login tests to stub and un-stub functions during execution.
window.loginTestSandbox = null;
// These modules are exposed for the sake of browser tests.
window.exposeModulesForTests = function() {
return (import('./exposeModulesForTests' /* webpackChunkName: "modulesForTests" */));
};
window.exposedModules = {
// Several existing tests use window.exposedModules.loadScript has loaded
// a file for them. We now load exposedModules asynchronously, so that it
// doesn't slow down application startup. To avoid changing tests
// unnecessarily, we implement a loadScript wrapper.
loadScript(name) {
return window.exposeModulesForTests()
.then(() => window.exposedModules._loadScript(name));
}
};
});