From 0f0f5a1e4cdc0ff41be1f780a829ae82683173e6 Mon Sep 17 00:00:00 2001 From: Adam Bobowski Date: Fri, 1 Aug 2025 10:34:03 +0200 Subject: [PATCH 1/2] Adds delay modifier to attributes --- src/datastar_py/attributes.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/datastar_py/attributes.py b/src/datastar_py/attributes.py index 3263c11..966bbab 100644 --- a/src/datastar_py/attributes.py +++ b/src/datastar_py/attributes.py @@ -433,6 +433,19 @@ def throttle( return self +class DelayMod: + def delay( + self: Self, + wait: int | float | str, + ) -> Self: + """Delay the event listener. + + :param wait: The minimum interval between events. + """ + self._mods["delay"] = [str(wait)] + return self + + class ViewtransitionMod: @property def viewtransition(self: Self) -> Self: @@ -461,7 +474,7 @@ def self(self) -> Self: return self -class OnAttr(BaseAttr, TimingMod, ViewtransitionMod): +class OnAttr(BaseAttr, TimingMod, DelayMod, ViewtransitionMod): _attr = "on" @property @@ -628,7 +641,7 @@ def focus(self) -> Self: return self -class OnIntersectAttr(BaseAttr, TimingMod, ViewtransitionMod): +class OnIntersectAttr(BaseAttr, TimingMod, DelayMod, ViewtransitionMod): @property def once(self) -> Self: """Only trigger the event listener once.""" @@ -659,14 +672,9 @@ def duration(self, duration: int | float | str, *, leading: bool = False) -> Sel return self -class OnLoadAttr(BaseAttr, ViewtransitionMod): +class OnLoadAttr(BaseAttr, ViewtransitionMod, DelayMod): _attr = "on-load" - def delay(self, delay: int | float | str) -> Self: - """Delay the event listener.""" - self._mods["delay"] = [str(delay)] - return self - @property def once(self) -> Self: """Only trigger the event listener once.""" @@ -678,7 +686,7 @@ class OnRafAttr(BaseAttr, TimingMod): _attr = "on-raf" -class OnSignalPatchAttr(BaseAttr, TimingMod): +class OnSignalPatchAttr(BaseAttr, TimingMod, DelayMod): _attr = "on-signal-patch" def filter(self, include: str | None = None, exclude: str | None = None) -> Self: From bdcc9177eabb8da5b9a4f56a91f4622345e1b088 Mon Sep 17 00:00:00 2001 From: Adam Bobowski Date: Fri, 1 Aug 2025 16:10:46 +0200 Subject: [PATCH 2/2] updates docs param description --- src/datastar_py/attributes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datastar_py/attributes.py b/src/datastar_py/attributes.py index 966bbab..0967fb0 100644 --- a/src/datastar_py/attributes.py +++ b/src/datastar_py/attributes.py @@ -440,7 +440,7 @@ def delay( ) -> Self: """Delay the event listener. - :param wait: The minimum interval between events. + :param wait: The delay time. """ self._mods["delay"] = [str(wait)] return self