37 feature use module attributes to map events to action names#44
Merged
vincentvanbush merged 13 commits intomainfrom Dec 4, 2025
Merged
Conversation
3 tasks
itamm15
approved these changes
Dec 4, 2025
| @moduledoc false | ||
|
|
||
| def __on_definition__(env, _kind, :handle_event, args, _guards, _body) do | ||
| event_name = args |> List.first() |
There was a problem hiding this comment.
nit:
Suggested change
| event_name = args |> List.first() | |
| event_name = List.first(args) |
| @callback unauthorized_message(PhoenixTypes.socket(), map()) :: binary() | ||
| @callback event_mapping() :: map() | ||
| @doc ~S""" | ||
| For events that do not carry an `"id"` param (e.g. updating a record with form data), determines whether to reload the record before each event authorization. |
lib/permit_phoenix/live_view.ex
Outdated
| case unquote(opts[:reload_on_event?]) do | ||
| fun when is_function(fun) -> fun.(action, socket) | ||
| nil -> true | ||
| other -> other |
There was a problem hiding this comment.
Q: What can be other? 🤔 Maybe it would be better to tighten the possible callbacks?
@impl true
def reload_on_event?(action, socket) do
case unquote(opts[:reload_on_event?]) do
fun when is_function(fun, 2) -> fun.(action, socket)
bool when is_boolean(bool) -> bool
nil -> true
other -> raise ArgumentError, "expected :reload_on_event? option to be a boolean or a 2-arity function, got: #{inspect(other)}"
end
end
vincentvanbush
commented
Dec 4, 2025
Contributor
Author
vincentvanbush
left a comment
There was a problem hiding this comment.
Q: What can be
other? 🤔 Maybe it would be better to tighten the possible callbacks?@impl true def reload_on_event?(action, socket) do case unquote(opts[:reload_on_event?]) do fun when is_function(fun, 2) -> fun.(action, socket) bool when is_boolean(bool) -> bool nil -> true other -> raise ArgumentError, "expected :reload_on_event? option to be a boolean or a 2-arity function, got: #{inspect(other)}" end end
It can also be false, so the raising pattern must be preceded by that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request
Description
In addition to the existing
event_mapping/0callback, introduces the@permit_actionmodule attribute to annotate LiveView event handlers with the corresponding Permit action name.Type of Change
Related Issues
Closes #37
Changes Made
Testing
Tests added for both Ecto and non-Ecto (loader-based) resolution in LiveViews. Also tested manually with a companion app.
Test Environment
Test Cases
Test Commands Run
Documentation
Code Quality
Phoenix/LiveView Specific
Backward Compatibility
Breaking Changes
Performance Impact
Performance Notes
Security Considerations
Additional Notes
Screenshots/Examples
Checklist
Reviewer Notes