Files
better-mreso/app/stores/mreso.ts
T
2026-07-06 19:49:28 +02:00

45 lines
1.4 KiB
TypeScript

import type {
Feature,
FeatureCollection,
MultiLineString,
Point,
} from "geojson";
export const useMresoStore = defineStore("mresoStore", {
state: () => ({
routes: [] as Route[],
lines: {} as FeatureCollection<MultiLineString>,
clusters: {} as FeatureCollection<Point>,
stops: {} as FeatureCollection<Point>,
}),
actions: {
async fetchData(options: { signal?: AbortSignal } = {}) {
[this.routes, this.lines, this.clusters, this.stops] = await Promise.all([
$fetch<Route[]>("/routes.json", options),
$fetch<FeatureCollection<MultiLineString>>("/lines.json", options),
$fetch<FeatureCollection<Point>>("/clusters.json", options),
$fetch<FeatureCollection<Point>>("/stops.json", options),
]);
this.lines = await $fetch("/lines.json", options);
this.clusters = await $fetch("/clusters.json", options);
this.stops = await $fetch("/stops.json", options);
},
},
getters: {
routesById(state): { [id: string]: Route } {
return Object.fromEntries(state.routes.map((r) => [r.id, r]));
},
linesById(state): { [id: string]: Feature<MultiLineString> } {
return Object.fromEntries(
state.lines.features.map((l) => [l.properties!.id, l]),
);
},
clustersById(state): { [id: string]: Feature<Point> } {
return Object.fromEntries(
state.clusters.features.map((l) => [l.properties!.id, l]),
);
},
},
});