elixir - Partial updates in Phoenix and function signature -


i want create partial update method via ajax/json. how should "update" function like?

def update(conn, %{"a" => a, "b" => b, "c" => c} = params)     # .... end 

namely, 1 of these parameters required at time. how can specify that? or should instead this:

def update(conn, params)     # .... end 

check if params contains a, b or c?

you can use pattern matching define possibilities:

def update(conn, %{"a" => a} = params)   # when have "a" end  def update(conn, %{"b" => b} = params)   # when have "b" end  def update(conn, %{"c" => c} = params)   # when have "c" end  def update(conn, params)   # handle else end 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -