Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Strategy Prop to Literal #3575

Merged
merged 9 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions reflex/components/base/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from __future__ import annotations

from typing import Literal

from reflex.components.component import Component
from reflex.event import EventHandler
from reflex.vars import Var
Expand All @@ -27,8 +29,10 @@ class Script(Component):
# Required unless inline script is used
src: Var[str]

# When the script will execute: afterInteractive | beforeInteractive | lazyOnload
strategy: Var[str] = "afterInteractive" # type: ignore
# When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior)
strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = (
Var.create_safe("afterInteractive", _var_is_string=True)
)

# Triggered when the script is loading
on_load: EventHandler[lambda: []]
Expand Down
12 changes: 10 additions & 2 deletions reflex/components/base/script.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import reflex
from reflex.vars import Var, BaseVar, ComputedVar
from reflex.event import EventChain, EventHandler, EventSpec
from reflex.style import Style
from typing import Literal
from reflex.components.component import Component
from reflex.event import EventHandler
from reflex.vars import Var
Expand All @@ -19,7 +20,14 @@ class Script(Component):
cls,
*children,
src: Optional[Union[reflex.vars.Var[str], str]] = None,
strategy: Optional[Union[reflex.vars.Var[str], str]] = None,
strategy: Optional[
Union[
reflex.vars.Var[
Literal["afterInteractive", "beforeInteractive", "lazyOnload"]
],
Literal["afterInteractive", "beforeInteractive", "lazyOnload"],
]
] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
Expand Down Expand Up @@ -97,7 +105,7 @@ class Script(Component):
Args:
*children: The children of the component.
src: Required unless inline script is used
strategy: When the script will execute: afterInteractive | beforeInteractive | lazyOnload
strategy: When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior)
style: The style of the component.
key: A unique key for the component.
id: The id for the component.
Expand Down
Loading