3 ms·
Yeah, the "magic" dispatcher code in <project>_web.ex is pretty powerful but I'm not sure it would be easy for beginners to grok it: @doc """ When used
by dugmartin 5y ago
Yeah, the "magic" dispatcher code in <project>_web.ex is pretty powerful but I'm not sure it would be easy for beginners to grok it:
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
That said I much prefer how Phoenix puts this code explicitly in each project and doesn't hide it in a gem like Rails.
- dqv 5y agoFor example’s sake, it would be fine to just remove that and do it manually: defmacro __using__(:view), do: view() But I think explaining what each element does in that dispatcher would be helpful. Especially in cases with typos.