reactive-python / reactive-python/reactpy
Create a way to evaluate arbitrary javascript
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 332
- PR merge metrics
- No merged PRs in 30d
Description
Current Situation
Currently, there is no method to transmit the results of a JavaScript function to the backend.
Proposed Actions
This might look like a use_script hook that operates similarly to html.script, but can return a result.
For example,
@component
def example():
executor = use_script("getComputedStyle(document.querySelector('#element'))")
return f"CSS Style Attributes: {executor.data}"
Since this hook would need to operate asynchronously, the interface would likely be heavily inspired by our Django use_query hook.
And perhaps it could be used as an executor within event contexts to be more "reactive":
@component
def example():
executor = use_script("getComputedStyle(document.querySelector('#element'))", deferred=True)
async def on_click(event):
await executor()
example_value = executor.data
return f"CSS Style Attributes: {script.data}"
See this comment for traceability.
Note: If possible, we should try pre-populate this keyword with something that makes sense, depending on where the JavaScript was executed.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing html.script and Django use_query hooks, then review the traceability comment in issue 857. Define how use_script should return JavaScript results, support asynchronous or deferred event execution, and handle the this keyword. Done means the proposed examples have a clear, working interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, python
- Domain
- backend, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100