Skip to content

Commit

Permalink
updading set_empty_attributes and forward_attributes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cblavier committed Mar 14, 2022
1 parent 2681173 commit 288eb86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/phx_component_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ defmodule PhxComponentHelpers do
for option <- opts, reduce: %{} do
acc ->
assigns = handle_forward_option(assigns, option)
Map.merge(acc, assigns)
assign(assigns, acc)
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/phx_component_helpers/set_attributes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule PhxComponentHelpers.SetAttributes do
for attr <- attributes, reduce: assigns do
acc ->
heex_attr_key = heex_attribute_key(attr)
Map.put_new(acc, heex_attr_key, [])
assign_new(acc, heex_attr_key, fn -> [] end)
end
end

Expand All @@ -50,6 +50,16 @@ defmodule PhxComponentHelpers.SetAttributes do

def assign(assigns, key, value), do: Map.put(assigns, key, value)

def assign(%{__changed__: _changes} = assigns, keyword_or_map),
do: Phoenix.LiveView.assign(assigns, keyword_or_map)

def assign(assigns, keyword_or_map), do: Map.merge(assigns, keyword_or_map)

def assign_new(%{__changed__: _changes} = assigns, key, fun),
do: Phoenix.LiveView.assign_new(assigns, key, fun)

def assign_new(assigns, key, fun), do: Map.put_new_lazy(assigns, key, fun)

defp heex_escaped(val, opts) do
if opts[:json] do
@json_library.encode!(val)
Expand Down

0 comments on commit 288eb86

Please sign in to comment.