Add store

This commit is contained in:
2020-09-15 15:16:55 +03:00
parent 57812be1fd
commit 5d33377a50
10 changed files with 108 additions and 16 deletions

View File

@@ -0,0 +1,15 @@
import { Actions } from 'vuex-smart-module';
import Vue from 'vue';
import { AxiosResponse, AxiosError } from 'axios';
import AlbumsState from './state';
import AlbumsGetters from './getters';
import AlbumsMutations from './muttations';
export default class AlbumsActions extends Actions<
AlbumsState,
AlbumsGetters,
AlbumsMutations,
AlbumsActions
> {
}

View File

@@ -0,0 +1,6 @@
import { Getters } from 'vuex-smart-module';
import AlbumsState from './state';
export default class AlbumsGetters extends Getters<AlbumsState> {
}

15
src/store/albums/index.ts Normal file
View File

@@ -0,0 +1,15 @@
import { Module } from 'vuex-smart-module';
import AlbumsState from './state';
import AlbumsGetters from './getters';
import AlbumsMutations from './muttations';
import AlbumsActions from './actions';
const authModule = new Module({
state: AlbumsState,
getters: AlbumsGetters,
mutations: AlbumsMutations,
actions: AlbumsActions,
});
export default authModule;

View File

@@ -0,0 +1,8 @@
import { Mutations } from 'vuex-smart-module';
import AlbumsState, { IAlbum } from './state';
export default class AlbumsMutations extends Mutations<AlbumsState> {
updateAlbums(albumsData: IAlbum[]) {
this.state.albums = albumsData;
}
}

12
src/store/albums/state.ts Normal file
View File

@@ -0,0 +1,12 @@
export interface IAlbum {
name: string;
description: string;
protected: boolean;
folderName: string;
files: string[];
}
export default class AlbumsState {
albums: IAlbum[] | null = null;
}

30
src/store/index.ts Normal file
View File

@@ -0,0 +1,30 @@
import Vue from 'vue';
import * as Vuex from 'vuex';
import { createStore, Module } from 'vuex-smart-module';
import { Store } from 'vuex';
import albums from './albums';
import albumsState from './albums/state';
Vue.use(Vuex);
interface IStore {
albums: albumsState
}
export type StoreType = Store<IStore>;
const store: StoreType = createStore(
new Module({
modules: {
albums,
}
}),
{
strict: process.env.NODE_ENV !== 'production',
}
)
export default store;