-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
markwhenStore.ts
49 lines (41 loc) · 1.39 KB
/
markwhenStore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { parse } from "@markwhen/parser";
import { Cache } from "@markwhen/parser/lib/Cache";
import { defineStore } from "pinia";
import { computed, reactive, ref, shallowReactive, type Ref } from "vue";
import type { Timeline } from "@markwhen/parser/lib/Types";
import { useParserWorker } from "./composables/useParserWorker";
import { exampleTimeline } from "@/exampleTimeline";
export const useMarkwhenStore = defineStore("markwhen", () => {
const rawTimelineString = ref<string>(exampleTimeline);
// const cache = reactive(new Cache());
// const timelines = computed(
// () => parse(rawTimelineString.value, cache).timelines
// );
const useWorker = false;
// console.log("using worker", useWorker);
let timelines: Ref<Timeline[]>;
const cache = shallowReactive(new Cache());
if (useWorker) {
timelines = useParserWorker(rawTimelineString).timelines;
timelines.value = parse(rawTimelineString.value, cache).timelines;
} else {
timelines = computed(() => {
// const start = performance.now();
const r = parse(rawTimelineString.value, cache).timelines;
// console.log("normal", performance.now() - start);
return r;
});
}
const setRawTimelineString = (s: string) => {
rawTimelineString.value = s;
};
return {
// state
rawTimelineString,
cache,
// getters
timelines,
// actions
setRawTimelineString,
};
});