Skip to content

Commit

Permalink
Merge pull request #14 from reflex-dev/use-modern-var
Browse files Browse the repository at this point in the history
update to new vars
  • Loading branch information
picklelo authored Sep 6, 2024
2 parents 5431572 + 0aff2be commit 97869c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 3 additions & 4 deletions reflex_chakra/components/forms/multiselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from reflex.components.component import Component
from reflex.constants import EventTriggers
from reflex.vars import Var
from reflex.ivars import ImmutableVar, LiteralVar


class Option(Base):
Expand Down Expand Up @@ -310,10 +311,8 @@ def get_event_triggers(self) -> dict[str, Union[Var, Any]]:
return {
**super().get_event_triggers(),
EventTriggers.ON_CHANGE: (
lambda e0: [
Var.create_safe(f"{e0}.map(e => e.value)", _var_is_local=True)
]
if self.is_multi.equals(Var.create_safe(True))
lambda e0: [ImmutableVar.create_safe(f"{e0}.map(e => e.value)")]
if self.is_multi.equals(LiteralVar.create(True))
else lambda e0: [e0]
),
}
Expand Down
8 changes: 4 additions & 4 deletions reflex_chakra/components/forms/pininput.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from reflex.utils import format
from reflex.utils.imports import ImportDict, merge_imports
from reflex.vars import Var
from reflex.ivars import ImmutableVar, ArrayVar


class PinInput(ChakraComponent):
Expand Down Expand Up @@ -111,14 +112,13 @@ def _get_ref_hook(self) -> Optional[str]:
"""
if self.id:
ref = format.format_array_ref(self.id, None)
refs_declaration = Var.range(self.length).foreach(
lambda: Var.create_safe("useRef(null)", _var_is_string=False),
refs_declaration = ImmutableVar.create_safe(
f"{str(ArrayVar.range(self.length))}.map(() => useRef(null))",
)
refs_declaration._var_is_local = True
if ref:
return (
f"const {ref} = {str(refs_declaration)}; "
f"{str(Var.create_safe(ref, _var_is_string=False).as_ref())} = {ref}"
f"{str(ImmutableVar.create_safe(ref).as_ref())} = {ref}"
)
return super()._get_ref_hook()

Expand Down
3 changes: 2 additions & 1 deletion reflex_chakra/components/forms/rangeslider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from reflex.event import EventHandler
from reflex.utils import format
from reflex.vars import Var
from reflex.ivars import ImmutableVar


class RangeSlider(ChakraComponent):
Expand Down Expand Up @@ -77,7 +78,7 @@ def _get_ref_hook(self) -> Optional[str]:
if ref:
return (
f"const {ref} = Array.from({{length:2}}, () => useRef(null)); "
f"{str(Var.create_safe(ref, _var_is_string=False).as_ref())} = {ref}"
f"{str(ImmutableVar.create_safe(ref).as_ref())} = {ref}"
)
return super()._get_ref_hook()

Expand Down

0 comments on commit 97869c3

Please sign in to comment.