live_props v0.2.1 LiveProps.States View Source

Link to this section Summary

Functions

Assign states of the given kind to the socket. The kind can be one of :all, :defaults, :computed (computed states without the :after_connect option), or :async (computed states defined with after_connect: true)

A replacement for Phoenix.LiveView.send_update/2. Invalid states will be ignored.

Same as set_state/3 but with a list or map of assigns.

Assign the state to the socket and return the socket. This will also trigger re-calculation of any computed state. If you do not wish to do this, use Phoenix.LiveView.assign/3 instead.

Same as set_state/2 but raises if passed an invalid state

Same as set_state/3 but raises if passed an invalid state

Define state of given name and type. Returns :ok.

Link to this section Functions

Link to this macro

assign_states(socket, kind)

View Source (macro)

Assign states of the given kind to the socket. The kind can be one of :all, :defaults, :computed (computed states without the :after_connect option), or :async (computed states defined with after_connect: true)

Link to this function

send_state(module, id, assigns)

View Source

Specs

send_state(module :: module(), id :: any(), assigns :: list()) :: :ok

A replacement for Phoenix.LiveView.send_update/2. Invalid states will be ignored.

Link to this macro

set_state(socket, assigns)

View Source (macro)

Specs

set_state(socket :: Phoenix.LiveView.Socket.t(), assigns :: list() | map()) ::
  Phoenix.LiveView.Socket.t()

Same as set_state/3 but with a list or map of assigns.

Link to this macro

set_state(socket, state, value)

View Source (macro)

Specs

set_state(
  socket :: Phoenix.LiveView.Socket.t(),
  state :: atom(),
  value :: any()
) :: Phoenix.LiveView.Socket.t()

Assign the state to the socket and return the socket. This will also trigger re-calculation of any computed state. If you do not wish to do this, use Phoenix.LiveView.assign/3 instead.

If the given state is has not been declared as a state, it will be ignored.

Link to this macro

set_state!(socket, assigns)

View Source (macro)

Specs

set_state!(socket :: Phoenix.LiveView.Socket.t(), assigns :: list() | map()) ::
  Phoenix.LiveView.Socket.t()

Same as set_state/2 but raises if passed an invalid state

Link to this macro

set_state!(socket, state, value)

View Source (macro)

Specs

set_state!(
  socket :: Phoenix.LiveView.Socket.t(),
  state :: atom(),
  value :: any()
) :: Phoenix.LiveView.Socket.t()

Same as set_state/3 but raises if passed an invalid state

Link to this macro

state(name, type, opts \\ [])

View Source (macro)

Specs

state(name :: atom(), type :: atom(), opts :: list()) :: :ok

Define state of given name and type. Returns :ok.

Types can be any atom and are just for documentation purposes.

Options:

  • :default - A default value that will be assigned on mount.
  • :compute - 1-arity function that takes the socket as an argument and returns the value to be assigned. Can be an atom of the name of a function in your component or a remote function call like &MyModule.compute/1. If you use an atom, the referenced function must be public.
  • :after_connect - boolean. Only applies in LiveViews. Setting this to true will cause the initial value to be computed asynchronously after the socket connects.