live_props v0.2.2 LiveProps.States View Source
Functions for working with states. These will be imported
whenever you use
LiveProps.LiveComponent or LiveProps.LiveView
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
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
)
Specs
A replacement for Phoenix.LiveView.send_update/2
. Invalid states will be ignored.
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.
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.
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
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
Specs
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 assigns 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.