mirror of
https://git.srhtnin.garden/sarah/srhtnin.github.io.git
synced 2026-10-14 10:48:12 +02:00
Added catalogue version to make webpages not need to repeatedly fetch
info from API.
This commit is contained in:
1 parent
dde47ff5a6
commit
ce6dced3ad
6 files changed
+374
-85
No files matched your search
@@ -1,30 +1,7 @@
|
||||
let MutationSets = {};
|
||||
|
||||
let MutationsLoadPromise = null;
|
||||
let GameContentLoadPromise = null;
|
||||
|
||||
|
||||
async function LoadMutations() {
|
||||
if (MutationsLoadPromise !== null) {
|
||||
return MutationsLoadPromise;
|
||||
}
|
||||
|
||||
|
||||
MutationsLoadPromise =
|
||||
LoadMutationsFromApi();
|
||||
|
||||
|
||||
try {
|
||||
return await MutationsLoadPromise;
|
||||
} catch (Error) {
|
||||
MutationsLoadPromise = null;
|
||||
|
||||
throw Error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function LoadMutationsFromApi() {
|
||||
async function FetchMutationsFromApi() {
|
||||
const Response =
|
||||
await fetch(
|
||||
ApiUrl + "/Mutations.php",
|
||||
@@ -34,7 +11,9 @@ async function LoadMutationsFromApi() {
|
||||
headers: {
|
||||
"Accept":
|
||||
"application/json"
|
||||
}
|
||||
},
|
||||
|
||||
cache: "no-store"
|
||||
}
|
||||
);
|
||||
|
||||
@@ -67,35 +46,5 @@ async function LoadMutationsFromApi() {
|
||||
}
|
||||
|
||||
|
||||
MutationSets =
|
||||
Result.Mutations;
|
||||
|
||||
|
||||
return MutationSets;
|
||||
}
|
||||
|
||||
|
||||
async function LoadGameContent() {
|
||||
if (GameContentLoadPromise === null) {
|
||||
GameContentLoadPromise =
|
||||
Promise.all([
|
||||
LoadPlants(),
|
||||
LoadMutations()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
await GameContentLoadPromise;
|
||||
} catch (Error) {
|
||||
GameContentLoadPromise = null;
|
||||
|
||||
throw Error;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
Plants: Plants,
|
||||
Mutations: MutationSets
|
||||
};
|
||||
return Result.Mutations;
|
||||
}
|
||||
Reference in new issue
Block a user