feat: improve store and model typing

This commit is contained in:
Dominik Pschenitschni 2022-07-21 00:42:36 +02:00
parent c9e85cb52b
commit 3766b5e51b
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
98 changed files with 1050 additions and 507 deletions

View file

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