Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Clean up store
Browse files Browse the repository at this point in the history
  • Loading branch information
alkaitagi committed Feb 9, 2021
1 parent 4e65cde commit f0165fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
9 changes: 4 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script lang="ts">
import { watchEffect, defineComponent } from "vue";
import { useRoute, useRouter } from "vue-router";
import { setupStore } from "./store";
import { lects } from "./store";
import "./Phonology/main";
import "./Converter/main";
Expand All @@ -23,10 +23,9 @@ export default defineComponent({
: { name: "Home" }
);
}
if (route.name !== "Home") {
const lects = JSON.parse(localStorage.lects ?? "[]");
setupStore(lects);
}
if (route.name !== "Home")
lects.value = JSON.parse(localStorage.lects ?? "[]");
watchEffect(() => {
if (route.name) localStorage.url = route.path;
});
Expand Down
4 changes: 2 additions & 2 deletions src/Home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
defineComponent,
} from "vue";
import { useRouter } from "vue-router";
import { setupStore } from "@/store";
import { lects } from "@/store";
import { reset, catalogue, search, query } from "./main";
import { createMap } from "./map";
Expand All @@ -85,7 +85,7 @@ export default defineComponent({
else search.selected.add(name);
}
function load() {
setupStore([...search.selected]);
lects.value = [...search.selected];
router.push({ name: "Phonology" });
}
Expand Down
14 changes: 0 additions & 14 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { ref } from "vue";

let key: symbol;
export const lects = ref<string[]>([]);
export const root =
process.env.VUE_APP_STORE === "local"
? "/store/"
: "https://raw.githubusercontent.com/alkaitagi/Avzag/store/";

export function setupStore(_lects: string[]) {
lects.value = _lects;
key = Symbol("lects");
}
export function getInitializer(callback: () => Promise<unknown>) {
let _key: symbol;
return async () => {
if (_key === key) return;
_key = key;
await callback();
};
}

export async function loadJSON(filename: string, defaultValue?: unknown) {
return await fetch(root + filename + ".json")
.then((r) => r.json())
Expand Down

0 comments on commit f0165fb

Please sign in to comment.