View Source Love.View (love_ex v0.2.0)
Extend LiveViews.
Add use Love.View
to a Phoenix.LiveView
. This adds:
@behaviour Love.Events
for the optionalLove.Events.handle_message/4
callbackimport Love.View
to make macros and functions locally available- Hooks into
mount
andhandle_info
Link to this section Summary
Field Definitions
Defines a state assign.
Functions
Updates state assigns.
Link to this section Field Definitions
Defines a state assign.
State is internal to the view and is modified via put_state/2
.
options
Options
:default
- optional; if specified, the state will be assigned the default value during mount. The expression for the default value is wrapped in a function and its evaluation is deferred until runtime at the moment the view is mounted. If not specified, you shouldput_state/2
during view initialization to set an initial value.
example
Example
# State with no initial value
state :changeset
# State with an initial value, evaluated during mount
state :now, default: DateTime.utc_now()
Link to this section Functions
@spec put_state(Phoenix.LiveView.Socket.t(), map() | keyword()) :: Phoenix.LiveView.Socket.t()
Updates state assigns.
When called outside of a reactive function, any reactive functions that depend on the changed
state will be immediately evaluated, so call this function as infrequently as possible. In
other words, try to batch state changes and limit put_state/2
calls to once per function.
Within a reactive function, any additionally-triggered reactive functions will be deferred until after the current reactive function completely executes.
Returns the socket with the new state and after any reactive callbacks have run.
example
Example
state :first_name
put_state(socket, first_name: "Marvin")