-
-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a template tag #1056
base: main
Are you sure you want to change the base?
Add a template tag #1056
Conversation
@rmorshea this PR contains the template tag itself, but not in a usable form due to
I don't know if I'm going to have time to work on this in-between working on the docs, so feel free to commit directly to this branch if you feel like moving it forward. |
This might make more sense as a standalone The current server API accepts WS connections at import json
from urllib.parse import parse_qs, unquote
views: dict[str, Callable[[], Component]] = { ... }
@component
def app():
loc = use_location()
cmpt = views[loc.pathname]
search = json.loads(parse_qs(loc.search[1:])
args = json.loads(unquote(search.get("args", ["[]"])[0]))
kwargs = json.loads(unquote(search.get("kwargs", ["{}"])[0]))
return cmpt(*args, **kwargs) So in the rough pseudo code above, connecting to a WS at:
would effectively render One could imagine user's interacting with this library in the following way: from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from reactpy.backend.fastapi import configure
import reactpy_jinja
@reactpy_jinja.register
def my_component(hello):
...
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
async def index(request):
return templates.TemplateResponse("index.html")
configure(app, reactpy_jinja.root) Where {% component "my_component" hello="world" %} |
You think Maybe we should call it The decorator might be finnicky. Unlike ASGI views, users might not have all of their component functions imported into their main file. We should probably require a Also do we even want to consider anything unique for Tornado, or do we force Tornado users to install jinja? I'm leaning towards the latter. |
I think we really should push for the template tag being built-in to ReactPy. In my opinion, it should be our main way of advertising how to use ReactPy. |
I think this work might be easier once we've consolidated around ASGI/WSGI implementations since it can build upon a more uniform application interface. |
Yep, that's why this issue is marked as blocked for now. |
By submitting this pull request you agree that all contributions to this project are made under the MIT license.
Issues
Summary
Adds template tag support for all of our supported backends.
Checklist
changelog.rst
has been updated with any significant changes.