Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't assigns have multiple signatures? #4

Open
bdtomlin opened this issue Aug 27, 2021 · 0 comments
Open

Shouldn't assigns have multiple signatures? #4

bdtomlin opened this issue Aug 27, 2021 · 0 comments

Comments

@bdtomlin
Copy link

bdtomlin commented Aug 27, 2021

Currently Bamboo.Phoenix only has the following assign/3 function and not the typical assign/2:

  def assign(%{assigns: assigns} = email, key, value) do
    %{email | assigns: Map.put(assigns, key, value)}
  end

This makes it a little inconvenient to assign multiple values. It forces you to have to either implement assign/2 yourself or do the following.

new_email()
|> assign(item_one: 1)
|> assign(item_two: 1)
|> assign(item_three: 1)

It definitely surprised me and I have to spend a little time figuring out why the following wasn't working:

new_email()
|> assign(item_one: 1, item_two: 2, item_three: 3)

Shouldn't we have the same functions available as Bamboo.Template?

  def assign(%{assigns: assigns} = email, attrs) when is_map(attrs) or is_list(attrs) do
    %{email | assigns: Enum.into(attrs, assigns)}
  end

  def assign(%{assigns: assigns} = email, key, value) do
    %{email | assigns: Map.put(assigns, key, value)}
  end

There is actually quite a bit of duplication of what's in Bamboo.Template, that could be cleaned up, along with adding assign/2 by doing the following in Bamboo.Phoenix:

import Bamboo.Email

I'm glad to do a pull request if you guys agree with that solution. We could also just re-implement assign/2, but I would prefer not to duplicate the code.

Let me know your thoughts, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant