reactive-python / reactpy-django

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

Rework view_to_component #98

Closed Archmonger closed 2 years ago

Archmonger commented 2 years ago

Description (NEW)

This PR reworks _view_tocomponent to prevent needing to constantly pass in frequently used parameters.

Description (OLD)

In Conreq, I am relying on several view_to_component URLs to exist prior to the first render. That meaning, the compatibility registration needs to occur prior to the component's first time rendering.

By moving the iframe registration outside of the hook, this change allows me to arbitrarily call view_to_component(my_view, compatibility=True) as a "preloading" step during Conreq initialization to ensure the URL exists beforehand.

Additionally, a nice benefit of this is now type hints will work. They were previously obfuscated due to the @component decorator.

In my opinion, this feels less obtrusive than a separate API just to register iframes.

Checklist:

Please update this checklist as you complete each item: