View Source Assigns (Assigns v0.1.0)

Helps abbreviate writing LiveView assign/3, assign_new/3 and update/3 wrapper functions.

Ex:

defassign :foo

expands into

def assign_foo( socket_or_assigns, foo) do
  assign( socket_or_assigns, :foo, foo)
end

while

defassign [ :foo, :bar, :baz]

expands into

def assign_foo( socket_or_assigns, foo) do
  assign( socket_or_assigns, :foo, foo)
end

def assign_foo( socket_or_assigns, bar) do
  assign( socket_or_assigns, :bar, bar)
end

def assign_foo( socket_or_assigns, baz) do
  assign( socket_or_assigns, :baz, baz)
end

Similarly,

defupdate [ :foo, :bar]

expands into

def update_foo( socket_or_assigns, updater) do
  assign( socket_or_assigns, :foo, updater)
end

def update_bar( socket_or_assigns, updater) do
  assign( socket_or_assigns, :bar, updater)
end

Boolean assigns are an exception in that the assign key is identical to the name, while the assign (or update) wrapper function name does not contain the question mark.

Ex:

defassign :connected?

expands into:

def assign_connected( socket_or_assigns, connected?) do
  assign( socket_or_assigns, :connected?, connected?)
end

Summary

Functions

Defines a Phoenix.Component.assign/3 wrapper function for each of the names whether provided in a list or as a standalone atom.

Defines a Phoenix.Component.assign_new/3 wrapper function for each of the names whether provided in a list or as a standalone atom.

Same as defassign_new/1 but defines private wrapper function(s).

Same as defassign/1 but defines private wrapper function(s).

Defines a Phoenix.Component.update/3 wrapper function for each of the names whether provided in a list or as a standalone atom.

Same as defupdate/1 but defines private wrapper function(s).

Functions

Link to this macro

defassign(name_or_names)

View Source (macro)
@spec defassign(atom() | [atom()]) :: Macro.output()

Defines a Phoenix.Component.assign/3 wrapper function for each of the names whether provided in a list or as a standalone atom.

Link to this macro

defassign_new(name_or_names)

View Source (macro)
@spec defassign_new(atom() | [atom()]) :: Macro.output()

Defines a Phoenix.Component.assign_new/3 wrapper function for each of the names whether provided in a list or as a standalone atom.

Link to this macro

defassign_newp(name_or_names)

View Source (macro)
@spec defassign_newp(atom() | [atom()]) :: Macro.output()

Same as defassign_new/1 but defines private wrapper function(s).

Link to this macro

defassignp(name_or_names)

View Source (macro)
@spec defassignp(atom() | [atom()]) :: Macro.output()

Same as defassign/1 but defines private wrapper function(s).

Link to this macro

defupdate(name_or_names)

View Source (macro)
@spec defupdate(atom() | [atom()]) :: Macro.output()

Defines a Phoenix.Component.update/3 wrapper function for each of the names whether provided in a list or as a standalone atom.

Link to this macro

defupdatep(name_or_names)

View Source (macro)
@spec defupdatep(atom() | [atom()]) :: Macro.output()

Same as defupdate/1 but defines private wrapper function(s).