feat: refs #6943 updateAndEmit param as object

This commit is contained in:
Javier Segarra 2025-02-14 02:43:09 +01:00
parent 47649d6186
commit c401bbb7fb
1 changed files with 11 additions and 6 deletions

View File

@ -136,7 +136,8 @@ onMounted(async () => {
if (!$props.formInitialData) { if (!$props.formInitialData) {
if ($props.autoLoad && $props.url) await fetch(); if ($props.autoLoad && $props.url) await fetch();
else if (arrayData.store.data) updateAndEmit('onFetch', arrayData.store.data); else if (arrayData.store.data)
updateAndEmit('onFetch', { val: arrayData.store.data });
} }
if ($props.observeFormChanges) { if ($props.observeFormChanges) {
watch( watch(
@ -156,7 +157,7 @@ onMounted(async () => {
if (!$props.url) if (!$props.url)
watch( watch(
() => arrayData.store.data, () => arrayData.store.data,
(val) => updateAndEmit('onFetch', val), (val) => updateAndEmit('onFetch', { val }),
); );
watch( watch(
@ -194,7 +195,7 @@ async function fetch() {
}); });
if (Array.isArray(data)) data = data[0] ?? {}; if (Array.isArray(data)) data = data[0] ?? {};
updateAndEmit('onFetch', data); updateAndEmit('onFetch', { val: data });
} catch (e) { } catch (e) {
state.set(modelValue, {}); state.set(modelValue, {});
originalData.value = {}; originalData.value = {};
@ -222,7 +223,11 @@ async function save() {
if ($props.urlCreate) notify('globals.dataCreated', 'positive'); if ($props.urlCreate) notify('globals.dataCreated', 'positive');
updateAndEmit('onDataSaved', formData.value, response?.data, originalData.value); updateAndEmit('onDataSaved', {
val: formData.value,
res: response?.data,
old: originalData.value,
});
if ($props.reload) await arrayData.fetch({}); if ($props.reload) await arrayData.fetch({});
hasChanges.value = false; hasChanges.value = false;
} finally { } finally {
@ -236,7 +241,7 @@ async function saveAndGo() {
} }
function reset() { function reset() {
updateAndEmit('onFetch', originalData.value); updateAndEmit('onFetch', { val: originalData.value });
if ($props.observeFormChanges) { if ($props.observeFormChanges) {
hasChanges.value = false; hasChanges.value = false;
isResetting.value = true; isResetting.value = true;
@ -258,7 +263,7 @@ function filter(value, update, filterOptions) {
); );
} }
function updateAndEmit(evt, val, res, old) { function updateAndEmit(evt, { val, res, old } = { val: null, res: null, old: null }) {
state.set(modelValue, val); state.set(modelValue, val);
originalData.value = val && JSON.parse(JSON.stringify(val)); originalData.value = val && JSON.parse(JSON.stringify(val));
if (!$props.url) arrayData.store.data = val; if (!$props.url) arrayData.store.data = val;