import Vue from 'vue' ; import Vuex , { MutationTree , ActionTree , ModuleTree , GetterTree } from 'vuex' ; import storage from '../modules/storage' ; import preference , { register as preferenceRegister } from './modules/preference' ; import translation , { register as translationRegister } from './modules/translation' ; import template , { register as templateRegister } from './modules/template' ; import { update , clear } from '@/stores/mutations' ; import { locale , theme } from '@/stores/getters' ; import { ipcActionRequestor } from '@/stores/' ; Vue . use ( Vuex ) ; const register = [ ... Object . keys ( preferenceRegister ) , ... Object . keys ( translationRegister ) , ... Object . keys ( templateRegister ) , ] as Array < keyof DefaultConfig > ; let Port ; const state = { notify : null , } ; const mutations = { update , clear } ; const actions = { init : ( { state , dispatch , rootState } , { port } ) => { Port = port ; dispatch ( 'storage/init' , { page : 'popup' , keys : register } ) ; } , ipc : async ( _ , action ) => ipcActionRequestor ( Port , action ) , notify : ( { commit } , message ) => commit ( 'update' , { notify : message || null } ) , } ; const getters = { locale , theme , } ; const modules = { storage , preference , translation , template , } ; const store = new Vuex . Store < State > ( { state , actions , mutations , getters , modules , } ) ; store . subscribe ( ( mutation ) => { if ( mutation . type === 'storage/update' ) { store . dispatch ( 'preference/fetch' ) ; store . dispatch ( 'translation/fetch' ) ; store . dispatch ( 'template/fetch' ) ; } } ) ; export default store ; export interface State { notify : null | string ; [ m ] : any ; }