phoenix socket multiple assign

708 Views Asked by At

I want to add a few data into socket but wondering what the best way to do that would be.

Instead of doing a bunch of

socket = assign(socket, :channel_id, channel_id)

1

There are 1 best solutions below

0
Daniel On

There is an alternative function assign/2 that allows assigning multiple values at once, by passing either map or keyword list:

assign(socket, name: "Elixir", logo: "")
assign(socket, %{name: "Elixir"})