Skip to content

Commit

Permalink
Use pattern matching more
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 23, 2023
1 parent 90563a2 commit c68548d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/phoenix_ecto/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,16 @@ if Code.ensure_loaded?(Phoenix.HTML) do

def input_value(%{changes: changes, data: data}, %{params: params}, field)
when is_atom(field) do
case Map.fetch(changes, field) do
{:ok, value} ->
case changes do
%{^field => value} ->
value

:error ->
case Map.fetch(params, Atom.to_string(field)) do
{:ok, value} ->
value
%{} ->
string = Atom.to_string(field)

:error ->
Map.get(data, field)
case params do
%{^string => value} -> value
%{} -> Map.get(data, field)
end
end
end
Expand Down

0 comments on commit c68548d

Please sign in to comment.