Skip to content

Commit e2e2e88

Browse files
BobowskiAdam Bobowski
andauthored
Adds delay modifier to attributes (#16)
* Adds delay modifier to attributes * updates docs param description --------- Co-authored-by: Adam Bobowski <[email protected]>
1 parent 63061ec commit e2e2e88

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/datastar_py/attributes.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,19 @@ def throttle(
433433
return self
434434

435435

436+
class DelayMod:
437+
def delay(
438+
self: Self,
439+
wait: int | float | str,
440+
) -> Self:
441+
"""Delay the event listener.
442+
443+
:param wait: The delay time.
444+
"""
445+
self._mods["delay"] = [str(wait)]
446+
return self
447+
448+
436449
class ViewtransitionMod:
437450
@property
438451
def viewtransition(self: Self) -> Self:
@@ -461,7 +474,7 @@ def self(self) -> Self:
461474
return self
462475

463476

464-
class OnAttr(BaseAttr, TimingMod, ViewtransitionMod):
477+
class OnAttr(BaseAttr, TimingMod, DelayMod, ViewtransitionMod):
465478
_attr = "on"
466479

467480
@property
@@ -628,7 +641,7 @@ def focus(self) -> Self:
628641
return self
629642

630643

631-
class OnIntersectAttr(BaseAttr, TimingMod, ViewtransitionMod):
644+
class OnIntersectAttr(BaseAttr, TimingMod, DelayMod, ViewtransitionMod):
632645
@property
633646
def once(self) -> Self:
634647
"""Only trigger the event listener once."""
@@ -659,14 +672,9 @@ def duration(self, duration: int | float | str, *, leading: bool = False) -> Sel
659672
return self
660673

661674

662-
class OnLoadAttr(BaseAttr, ViewtransitionMod):
675+
class OnLoadAttr(BaseAttr, ViewtransitionMod, DelayMod):
663676
_attr = "on-load"
664677

665-
def delay(self, delay: int | float | str) -> Self:
666-
"""Delay the event listener."""
667-
self._mods["delay"] = [str(delay)]
668-
return self
669-
670678
@property
671679
def once(self) -> Self:
672680
"""Only trigger the event listener once."""
@@ -678,7 +686,7 @@ class OnRafAttr(BaseAttr, TimingMod):
678686
_attr = "on-raf"
679687

680688

681-
class OnSignalPatchAttr(BaseAttr, TimingMod):
689+
class OnSignalPatchAttr(BaseAttr, TimingMod, DelayMod):
682690
_attr = "on-signal-patch"
683691

684692
def filter(self, include: str | None = None, exclude: str | None = None) -> Self:

0 commit comments

Comments
 (0)