import type { Store } from 'pinia'; import { isRef, type Ref, ref, unref } from 'vue'; import type { Patch, StoreInstance } from '../types/createDatalistStore.types'; /** * the applyStorePatch method is used to repeat the logic of the $patch method from pinia for the composable stores * */ export const applyStorePatch = ( store: StoreBody | Store, patch: Patch, ) => { for (const key of Object.keys(patch)) { const value = patch[key]; const target = store[key]; if (isRef(target)) { (target as Ref).value = isRef(value) ? unref(value) : value; } else { (store as Record)[key] = isRef(value) ? value : ref(value); } } };