forked from MapComplete/MapComplete
Performance: sprinkle 'onDestroy' everywhere to cleanup old stores; cleanup 'Stores' utility class
This commit is contained in:
parent
66f093afd8
commit
81be4db044
79 changed files with 332 additions and 325 deletions
|
|
@ -6,7 +6,7 @@ import WayImportButtonViz from "../Popup/ImportButtons/WayImportButtonViz"
|
|||
import ConflateImportButtonViz from "../Popup/ImportButtons/ConflateImportButtonViz"
|
||||
import { PlantNetDetectionViz } from "../Popup/PlantNetDetectionViz"
|
||||
import Constants from "../../Models/Constants"
|
||||
import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { Feature, GeoJsonProperties } from "geojson"
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
|
|
@ -170,50 +170,46 @@ class LinkedDataFromWebsite extends SpecialVisualization {
|
|||
}
|
||||
const country = countryStore.data
|
||||
if (url.startsWith("https://data.velopark.be/")) {
|
||||
return Stores.FromPromiseWithErr(
|
||||
(async () => {
|
||||
try {
|
||||
const loadAll = layer.id.toLowerCase().indexOf("maproulette") >= 0 // Dirty hack
|
||||
const features = await LinkedDataLoader.fetchVeloparkEntry(
|
||||
url,
|
||||
loadAll
|
||||
)
|
||||
const feature =
|
||||
features.find((f) => f.properties["ref:velopark"] === url) ??
|
||||
features[0]
|
||||
const properties = feature.properties
|
||||
properties["ref:velopark"] = url
|
||||
console.log("Got properties from velopark:", properties)
|
||||
return properties
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
})()
|
||||
)
|
||||
return UIEventSource.fromPromiseWithErr((async () => {
|
||||
try {
|
||||
const loadAll = layer.id.toLowerCase().indexOf("maproulette") >= 0 // Dirty hack
|
||||
const features = await LinkedDataLoader.fetchVeloparkEntry(
|
||||
url,
|
||||
loadAll
|
||||
)
|
||||
const feature =
|
||||
features.find((f) => f.properties["ref:velopark"] === url) ??
|
||||
features[0]
|
||||
const properties = feature.properties
|
||||
properties["ref:velopark"] = url
|
||||
console.log("Got properties from velopark:", properties)
|
||||
return properties
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
})())
|
||||
}
|
||||
if (country === undefined) {
|
||||
return undefined
|
||||
}
|
||||
return Stores.FromPromiseWithErr(
|
||||
(async () => {
|
||||
try {
|
||||
return await LinkedDataLoader.fetchJsonLd(
|
||||
url,
|
||||
{ country },
|
||||
useProxy ? "proxy" : "fetch-lod"
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(
|
||||
"Could not get with proxy/download LOD, attempting to download directly. Error for ",
|
||||
url,
|
||||
"is",
|
||||
e
|
||||
)
|
||||
return await LinkedDataLoader.fetchJsonLd(url, { country }, "fetch-raw")
|
||||
}
|
||||
})()
|
||||
)
|
||||
return UIEventSource.fromPromiseWithErr((async () => {
|
||||
try {
|
||||
return await LinkedDataLoader.fetchJsonLd(
|
||||
url,
|
||||
{ country },
|
||||
useProxy ? "proxy" : "fetch-lod"
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(
|
||||
"Could not get with proxy/download LOD, attempting to download directly. Error for ",
|
||||
url,
|
||||
"is",
|
||||
e
|
||||
)
|
||||
return await LinkedDataLoader.fetchJsonLd(url, { country }, "fetch-raw")
|
||||
}
|
||||
})())
|
||||
},
|
||||
[countryStore, downloadInformation]
|
||||
)
|
||||
|
|
@ -271,7 +267,7 @@ class CompareData extends SpecialVisualization {
|
|||
): BaseUIElement {
|
||||
const url = args[0]
|
||||
const readonly = args[3] === "yes"
|
||||
const externalData = Stores.FromPromiseWithErr(Utils.downloadJson(url))
|
||||
const externalData = UIEventSource.fromPromiseWithErr(Utils.downloadJson(url))
|
||||
return new SvelteUIElement(ComparisonTool, {
|
||||
url,
|
||||
state,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue