Skip to content
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

Shared event handlers #571

Merged
merged 24 commits into from
Aug 24, 2024
Merged

Shared event handlers #571

merged 24 commits into from
Aug 24, 2024

Conversation

APB9785
Copy link
Contributor

@APB9785 APB9785 commented Aug 2, 2024

Resolves #519

@APB9785 APB9785 self-assigned this Aug 2, 2024
@APB9785 APB9785 marked this pull request as ready for review August 2, 2024 22:20
@APB9785 APB9785 requested a review from leandrocp August 2, 2024 22:20
@@ -124,10 +125,10 @@ defmodule Beacon.Loader.Page do
end

defp handle_event(page) do
%{site: site, event_handlers: event_handlers} = page
event_handlers = Content.list_event_handlers(page.site)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still one step missing here :)

Whenever an event handler changes we'd need to broadcast a message to recompile all page modules so I'm wondering if it would be better to create a new EventHandler module containing all handle_event and on the handle_event of PageLive here

result =
Beacon.apply_mfa(
page_module,
:handle_event,
[event_name, event_params, socket],
context: %{site: site, page_id: page_id, live_path: live_path}
)

We just replace page_module with event_handler_module.

In this case whenever an event handler changes we only recompile the single event handler module and save resources by not duplicating the same event_handler on all page modules.

Wdyt?

@leandrocp leandrocp merged commit 010baae into main Aug 24, 2024
3 checks passed
@leandrocp leandrocp deleted the apb/global-event-handlers branch August 24, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shared Event Handlers
2 participants