-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5bf6b5
commit 6eb2905
Showing
6 changed files
with
88 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// because this is a module, I'm strict by default | ||
|
||
const database = {}; | ||
|
||
|
||
/** | ||
* localFetch optimaliseert de verbinding met de database op de server | ||
* door het antwoord van de server ook lokaal op te slaan | ||
* | ||
* @param url de vraag aan de database op de server | ||
* @returns {Promise<any>} het antwoord van de server | ||
*/ | ||
async function localFetch(url) { | ||
let object = JSON.parse(sessionStorage.getItem(url)); | ||
if (!object) { | ||
object = await serverFetch(url); | ||
sessionStorage.setItem(url, JSON.stringify(object)); | ||
} | ||
return object; | ||
} | ||
|
||
/** | ||
* serverFetch maakt verbinding met de database voor actuele situatie | ||
* | ||
* @param url de vraag aan de database op de server | ||
* @returns {Promise<any>} het antwoord van de server | ||
*/ | ||
async function serverFetch(url) { | ||
try { | ||
const response = await fetch(server + url); | ||
if (response.ok) { | ||
return await response.json(); | ||
} else { | ||
console.log(`--- serverFetch ---`); | ||
console.log(response); | ||
return false; | ||
} | ||
} catch (error) { | ||
console.log(`--- serverFetch error ---`); | ||
console.error(error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters