forked from MapComplete/MapComplete
Stabilize longPreferences
This commit is contained in:
parent
94dcf57d41
commit
254098a7e5
1 changed files with 19 additions and 14 deletions
|
@ -76,9 +76,9 @@ export class OsmPreferences {
|
||||||
|
|
||||||
|
|
||||||
function updateData(l: number) {
|
function updateData(l: number) {
|
||||||
if (l === undefined) {
|
if(Object.keys(self.preferences.data).length === 0){
|
||||||
source.setData(undefined);
|
// The preferences are still empty - they are not yet updated, so we delay updating for now
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
const prefsCount = Number(l);
|
const prefsCount = Number(l);
|
||||||
if (prefsCount > 100) {
|
if (prefsCount > 100) {
|
||||||
|
@ -86,7 +86,11 @@ export class OsmPreferences {
|
||||||
}
|
}
|
||||||
let str = "";
|
let str = "";
|
||||||
for (let i = 0; i < prefsCount; i++) {
|
for (let i = 0; i < prefsCount; i++) {
|
||||||
str += self.GetPreference(allStartWith + "-" + i, "").data;
|
const key = allStartWith + "-" + i
|
||||||
|
if(self.preferences.data[key] === undefined){
|
||||||
|
console.warn("Detected a broken combined preference:", key, "is undefined", self.preferences)
|
||||||
|
}
|
||||||
|
str += self.preferences.data[key] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
source.setData(str);
|
source.setData(str);
|
||||||
|
@ -95,7 +99,9 @@ export class OsmPreferences {
|
||||||
length.addCallback(l => {
|
length.addCallback(l => {
|
||||||
updateData(Number(l));
|
updateData(Number(l));
|
||||||
});
|
});
|
||||||
|
this.preferences.addCallbackAndRun(_ => {
|
||||||
updateData(Number(length.data));
|
updateData(Number(length.data));
|
||||||
|
})
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +133,8 @@ export class OsmPreferences {
|
||||||
public ClearPreferences() {
|
public ClearPreferences() {
|
||||||
let isRunning = false;
|
let isRunning = false;
|
||||||
const self = this;
|
const self = this;
|
||||||
this.preferences.addCallbackAndRun(prefs => {
|
this.preferences.addCallback(prefs => {
|
||||||
|
console.log("Cleaning preferences...")
|
||||||
if (Object.keys(prefs).length == 0) {
|
if (Object.keys(prefs).length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -135,19 +142,17 @@ export class OsmPreferences {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isRunning = true
|
isRunning = true
|
||||||
const prefixes = ["mapcomplete-installed-theme", "mapcomplete-installed-themes-", "mapcomplete-current-open-changeset", "mapcomplete-personal-theme-layer"]
|
const prefixes = ["mapcomplete-"]
|
||||||
for (const key in prefs) {
|
for (const key in prefs) {
|
||||||
for (const prefix of prefixes) {
|
const matches = prefixes.some(prefix => key.startsWith(prefix))
|
||||||
if (key.startsWith(prefix)) {
|
if (matches) {
|
||||||
console.log("Clearing ", key)
|
console.log("Clearing ", key)
|
||||||
self.GetPreference(key, "").setData("")
|
self.GetPreference(key, "").setData("")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
return true;
|
return;
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue