Skip to content

Create a way to evaluate arbitrary javascript #894

Description

@Archmonger

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-3-lowMay be resolved one any timeline.type-investigationAbout research and gathering information

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions