reactive-python / reactpy-django

It's React, but in Python. Now with Django integration.
https://reactive-python.github.io/reactpy-django/
MIT License
322 stars 18 forks source link

Client-side Python components #229

Closed Archmonger closed 2 months ago

Archmonger commented 6 months ago

Current Situation

While it's currently not possible to implement in core, we can use our template tag to render client-side components within this repo as a Django exclusive early release.

Proposed Actions

Develop client side components with multiple execution methods. The initial draft will be based on https://github.com/reactive-python/reactpy/discussions/1096

We need to make sure the interface makes the user understand that the whole file is going to be loaded into the browser.

Here's a quick draft of potential API designs:

{% component "example.hello_world" client_side_render="pyscript" %}
{% component "file:/example/components.py:hello_world" executor="pyscript" %}
{% client_component "/example/components.py:hello_world" executor="reactpy_django.client.pyscript" %}
{% pyscript_component "/example/components.py:hello_world" %}
{% pyscript_component "/example/components.py" root="hello_world" %}

We should also create a callable variant that can be used as a child within server side components.

@component
def parent_component():
    return html.div( pyscript_component("/example/components.py", root="hello_world") )

It seems logical that the root component should be def root(...) by default.

We may also want to minify the python code we generate. Minification should be toggleable through minify=False Not feasible since minification would rename the root component