Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/datastar_py/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 delay time.
"""
self._mods["delay"] = [str(wait)]
return self


class ViewtransitionMod:
@property
def viewtransition(self: Self) -> Self:
Expand Down Expand Up @@ -461,7 +474,7 @@ def self(self) -> Self:
return self


class OnAttr(BaseAttr, TimingMod, ViewtransitionMod):
class OnAttr(BaseAttr, TimingMod, DelayMod, ViewtransitionMod):
_attr = "on"

@property
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand All @@ -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:
Expand Down
Loading