Use addCallbackAndRunD

This commit is contained in:
pietervdvn 2021-06-30 16:02:46 +02:00
parent 8d9a992507
commit ba04beab2c
4 changed files with 5 additions and 12 deletions

View file

@ -16,11 +16,7 @@ export default class LocalStorageSaver implements FeatureSource {
constructor(source: FeatureSource, layout: UIEventSource<LayoutConfig>) {
this.features = source.features;
this.features.addCallbackAndRun(features => {
if (features === undefined) {
return;
}
this.features.addCallbackAndRunD(features => {
const now = new Date().getTime()
features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000)

View file

@ -11,8 +11,6 @@ export default class LocalStorageSource implements FeatureSource {
this.features = new UIEventSource<{ feature: any; freshness: Date }[]>([])
const key = LocalStorageSaver.storageKey + layout.data.id
layout.addCallbackAndRun(_ => {
try {
const fromStorage = localStorage.getItem(key);
if (fromStorage == null) {

View file

@ -3,7 +3,6 @@ import {UIEventSource} from "../UIEventSource";
import {OsmObject} from "../Osm/OsmObject";
import State from "../../State";
import {Utils} from "../../Utils";
import Loc from "../../Models/Loc";
export default class OsmApiFeatureSource implements FeatureSource {
@ -21,10 +20,10 @@ export default class OsmApiFeatureSource implements FeatureSource {
return;
}
console.debug("Downloading", id, "from the OSM-API")
OsmObject.DownloadObject(id, (element, meta) => {
OsmObject.DownloadObject(id).addCallbackAndRunD(element => {
const geojson = element.asGeoJson();
geojson.id = geojson.properties.id;
this.features.setData([{feature: geojson, freshness: meta["_last_edit:timestamp"]}])
this.features.setData([{feature: geojson, freshness: element.timestamp}])
})
}

View file

@ -9,8 +9,8 @@ export default class RegisteringFeatureSource implements FeatureSource {
constructor(source: FeatureSource) {
this.features = source.features;
this.name = "RegisteringSource of " + source.name;
this.features.addCallbackAndRun(features => {
for (const feature of features ?? []) {
this.features.addCallbackAndRunD(features => {
for (const feature of features) {
State.state.allElements.addOrGetElement(feature.feature)
}
})