forked from MapComplete/MapComplete
Add caching into local storage for a faster map experience
This commit is contained in:
parent
3a2d654ac3
commit
f33fe081d0
12 changed files with 128 additions and 41 deletions
22
Logic/FeatureSource/LocalStorageSource.ts
Normal file
22
Logic/FeatureSource/LocalStorageSource.ts
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue