I developed an application that utilizes LocalStorage to store data.
The issue I encountered was storing a large number of objects under a single key, causing the DOM to become blocked. This is due to the necessity of parsing and stringifying the JSON data every time there is a read or write operation on the "database."
As stated in a response on a different question:
LocalStorage and JSON stringify/parse operations happen synchronously on the main thread, which can slow down the app and lead to a delay in DOM rendering.
The data insertion function in the code snippet looks like this:
$scope.recordlist = extractRecordJSONFromLocalStorage();
$scope.addRecord = function () {
$scope.recordlist.push(
{
date: $scope.dateJson,
time: $scope.time,
car: $scope.carList.code,
driver: $scope.driverList.name,
from: $scope.locationList.place,
destination: $scope.locationList2.place,
pax: $scope.paxList,
comments: [],
arrival: '',
inserted: '',
cancelled:'',
duration:''
}
);
jsonToRecordLocalStorage($scope.recordlist);
};
Given these limitations, I need to rethink my approach to storing and retrieving data.
The current method made sense to me, as I relied on AngularJS to work with and compare the objects stored under a single key.
<div class="row msf-row"
ng-repeat="record in filteredRecords = (recordlist | filter:dateFilter | filter: search )"
ng-hide="is.cancelled && (!record.cancelled || record.cancelled === '') || has.comment && (!record.comment || record.comment === '')"
ng-class="{ 'msf-cancelled': record.cancelled, 'msf-commented' : record.comment}"
ng-hide="!record.arrival && !record.cancelled"
ng-show="record.cancelled">
Any suggestions on how I can migrate to a more efficient system while retaining the AngularJS functionality?
I aim to avoid reading the entire file each time and still be able to filter records effectively. Any guidance on this matter, such as recommended documentation or theories, would be greatly appreciated.
You can view a live demo of the application here.
I acknowledge that there are key concepts related to data storage and retrieval that I may be overlooking. Any resources or advice on this topic would be invaluable.