BeaconCMS / beacon

Open-source content management system (CMS) built with Phoenix LiveView. Faster render times to boost SEO performance, even for the most content-heavy pages.
https://beaconcms.org
MIT License
818 stars 84 forks source link

[Proposal] Shared Event Handlers #519

Open leandrocp opened 2 weeks ago

leandrocp commented 2 weeks ago

A common scenario that's not yet handled fully by Beacon is handling events emitted by components. Suppose a newsletter_form component that renders a form with phx-submit="signup", that signup event will be handled by an event handler defined in the Page, that works and is the current approach we have.

But it becomes cumbersome when that component is called in a layout because now all pages using that layout must create the same event handler over and over again, duplicating data and effort to manage that event.

layouts:
  - newsletter_form component
  pages:
    - page a
      - event_handler signup
    - page b
      - event_handler signup

See how the event_handler signup gets duplicated.

The proposal is to introduce a *(Event Handlers** resource in the Content API and also on the Admin interface to manage shared events so whenever an event is called, it will be fetched by name and executed, globally on the site.

Tasks

FAQ

absowoot commented 1 week ago

Could there be a separate CRUD for adding live components as well? It would be great to have the ability to add them without needing to restart the app.

leandrocp commented 1 week ago

Could there be a separate CRUD for adding live components as well? It would be great to have the ability to add them without needing to restart the app.

Hey @absowoot do you mean creating a https://hexdocs.pm/phoenix_live_view/Phoenix.LiveComponent.html? That's possible although it's not on the roadmap yet. First we're getting functions components so you can define attrs, slots, etc to use on page template, ie: a component named my_header is available on the template as <.my_header attrs...> - the last task to get this done is the admin interface https://github.com/BeaconCMS/beacon_live_admin/pull/160

After getting that done we would have the foundation to work on LiveComponents too. Feel free to open an issue requesting support for LiveComponents so we can have it on the backlog.