Don't reload i18n when cached (#2973)

This commit is contained in:
Jaco Greeff 2020-06-17 16:24:58 +02:00 committed by GitHub
parent 4c3d3b4675
commit bd1cf8888f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,10 +33,19 @@ type Progress = [[number, number, number], Record<string, [number, number, numbe
type Strings = Record<string, string>;
type StringsMod = Record<string, Strings>;
async function retrieveJson (url: string): Promise<any> {
const response = await fetch(`locales/${url}`);
const cache = new Map<string, unknown>();
return response.json();
async function retrieveJson (url: string): Promise<any> {
if (cache.has(url)) {
return cache.get(url);
}
const response = await fetch(`locales/${url}`);
const json = await response.json() as unknown;
cache.set(url, json);
return json;
}
async function retrieveEnglish (): Promise<StringsMod> {