PhoenixLiveViewExt.Listilled behaviour (phoenix_live_view_ext v1.1.0) View Source

Listilled behaviour should be implemented by the modules (e.g. LiveView components) assuming the concern of their state-to-assigns transformation where such assigns then need to get compared and diffed (listilled) by the Listiller before getting actually assigned for the LiveComponent list rendering. This is to avoid updating (replacing) the appended (or prepended) container list with elements that haven't really changed which for LiveView is the default behavior when dealing with element lists.

LiveComponent templates rendered by relying on the assigns constructed with this module need to take into account the :updated assign and interpret it according to the updated/0 docs. The same is also used in the Javascript element sorting code.

Link to this section Summary

Types

  • :noop instructs of patching without sorting; intended for actual element updates or :full insertions (replacements)
  • :delete instructs of rendering the marked-for-deletion variation of the LiveComponent element
  • { :sort, dst_id :: String.t()} instructs of sorting the element i.e. inserting it before the provided destination dom id.

Callbacks

Returns the component id string representation of the provided element diff id.

Constructs component assigns from the provided model state.

Returns the list of all element diff ids along with the provided state with its last moment updates if any.

Checks if any distilling-relevant portion of the provided state has changed. This is an optional callback that, if defined, is invoked before distilling any assigns from the state. It should be defined to provide simple, comparison based checking as an alternative to constructing assigns if there are no changes in the state.

Link to this section Types

Specs

assigns() :: %{:updated => updated(), optional(atom()) => any()}

Specs

state() :: term() | nil

Specs

updated() :: :noop | :delete | {:sort, dst_id :: String.t()}
  • :noop instructs of patching without sorting; intended for actual element updates or :full insertions (replacements)
  • :delete instructs of rendering the marked-for-deletion variation of the LiveComponent element
  • { :sort, dst_id :: String.t()} instructs of sorting the element i.e. inserting it before the provided destination dom id.

Link to this section Callbacks

Specs

component_id(diff_id()) :: String.t()

Returns the component id string representation of the provided element diff id.

Link to this callback

construct_assigns(state, diff_id)

View Source

Specs

construct_assigns(state(), diff_id()) :: assigns()

Constructs component assigns from the provided model state.

Specs

prepare_list(state()) :: {[diff_id()], state()}

Returns the list of all element diff ids along with the provided state with its last moment updates if any.

Link to this callback

state_changed?(old, new)

View Source (optional)

Specs

state_changed?(old :: state(), new :: state()) :: boolean()

Checks if any distilling-relevant portion of the provided state has changed. This is an optional callback that, if defined, is invoked before distilling any assigns from the state. It should be defined to provide simple, comparison based checking as an alternative to constructing assigns if there are no changes in the state.