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 optional Love.Events.handle_message/4 callback
  • import Love.View to make macros and functions locally available
  • Hooks into mount and handle_info

Link to this section Summary

Field Definitions

Defines a state assign.

Functions

Updates state assigns.

Link to this section Field Definitions

Link to this macro

state(key, opts \\ [])

View Source (macro)
@spec state(key :: atom(), opts :: keyword()) :: nil

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 should put_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

Link to this function

put_state(socket, changes)

View Source

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")