From 5d2df03223c27cb85661313b47d6af2ef7703c6b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 12:47:26 +0200 Subject: [PATCH] refs #6772 perf: use ArrayData --- src/components/ui/VnPaginate.vue | 20 +------------------- src/composables/useArrayData.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index 4dea57680..cb2e8d98e 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -94,25 +94,7 @@ watch( ); watch( () => route.params.id, - () => { - if (route.path === props.url) return; - //Así fuerzo al reinicio - store.data = null; - if (!arrayData.store?.filter?.where) { - //Cuando el cambio viene por VnSearchbar - if (route.params.id) store.url = store.url.replace(/(\d+)/, route.params.id); - } else { - // Cuando el usuario cambia en la URL - const keyFk = Object.keys(arrayData.store.filter.where).find((key) => - key.endsWith('Fk') - ); - if (keyFk) { - arrayData.store.filter.where[keyFk] = route.params.id; - } - } - - fetch(); - } + () => arrayData.reloadRoute() ); async function fetch() { await arrayData.fetch({ append: false }); diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index b6b81f2d5..6a2f0aae6 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -34,6 +34,26 @@ export function useArrayData(key, userOptions) { setOptions(); } + function reloadRoute() { + if (route.path === store.url) return; + //Así fuerzo al reinicio + store.data = null; + if (!store?.filter?.where) { + //Cuando el cambio viene por VnSearchbar + if (route.params.id) store.url = store.url.replace(/(\d+)/, route.params.id); + } else { + // Cuando el usuario cambia en la URL + const keyFk = Object.keys(store.filter.where).find((key) => + key.endsWith('Fk') + ); + if (keyFk) { + store.filter.where[keyFk] = route.params.id; + } + } + + fetch({ append: false }); + } + function setOptions() { const allowedOptions = [ 'url', @@ -210,5 +230,6 @@ export function useArrayData(key, userOptions) { totalRows, updateStateParams, isLoading, + reloadRoute, }; }