ogrodnek / pyview

A Python implementation of Phoenix LiveView
https://examples.pyview.rocks
MIT License
25 stars 0 forks source link

Any thoughts about components? #7

Open azazel75 opened 5 months ago

azazel75 commented 5 months ago

What's your idea of reusability across views? any thoughts on something similar to https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html?

ogrodnek commented 5 months ago

@azazel75 Yes, I'd definitely love to have a component and live component implementation, just haven't gotten to it yet...

Even shorter term, template includes (which don't currently work) are high on the list of things to implement.

azazel75 commented 5 months ago

That's a bummer! The custom templates are needed because of the diffing protocol, like in the original LiveView?

ogrodnek commented 5 months ago

Yup, that's right, we need to generate a tree of statics and dynamics for the diffs and to integrate with the client-side JS (I'm using the same Phoenix Liveview client side JS).

The library I'm currently using as the basis (https://github.com/dmulholl/ibis), does support includes already (for generating strings), I just haven't yet hacked in the statics/dynamics support.

I'm hoping if https://peps.python.org/pep-0501/ get implemented, it would be easier to also generate the tree we needed from python code (in addition to templating).

Theoretically, we could support another templating library if the library had support for generating some kind of parse tree instead of just output text...

ogrodnek commented 1 week ago

Quick update on this, I did add some initial support for template includes (you can see an example here: https://github.com/ogrodnek/pyview/blob/main/examples/views/includes/includes.html#L1 ), and more details on template includes in the ibis template include docs, so now there is a mechanism to reuse markup across views.

I do still plan to add support for "live components" (Ala phoenix LiveView https://hexdocs.pm/phoenix_live_view/Phoenix.LiveComponent.html ) which encapsulate state in addition to markup and can handle events at some point...