Open yunge opened 9 months ago
Interesting approach, appreciate the sample code and good description.
I think this could work, the main difference to make run_script
return the value is to have the internal callback function set the result of an asyncio.Future
that the outer function awaits after emitting the update. As long as run_script
is only ever called from a state event handler, then it should work.
A few other cleanups are necessary, like removing the temporary handler from event_handlers
dict, but i don't immediately see anything that's a deal breaker from a reflex architecture perspective. I would probably implement the logic as rx.State.call_script
so everything stays within rx.State
.
rx.State.call_script would be great, thanks for your hard work.
The current version of call_script() is too limited, as it can only defines a State.callback_function, we can't use it directly in a function.
Suppose we have the following requirement, it's hard to implement with call_script(). (It's just an improvised idea, so please ignore its practical value.)
I tried to make an easier-to-use function, temporarily called run_script():
Usage:
(This is an unfinished version, I haven't been able to make it return a value directly, so it needs a callback instead, and no doubt the dev team can make a better version.)
I sincerely hope the Reflex team can consider these proposals, thanks.
REF-1501