diff options
Diffstat (limited to 'viewer/src/store')
-rw-r--r-- | viewer/src/store/galleryStore.ts | 21 | ||||
-rw-r--r-- | viewer/src/store/index.ts | 27 |
2 files changed, 48 insertions, 0 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts new file mode 100644 index 0000000..63e5109 --- /dev/null +++ b/viewer/src/store/galleryStore.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import { createModule, mutation, action } from "vuex-class-component"; | ||
2 | |||
3 | const VuexModule = createModule({ | ||
4 | namespaced: "galleryStore", | ||
5 | strict: true | ||
6 | }) | ||
7 | |||
8 | export default class GalleryStore extends VuexModule { | ||
9 | |||
10 | galleryItems: Gallery.Item[] = []; | ||
11 | |||
12 | @mutation setGalleryItems(galleryItems: Gallery.Item[]) { | ||
13 | this.galleryItems = galleryItems; | ||
14 | } | ||
15 | |||
16 | @action async fetchGalleryItems(url: string) { | ||
17 | fetch(url) | ||
18 | .then(response => response.json()) | ||
19 | .then(this.setGalleryItems); | ||
20 | } | ||
21 | } \ No newline at end of file | ||
diff --git a/viewer/src/store/index.ts b/viewer/src/store/index.ts new file mode 100644 index 0000000..cadd8e3 --- /dev/null +++ b/viewer/src/store/index.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import Vue from 'vue' | ||
2 | import Vuex from 'vuex' | ||
3 | import { extractVuexModule } from "vuex-class-component"; | ||
4 | import { createProxy } from "vuex-class-component"; | ||
5 | import UIStore from '@/store/uiStore'; | ||
6 | import GalleryStore from '@/store/galleryStore'; | ||
7 | |||
8 | Vue.use(Vuex) | ||
9 | |||
10 | const store = new Vuex.Store({ | ||
11 | modules: { | ||
12 | ...extractVuexModule(UIStore), | ||
13 | ...extractVuexModule(GalleryStore) | ||
14 | } | ||
15 | }); | ||
16 | |||
17 | Vue.use((vue) => vue.prototype.$uiStore = createProxy(store, UIStore)); | ||
18 | Vue.use((vue) => vue.prototype.$galleryStore = createProxy(store, GalleryStore)); | ||
19 | |||
20 | declare module 'vue/types/vue' { | ||
21 | interface Vue { | ||
22 | $uiStore: UIStore, | ||
23 | $galleryStore: GalleryStore | ||
24 | } | ||
25 | } | ||
26 | |||
27 | export default store; | ||