import { InjectionKey } from 'vue' ; import { createStore , GetterTree , MutationTree , Store , Store as VuexStore , useStore as vuexUseStore , } from 'vuex' ; import invoices_quotations from './invoices_quotations' ; import { InvoiceQuotationStateInterface } from './invoices_quotations/state' ; import { store } from 'quasar/wrappers' ; export interface StateInterface { invoices_quotations : InvoiceQuotationStateInterface ; } declare module '@vue/runtime-core' { interface ComponentCustomProperties { $store : VuexStore < StateInterface > ; } } declare module 'vuex' { interface Store < S > { provide < T > ( name , service ) : void ; inject < T > ( name ) : T | undefined ; } } export const storeKey = Symbol ( 'vuex-key' ) ; export interface RootState { apiProtocol : string ; apiHost : string ; } export interface StoreRootInterface { strict ? : boolean ; state ? : RootState ; modules ? : StateInterface ; getters ? : GetterTree < RootState , StateInterface > ; mutations ? : MutationTree < RootState > ; } export type StoreState = RootState & StateInterface ; let vuexStore ; export default store ( function ( ) { vuexStore = createStore < StoreState > ( { getters : { getRootURL : ( ) => { let host ; let port ; if ( process . env . DEV ) { host = process . env . DEV_API_SERVER_HOST ?? '' ; port = Number ( process . env . DEV_API_SERVER_PORT ) ; } else { host = process . env . PROD_API_SERVER_HOST ?? '' ; port = Number ( process . env . PROD_API_SERVER_PORT ) ; } return `http://${ host }:${ port }/` ; } , } , modules : { invoices_quotations , } , strict : ! ! process . env . DEBUGGING , } ) ; const dependencies = { } ; vuexStore . provide = function < T > ( name , service ) { dependencies [ name ] = service ; } ; vuexStore . inject = function < T > ( name ) { if ( name in dependencies ) { const service = dependencies [ name ] ; return service as T ; } } ; return vuexStore ; } ) ; export function useStore ( ) { return vuexUseStore ( storeKey ) ; } export { vuexStore } ;