1
0

feat: port config store to pinia

This commit is contained in:
Dominik Pschenitschni
2022-09-21 02:21:22 +02:00
parent 9e8c429864
commit a737fc5bc2
21 changed files with 93 additions and 68 deletions

View File

@ -1,14 +1,13 @@
import type { Module } from 'vuex'
import {defineStore, acceptHMRUpdate} from 'pinia'
import {parseURL} from 'ufo'
import {CONFIG} from '../mutation-types'
import {CONFIG} from '../store/mutation-types'
import {HTTPFactory} from '@/http-common'
import {objectToCamelCase} from '@/helpers/case'
import type { RootStoreState, ConfigState } from '@/store/types'
import type {ConfigState} from '@/store/types'
const configStore : Module<ConfigState, RootStoreState> = {
namespaced: true,
state: () => ({
export const useConfigStore = defineStore('config', {
state: (): ConfigState => ({
// These are the api defaults.
version: '',
frontendUrl: '',
@ -45,19 +44,20 @@ const configStore : Module<ConfigState, RootStoreState> = {
return protocol + '//' + host
},
},
mutations: {
[CONFIG](state, config: ConfigState) {
Object.assign(state, config)
},
},
actions: {
async update(ctx) {
[CONFIG](config: ConfigState) {
Object.assign(this, config)
},
async update() {
const HTTP = HTTPFactory()
const {data: config} = await HTTP.get('info')
ctx.commit(CONFIG, objectToCamelCase(config))
this[CONFIG](objectToCamelCase(config))
return config
},
},
}
})
export default configStore
// support hot reloading
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useConfigStore, import.meta.hot))
}