-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataLoader.js.html
More file actions
111 lines (85 loc) · 3.52 KB
/
dataLoader.js.html
File metadata and controls
111 lines (85 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: dataLoader.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: dataLoader.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* js/dataLoader.js
* Handles loading of data files: films, series, collections, and notifications.
* @module dataLoader
*/
/**
* Fetches all necessary data files: films, series, and collections.
* @returns {Object} An object containing films, series, and collections data.
*/
export async function fetchAllData() {
try {
// Simulate loading delay for better UX
await new Promise(r => setTimeout(r, 800));
// Fetch all data files in parallel for better performance
const [filmsRes, seriesRes, collectionsRes, notifsRes, actorsRes] = await Promise.all([
fetch('data/films.json'),
fetch('data/series.json'),
fetch('data/collections.json'),
fetch('data/notifs.json'),
fetch('data/actors.json'),
]);
// Validate critical data files (films and series are required)
if (!filmsRes.ok || !seriesRes.ok) throw new Error("Erreur de chargement des fichiers JSON (Films/Séries)");
// Parse required data (films and series)
const films = await filmsRes.json();
const series = await seriesRes.json();
// Parse optional data (collections) - gracefully handle missing files
let collections = {};
if (collectionsRes.ok) {
collections = await collectionsRes.json();
} else {
console.warn("Fichier collections.json non trouvé ou vide.");
}
// Parse optional data (notifications)
const notifs = notifsRes.ok ? await notifsRes.json() : [];
if (!notifsRes.ok) {
console.warn("Fichier notifs.json non trouvé ou vide.");
}
// Parse optional data (actors)
let actors = {};
if (actorsRes.ok) {
actors = await actorsRes.json();
} else {
console.warn("Fichier actors.json non trouvé ou vide.");
}
// Return all loaded data
return { films, series, collections, notifs, actors };
} catch (error) {
console.error("Erreur Data Loader:", error);
// Return empty objects as fallback on error
return { films: {}, series: {}, collections: {}, notifs: {}, actors: {} };
}
}</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-dataLoader.html">dataLoader</a></li><li><a href="module-display.html">display</a></li><li><a href="module-errorHandler.html">errorHandler</a></li><li><a href="module-main.html">main</a></li><li><a href="module-utils.html">utils</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Sun Feb 22 2026 09:55:20 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>