Add phx-custom-events
to allow custom events to be handled by LiveView
#3438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for a
phx-custom-events
attribute which will cause a private hook to be added to listen for Custom Events.The hook will use the value for this attribute which should contain either a single or comma-delimited list of custom event names, which will be pushed to LV. The
detail
property of the custom event, merged with the element dataset, will be used as the payload of the event sent to LV.Alternatively, if the
phx-custom-events
attribute is present to trigger this hook, the hook will look for any attributes which begin withphx-custom-event-
and allow the user to rename the event e. g.phx-custom-event-foo="bar"
This code originated in the phoenix-custom-event-hook project and has been used on several projects.