Add caching into local storage for a faster map experience

This commit is contained in:
Pieter Vander Vennet 2021-01-15 00:29:07 +01:00
parent 3a2d654ac3
commit f33fe081d0
12 changed files with 128 additions and 41 deletions

View file

@ -0,0 +1,22 @@
import FeatureSource from "./FeatureSource";
import {UIEventSource} from "../UIEventSource";
import LocalStorageSaver from "./LocalStorageSaver";
export default class LocalStorageSource implements FeatureSource {
public features: UIEventSource<{ feature: any; freshness: Date }[]>;
constructor() {
this.features = new UIEventSource<{ feature: any; freshness: Date }[]>([])
try {
const fromStorage = localStorage.getItem(LocalStorageSaver.storageKey);
if (fromStorage == null) {
return;
}
const loaded = JSON.parse(fromStorage);
this.features.setData(loaded);
} catch (e) {
console.log("Could not load features from localStorage:", e)
}
}
}