Skip to content

Commit fe9b208

Browse files
authored
Merge pull request #1 from Loopshape/master-komment
Documented 5 functions across 1 file
2 parents 92e8759 + 7cbc91c commit fe9b208

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

app.request.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
/**
2+
* @description loads resources (either CSS or JavaScript) from an array of sources,
3+
* tracking the number of loaded resources and calling a provided callback function
4+
* when all resources have been loaded.
5+
*
6+
* @param { array } sources - list of files to load, including CSS and JavaScript
7+
* files, which are processed by the `loadScript()` and `loadCSS()` functions accordingly.
8+
*
9+
* @param { ‘function’. } callback - function that will be executed once all resources
10+
* have been loaded, indicating that the loading process has finished successfully.
11+
*
12+
* - Type: Function
13+
* - Description: A callback function that is executed when all sources have been
14+
* loaded. It takes no arguments.
15+
*/
116
function loadResources(sources, callback) {
217
let loadedCount = 0;
318
const totalSources = sources.length;
419

20+
/**
21+
* @description loads a script tag in a webpage by creating an HTML element, attaching
22+
* event listeners, and appending it to the body element. When the script is loaded
23+
* or the state is 'complete', the function calls a callback function if present.
24+
*
25+
* @param { string } source - URL or script code of the script to be loaded.
26+
*/
527
function loadScript(source) {
628
const script = document.createElement('script');
729
script.src = source;
@@ -24,6 +46,14 @@ function loadResources(sources, callback) {
2446
document.body.appendChild(script);
2547
}
2648

49+
/**
50+
* @description creates a link element in the HTML document's head, sets its `rel`
51+
* attribute to "stylesheet", and its `href` attribute to the given CSS source. When
52+
* the linked CSS is loaded or errored, the function increments a count variable,
53+
* checks if all sources have been loaded, and calls a callback function if applicable.
54+
*
55+
* @param { string } source - URL of the CSS file to be loaded.
56+
*/
2757
function loadCSS(source) {
2858
const link = document.createElement('link');
2959
link.rel = 'stylesheet';
@@ -59,6 +89,10 @@ function loadResources(sources, callback) {
5989
});
6090
}
6191

92+
/**
93+
* @description imports and executes a JavaScript module named `app.response.js`,
94+
* passing the result to a specified handleFunction or logging an error message if necessary.
95+
*/
6296
function executeAppResponse() {
6397
try {
6498
// Assuming app.response.js is in the same directory
@@ -120,6 +154,16 @@ loadResources(sources, function() {
120154
executeAppResponse();
121155
});
122156

157+
/**
158+
* @description logs the input "result" to the console with a timestamp as the index
159+
* for the multidimensional array.
160+
*
161+
* @param { uncertain or ambiguous data type, as it is not specified or defined within
162+
* the context of the given code snippet. } result - value that is stored at the
163+
* current time stamp in a multidimensional array.
164+
*
165+
* - Timestamp: A new date-time stamp in milliseconds, captured using `new Date().getTime()`.
166+
*/
123167
function handleResult(result) {
124168
// Assuming you want to store the result in a multidimensional array with timestamp as index
125169
const timestamp = new Date().getTime();

0 commit comments

Comments
 (0)