forked from MapComplete/MapComplete
Huge refactoring: split readonly and writable stores
This commit is contained in:
parent
0946d8ac9c
commit
4283b76f36
95 changed files with 819 additions and 625 deletions
|
@ -182,7 +182,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
features.push(newGeometry)
|
||||
|
||||
}
|
||||
return new StaticFeatureSource(features, false)
|
||||
return StaticFeatureSource.fromGeojson(features)
|
||||
}
|
||||
|
||||
public async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
|
||||
|
|
|
@ -159,7 +159,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction {
|
|||
})
|
||||
|
||||
|
||||
return new StaticFeatureSource(Utils.NoNull(preview), false)
|
||||
return StaticFeatureSource.fromGeojson(Utils.NoNull(preview))
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ export class Changes {
|
|||
const successes = await Promise.all(Array.from(pendingPerTheme,
|
||||
async ([theme, pendingChanges]) => {
|
||||
try {
|
||||
const openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).map(
|
||||
const openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).sync(
|
||||
str => {
|
||||
const n = Number(str);
|
||||
if (isNaN(n)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import osmAuth from "osm-auth";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import {Stores, UIEventSource} from "../UIEventSource";
|
||||
import {OsmPreferences} from "./OsmPreferences";
|
||||
import {ChangesetHandler} from "./ChangesetHandler";
|
||||
import {ElementStorage} from "../ElementStorage";
|
||||
|
@ -228,7 +228,7 @@ export class OsmConnection {
|
|||
}
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually closing note ", id, " with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
return new Promise((ok) => {
|
||||
ok()
|
||||
});
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ export class OsmConnection {
|
|||
this.auth.xhr({
|
||||
method: 'POST',
|
||||
path: `/api/0.6/notes/${id}/close${textSuffix}`,
|
||||
}, function (err, response) {
|
||||
}, function (err, _) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
} else {
|
||||
|
@ -251,7 +251,7 @@ export class OsmConnection {
|
|||
public reopenNote(id: number | string, text?: string): Promise<void> {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually reopening note ", id, " with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
return new Promise((ok) => {
|
||||
ok()
|
||||
});
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ export class OsmConnection {
|
|||
this.auth.xhr({
|
||||
method: 'POST',
|
||||
path: `/api/0.6/notes/${id}/reopen${textSuffix}`
|
||||
}, function (err, response) {
|
||||
}, function (err, _) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
} else {
|
||||
|
@ -278,7 +278,7 @@ export class OsmConnection {
|
|||
public openNote(lat: number, lon: number, text: string): Promise<{ id: number }> {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually opening note with text ", text)
|
||||
return new Promise<{ id: number }>((ok, error) => {
|
||||
return new Promise<{ id: number }>((ok) => {
|
||||
window.setTimeout(() => ok({id: Math.floor(Math.random() * 1000)}), Math.random() * 5000)
|
||||
});
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ export class OsmConnection {
|
|||
public addCommentToNode(id: number | string, text: string): Promise<void> {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually adding comment ", text, "to note ", id)
|
||||
return new Promise((ok, error) => {
|
||||
return new Promise((ok) => {
|
||||
ok()
|
||||
});
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ export class OsmConnection {
|
|||
method: 'POST',
|
||||
|
||||
path: `/api/0.6/notes/${id}/comment?text=${encodeURIComponent(text)}`
|
||||
}, function (err, response) {
|
||||
}, function (err, _) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
} else {
|
||||
|
@ -374,7 +374,7 @@ export class OsmConnection {
|
|||
return;
|
||||
}
|
||||
this.isChecking = true;
|
||||
UIEventSource.Chronic(5 * 60 * 1000).addCallback(_ => {
|
||||
Stores.Chronic(5 * 60 * 1000).addCallback(_ => {
|
||||
if (self.isLoggedIn.data) {
|
||||
console.log("Checking for messages")
|
||||
self.AttemptLogin();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {Utils} from "../../Utils";
|
||||
import * as polygon_features from "../../assets/polygon-features.json";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import {Store, Stores, UIEventSource} from "../UIEventSource";
|
||||
import {BBox} from "../BBox";
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ export abstract class OsmObject {
|
|||
this.backendURL = url;
|
||||
}
|
||||
|
||||
public static DownloadObject(id: string, forceRefresh: boolean = false): UIEventSource<OsmObject> {
|
||||
public static DownloadObject(id: string, forceRefresh: boolean = false): Store<OsmObject> {
|
||||
let src: UIEventSource<OsmObject>;
|
||||
if (OsmObject.objectCache.has(id)) {
|
||||
src = OsmObject.objectCache.get(id)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {TagsFilter} from "../Tags/TagsFilter";
|
||||
import RelationsTracker from "./RelationsTracker";
|
||||
import {Utils} from "../../Utils";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import {ImmutableStore, Store} from "../UIEventSource";
|
||||
import {BBox} from "../BBox";
|
||||
import * as osmtogeojson from "osmtogeojson";
|
||||
import {FeatureCollection} from "@turf/turf";
|
||||
|
@ -12,7 +12,7 @@ import {FeatureCollection} from "@turf/turf";
|
|||
export class Overpass {
|
||||
private _filter: TagsFilter
|
||||
private readonly _interpreterUrl: string;
|
||||
private readonly _timeout: UIEventSource<number>;
|
||||
private readonly _timeout: Store<number>;
|
||||
private readonly _extraScripts: string[];
|
||||
private _includeMeta: boolean;
|
||||
private _relationTracker: RelationsTracker;
|
||||
|
@ -20,10 +20,10 @@ export class Overpass {
|
|||
constructor(filter: TagsFilter,
|
||||
extraScripts: string[],
|
||||
interpreterUrl: string,
|
||||
timeout?: UIEventSource<number>,
|
||||
timeout?: Store<number>,
|
||||
relationTracker?: RelationsTracker,
|
||||
includeMeta = true) {
|
||||
this._timeout = timeout ?? new UIEventSource<number>(90);
|
||||
this._timeout = timeout ?? new ImmutableStore<number>(90);
|
||||
this._interpreterUrl = interpreterUrl;
|
||||
const optimized = filter.optimize()
|
||||
if(optimized === true || optimized === false){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue