Skip to content

Commit

Permalink
fix set value logix for client state (#3966)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 authored Sep 23, 2024
1 parent 61332fd commit ee3b0e6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions reflex/experimental/client_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import dataclasses
import re
import sys
from typing import Any, Callable, Union

Expand Down Expand Up @@ -174,15 +175,15 @@ def set_value(self, value: Any = NoValue) -> Var:
else self._setter_name
)
if value is not NoValue:
import re

# This is a hack to make it work like an EventSpec taking an arg
value_str = str(LiteralVar.create(value))

# remove patterns of ["*"] from the value_str using regex
arg = re.sub(r"\[\".*\"\]", "", value_str)

setter = f"({arg}) => {setter}({str(value)})"
if value_str.startswith("_"):
# remove patterns of ["*"] from the value_str using regex
arg = re.sub(r"\[\".*\"\]", "", value_str)
setter = f"(({arg}) => {setter}({value_str}))"
else:
setter = f"(() => {setter}({value_str}))"
return Var(
_js_expr=setter,
_var_data=VarData(imports=_refs_import if self._global_ref else {}),
Expand Down

0 comments on commit ee3b0e6

Please sign in to comment.