mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2025-09-10 08:27:20 +00:00
move localStorage util to localStorage.js,
update main,js to rquire localStroage, add simple unit tests to localStroage.test.js, create symlink of testenv.js to source/assets/scripts, update package.json with proper recursive call Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// main.js
|
||||
const {getReviewsFromStorage, saveReviewsToStorage} = require('./localStorage');
|
||||
|
||||
// Run the init() function when the page has loaded
|
||||
window.addEventListener('DOMContentLoaded', init);
|
||||
@@ -12,17 +13,6 @@ function init() {
|
||||
initFormHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Array<Object>} An array of reviews found in localStorage
|
||||
*/
|
||||
function getReviewsFromStorage() {
|
||||
let result = JSON.parse(localStorage.getItem('reviews'))
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return new Array(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<Object>} reviews An array of reviews
|
||||
*/
|
||||
@@ -36,15 +26,6 @@ function addReviewsToDocument(reviews) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes in an array of reviews, converts it to a string, and then
|
||||
* saves that string to 'reviews' in localStorage
|
||||
* @param {Array<Object>} reviews An array of reviews
|
||||
*/
|
||||
function saveReviewsToStorage(reviews) {
|
||||
localStorage.setItem('reviews', JSON.stringify(reviews));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the necesarry event handlers to <form> and the clear storage
|
||||
* <button>.
|
||||
|
Reference in New Issue
Block a user