From 255ea763b4e38db29407bdb9dcd125821706e573 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 10 Jul 2024 17:06:29 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20poder=20cancelar=20cuando=20se=20est?= =?UTF-8?q?=C3=A1=20haciendo=20un=20fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit si salimos de la página hay que poder cancelar todos los fetchs pendientes sin producir errores --- app/javascript/controllers/array_controller.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/javascript/controllers/array_controller.js b/app/javascript/controllers/array_controller.js index fea690d2..e8f15e8c 100644 --- a/app/javascript/controllers/array_controller.js +++ b/app/javascript/controllers/array_controller.js @@ -103,6 +103,8 @@ export default class extends Controller { this.currentTarget.innerHTML = ""; this.originalValue = []; + const signal = window.abortController?.signal; + for (const itemTarget of this.itemTargets) { if (!itemTarget.dataset.value) continue; if (!this.isChecked(itemTarget)) continue; @@ -114,8 +116,7 @@ export default class extends Controller { this.currentTarget.appendChild(placeholder); - // TODO: Renderizarlas todas juntas - fetch(this.newArrayValueURL) + fetch(this.newArrayValueURL, { signal }) .then((response) => response.text()) .then((body) => { const template = document.createElement("template");