LiveEx.Example (live_ex v0.3.1) View Source

Example Implementation of a LiveEx Store that is used by Phoenix.LiveViews.

Link to this section Summary

Functions

Commit a change to the store.

Dispatch an Action with a type and an optional payload.

Handles a dispatch and commits a mutation based on the payload of the action.

Call this function from the mount/2 function of your "root"-LiveView.

Configures the socket with an initial setup.

Mutates the :no_payload variable of the store.

Link to this section Types

Link to this section Functions

Link to this function

commit(type, payload, socket)

View Source

Specs

commit(atom() | String.t(), any(), socket()) :: {:noreply, socket()}

Commit a change to the store.

Link to this function

dispatch(type, payload \\ nil, socket)

View Source

Specs

dispatch(String.t(), any(), socket()) :: :ok | {:error, term()}

Dispatch an Action with a type and an optional payload.

Link to this function

handle_info(action, socket)

View Source

Specs

handle_info(%{type: String.t(), payload: map()}, socket()) ::
  {:noreply, socket()}

Handles a dispatch and commits a mutation based on the payload of the action.

action here has the format: %{type: :a_type_here, payload: %{}}

Specs

init(socket()) :: socket()

Call this function from the mount/2 function of your "root"-LiveView.

Adds the initial state variables to the socket.assigns and returns the updated LiveView.Socket.

Specs

init(map(), socket()) :: socket()

Configures the socket with an initial setup.

The pid of the parent process is stored in the socket.assigns so that Child processes can dispatch Actions on the parents's Store.

Specs

no_payload(map(), socket()) :: socket()

Mutates the :no_payload variable of the store.

Link to this function

with_payload(payload, socket)

View Source

Specs

with_payload(map(), socket()) :: socket()