feat: improve store typing

This commit is contained in:
Dominik Pschenitschni 2022-07-21 18:45:58 +02:00
parent a6b96f857d
commit 244478400a
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
60 changed files with 239 additions and 192 deletions

View file

@ -1,26 +1,29 @@
import type { Module } from 'vuex'
import {findIndexById} from '@/helpers/utils'
import type { AttachmentState } from '@/store/types'
import type { AttachmentState, RootStoreState } from '@/store/types'
import type { IAttachment } from '@/models/attachment'
export default {
const store : Module<AttachmentState, RootStoreState> = {
namespaced: true,
state: (): AttachmentState => ({
state: () => ({
attachments: [],
}),
mutations: {
set(state: AttachmentState, attachments: IAttachment[]) {
set(state, attachments: IAttachment[]) {
console.debug('Set attachments', attachments)
state.attachments = attachments
},
add(state: AttachmentState, attachment: IAttachment) {
add(state, attachment: IAttachment) {
console.debug('Add attachement', attachment)
state.attachments.push(attachment)
},
removeById(state: AttachmentState, id: IAttachment['id']) {
removeById(state, id: IAttachment['id']) {
const attachmentIndex = findIndexById<IAttachment>(state.attachments, id)
state.attachments.splice(attachmentIndex, 1)
console.debug('Remove attachement', id)
},
},
}
}
export default store