import generator , { Entity } from 'megalodon' ; import { Module , MutationTree , ActionTree } from 'vuex' ; import { RootState } from '@/store' ; export type IndexState = { lists : Array < Entity . List > ; } ; const state = ( ) : IndexState => ( { lists : [ ] } ) ; export const MUTATION_TYPES = { CHANGE_LISTS : 'changeLists' } ; const mutations = { [ MUTATION_TYPES . CHANGE_LISTS ] : ( state , lists ) => { state . lists = lists ; } } ; const actions = { fetchLists : async ( { commit , rootState } ) : Promise < Array < Entity . List > > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . getLists ( ) ; commit ( MUTATION_TYPES . CHANGE_LISTS , res . data ) ; return res . data ; } , createList : async ( { rootState } , title ) : Promise < Entity . List > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . createList ( title ) ; return res . data ; } , deleteList : async ( { dispatch , rootState } , list ) => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . deleteList ( list . id ) ; dispatch ( 'fetchLists' ) ; return res . data ; } } ; export default { namespaced : true , state : state , mutations : mutations , actions : actions } as Module < IndexState , RootState > ;