You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm curious what the intended method for interacting with State from an external process is in Reflex. I can setup an application with something like this:
import reflex as rx
app = rx.App()
class ExampleState(rx.State):
example_integer:int = 1000
async def set_example_integer(self, new_integer:int) ->None:
self.example_integer = new_integer
async def get_example_integer(self) ->int:
return self.example_integer
async def set_example_integer(new_integer:int):
# How do we set the ExampleState's example_integer?
# ExampleState.example_integer = new_integer
# ExampleState.set_example_integer(new_integer)
async def get_example_integer():
# How do we get the ExampleState's example_integer?
# return ExampleState.example_integer
# return ExampleState.get_example_integer()
app.api.add_api_route("/example_integer", set_example_integer,methods=['POST'])
app.api.add_api_route("/example_integer", get_example_integer,methods=['GET'])
In this application, we have a variable 'example_integer' within ExampleState that we want to be able to get and set externally. However, the two patterns I've tried (commented out above) yield unexpected results. The GET returns an rx.Var object while the SET seems to fail silently -- the value doesn't change in the main application and when I print the returned and changed value, it also gives an rx.Var object. The rx.Var object doesn't seem to have an obvious way to see the actual value of the Var.
Is there a better way within Reflex to enable the modification and retrieval of State from outside the application, ideally by adding API Routers? Thanks in advance!
There's some overlap with this discussion but unfortunately it didn't solve my question.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm curious what the intended method for interacting with State from an external process is in Reflex. I can setup an application with something like this:
In this application, we have a variable 'example_integer' within ExampleState that we want to be able to get and set externally. However, the two patterns I've tried (commented out above) yield unexpected results. The GET returns an rx.Var object while the SET seems to fail silently -- the value doesn't change in the main application and when I print the returned and changed value, it also gives an rx.Var object. The rx.Var object doesn't seem to have an obvious way to see the actual value of the Var.
Is there a better way within Reflex to enable the modification and retrieval of State from outside the application, ideally by adding API Routers? Thanks in advance!
There's some overlap with this discussion but unfortunately it didn't solve my question.
Beta Was this translation helpful? Give feedback.
All reactions