import {ormState} from '~/types/interfaces' import {defineStore} from "pinia"; import ApiResource from "~/models/ApiResource"; export const useOrmStore = defineStore('orm', { state: (): ormState => { return { /** * Store the initial value of the entities, just after the fetch, to make reinitialization possible */ initialValues: new Map>() } }, actions: { storeInitialValue(model: typeof ApiResource, entity: ApiResource) { if (!this.initialValues.has(model.entity)) { this.initialValues.set(model.entity, new Map()) } // @ts-ignore this.initialValues.get(model.entity).set(entity.id, useCloneDeep(entity)) // TODO: voir si structuredClone est compatible avec les navigateurs supportés, et si ça vaut le coup // de l'utiliser à la place du clonedeep de lodash // >> https://developer.mozilla.org/en-US/docs/Web/API/structuredClone } } })