diff --git a/library/src/plugins/attributes/onSignalPatch.ts b/library/src/plugins/attributes/onSignalPatch.ts index 90baa817..e7c60262 100644 --- a/library/src/plugins/attributes/onSignalPatch.ts +++ b/library/src/plugins/attributes/onSignalPatch.ts @@ -29,26 +29,26 @@ attribute({ filters = jsStrToObject(filtersRaw) } - let running = false - - const callback: EventListener = modifyTiming( + const timedCallback = modifyTiming( (evt: CustomEvent) => { - if (running) return - const watched = filtered(filters, evt.detail) - if (!isEmpty(watched)) { - running = true - beginBatch() - try { - rx(watched) - } finally { - endBatch() - running = false - } + beginBatch() + try { + rx(evt.detail) + } finally { + endBatch() } }, mods, ) + const callback: EventListener = (evt: Event | CustomEvent) => { + // we know that evt is CustomEvent, but typescript doesn't + const watched = filtered(filters, (evt as CustomEvent).detail) + if (!isEmpty(watched)) { + timedCallback({...evt, detail: watched}) + } + } + document.addEventListener(DATASTAR_SIGNAL_PATCH_EVENT, callback) return () => { document.removeEventListener(DATASTAR_SIGNAL_PATCH_EVENT, callback)