Hi all,
I am struggling with an API for very important function in my library, maybe someone will find a better idea than mine.
Background: there is a function poke
, coming with arity of 2, 3 or 4, specs are:
@spec poke(Phoenix.Socket.t(), Keyword.t()) :: result
def poke(socket, assigns)
@spec poke(Phoenix.Socket.t(), String.t(), Keyword.t()) :: result
def poke(socket, partial, assigns)
@spec poke(Phoenix.Socket.t(), atom, String.t(), Keyword.t()) :: result
def poke(socket, view, partial, assigns)
Sample:
poke socket, assign1: "something", assign2: 42
I need to add an optional option, also the keyword list (although so far it will be only one option, :using_assigs
). I could just use one key from the assigns
list for this, so user would mix the assigns
and options:
poke socket, assign1: "something", assign2: 42, using_assigns: [...]
Because assigns
keyword list key are Phoenix template assigns, I could even prevent having using_assign
by user (I compile the template and may raise when some uses this assign).
This would do a trick, but I am having the impression that it is not very idiomatic. Is there the cleaner way to solve this, without changing the existing API?