chore: cleanup the other declaration-data.js singleton

main
Henrik 2023-07-20 22:55:09 +02:00
parent 5ce54e8e10
commit 92650029f0
1 changed files with 5 additions and 9 deletions

View File

@ -24,7 +24,6 @@ export class DeclarationDataCenter {
/** /**
* Used to implement the singleton, in case we need to fetch data mutiple times in the same page. * Used to implement the singleton, in case we need to fetch data mutiple times in the same page.
*/ */
static singleton = null;
static requestSingleton = null; static requestSingleton = null;
/** /**
@ -42,13 +41,10 @@ export class DeclarationDataCenter {
* @returns {Promise<DeclarationDataCenter>} * @returns {Promise<DeclarationDataCenter>}
*/ */
static async init() { static async init() {
if (DeclarationDataCenter.singleton === null) {
if (DeclarationDataCenter.requestSingleton === null) { if (DeclarationDataCenter.requestSingleton === null) {
DeclarationDataCenter.requestSingleton = DeclarationDataCenter.getData(); DeclarationDataCenter.requestSingleton = DeclarationDataCenter.getData();
} }
await DeclarationDataCenter.requestSingleton; return await DeclarationDataCenter.requestSingleton;
}
return DeclarationDataCenter.singleton;
} }
static async getData() { static async getData() {
@ -61,13 +57,13 @@ export class DeclarationDataCenter {
const data = await fetchCachedDeclarationData().catch(_e => null); const data = await fetchCachedDeclarationData().catch(_e => null);
if (data) { if (data) {
// if data is defined, use the cached one. // if data is defined, use the cached one.
DeclarationDataCenter.singleton = new DeclarationDataCenter(data); return new DeclarationDataCenter(data);
} else { } else {
// undefined. then fetch the data from the server. // undefined. then fetch the data from the server.
const dataListRes = await fetch(dataListUrl); const dataListRes = await fetch(dataListUrl);
const data = await dataListRes.json(); const data = await dataListRes.json();
await cacheDeclarationData(data); await cacheDeclarationData(data);
DeclarationDataCenter.singleton = new DeclarationDataCenter(data); return new DeclarationDataCenter(data);
} }
} }