mroberge/HydroCloud

Screen out requests if they've already occurred.

Closed this issue · 4 comments

Save data locally, and use this data instead of loading the data again.
Right now if you click on the same point twice, it will get added to the table twice, and it will download the data twice too.

The Web Storage API with examples.
The basic localStorage object

Detect if localStorage is available: (source)

function storageAvailable(type) {
	try {
		var storage = window[type],
			x = '__storage_test__';
		storage.setItem(x, x);
		storage.removeItem(x);
		return true;
	}
	catch(e) {
		return false;
	}
}

Use this function like this:

if (storageAvailable('localStorage')) {
	// Yippee! We can use localStorage awesomeness
}
else {
	// Too bad, no localStorage for us
}

Whenever a new site is requested, so something like this:

if(!localStorage.getItem(site-id)) {
    requestData();
    saveToStorage();
    useStorageData();
} else {
    useStorageData();
}

This feature was implemented with commit 68da117 .