Innnnnteresting. I was trying to figure out how to do something like this and couldn’t figure it out. I was trying to use var!/2 for this to no avail. I never understood that you can check the caller env.
I was looking to create a single guard that would work on both socket and assigns. I have a lot of single module CRUD LiveViews so I wanted something like:
def handle_event("update", %{"user" => user_params}, socket) when in_action([:edit]) do
#...
end
def render(assigns) when in_action([:edit]) do
~H"""
"""
end
This would check whichever existed of socket.assigns.live_action or assigns.live_action was in [:edit].
Even though I don’t think that is particularly evil (that is, what I wanted to do—what you’re suggesting is absolutely pure evil
) , I ultimately decided I’d rather not do anything out the ordinary like this so I never bothered to seek help figuring it out, but it’s nice to know how it could be done, so thanks!
(that is, if that would even solve the problem… I haven’t actually tried, just responded immediately, lol, but still informative for me)






















