Dala.Ui.Socket (dala v0.0.8)

Copy Markdown View Source

The socket struct passed through all Dala.Screen and Dala.Ui.NativeView callbacks.

Holds two things:

  • assigns — the public data map your render/1 function reads from @assigns
  • __dala__ — internal Dala metadata (screen module, platform, view refs, nav stack)

You interact with a socket via assign/2 and assign/3. Never mutate __dala__ directly — it is an internal contract.

Summary

Functions

Assign multiple key/value pairs at once from a keyword list or map.

Assign a single key/value pair into the socket's assigns.

Check if specific key(s) have changed since the last render.

Clear the changed set after a render.

Get a value from the internal __dala__ metadata.

Create a new socket for the given screen module.

Queue a pop_screen navigation action.

Queue a pop_to navigation action.

Queue a pop_to_root navigation action.

Queue a push_screen navigation action.

Put a value into the internal __dala__ metadata.

Store the root view ref returned by the renderer into __dala__.root_view. Called internally after the initial render.

Queue a reset_to navigation action.

Types

platform()

@type platform() :: :android | :ios

t()

@type t() :: %Dala.Ui.Socket{
  __dala__: %{
    screen: module() | nil,
    platform: platform(),
    root_view: term(),
    view_tree: map(),
    nav_stack: list(),
    nav_action: term()
  },
  assigns: map()
}

Functions

assign(socket, kw)

@spec assign(t(), keyword() | map()) :: t()

Assign multiple key/value pairs at once from a keyword list or map.

socket = assign(socket, count: 0, name: "test")
socket = assign(socket, %{count: 0})

assign(socket, key, value)

@spec assign(t(), atom(), term()) :: t()

Assign a single key/value pair into the socket's assigns.

socket = assign(socket, :count, 0)

changed?(socket, keys)

@spec changed?(t(), atom() | [atom()]) :: boolean()

Check if specific key(s) have changed since the last render.

Returns true if all keys were assigned since the last render. Accepts a single atom or a list of atoms.

clear_changed(socket)

@spec clear_changed(t()) :: t()

Clear the changed set after a render.

Called internally after rendering to reset the change tracking.

get_dala(socket, key)

@spec get_dala(t(), atom()) :: term()

Get a value from the internal __dala__ metadata.

Used internally by the screen process.

get_dala(socket, key, default)

@spec get_dala(t(), atom(), term()) :: term()

new(screen, opts \\ [])

@spec new(
  module(),
  keyword()
) :: t()

Create a new socket for the given screen module.

Options:

  • :platform:android (default) or :ios

pop_screen(socket)

@spec pop_screen(t()) :: t()

Queue a pop_screen navigation action.

Pops the current screen from the navigation stack.

pop_to(socket, dest)

@spec pop_to(t(), module() | atom()) :: t()

Queue a pop_to navigation action.

Pops screens until the target module is at the top of the stack.

pop_to_root(socket)

@spec pop_to_root(t()) :: t()

Queue a pop_to_root navigation action.

Pops all screens except the root.

push_screen(socket, dest, params \\ %{})

@spec push_screen(t(), module(), map()) :: t()

Queue a push_screen navigation action.

The screen process will process this on the next render cycle.

put_dala(socket, key, value)

@spec put_dala(t(), atom(), term()) :: t()

Put a value into the internal __dala__ metadata.

Used internally by the screen process.

put_root_view(socket, view)

@spec put_root_view(t(), term()) :: t()

Store the root view ref returned by the renderer into __dala__.root_view. Called internally after the initial render.

reset_to(socket, dest, params \\ %{})

@spec reset_to(t(), module() | atom(), map()) :: t()

Queue a reset_to navigation action.

Replaces the entire navigation stack with a fresh screen.