Emerge.Engine (Emerge v0.2.1)

Copy Markdown View Source

Retained tree diffing, encoding, and event routing helpers.

Summary

Types

Incremental diff state used between tree uploads and patches.

Functions

Initialize a diff state for incremental updates.

Compute patches for a new tree and return {patch_binary, next_state, assigned_tree}.

Dispatch a click event to the handler registered for an element id.

Dispatch an element event to the handler registered for an element id.

Dispatch an element event with payload to the registered handler.

Encode a full tree with ids and return {binary, next_state, assigned_tree}.

Encode a full tree and return {full_binary, patch_binary, next_state, assigned_tree}.

Lookup the handler payload for an element event.

Types

diff_state()

@type diff_state() :: Emerge.Engine.DiffState.t()

Incremental diff state used between tree uploads and patches.

Functions

diff_state_new(tree \\ nil)

@spec diff_state_new(Emerge.tree() | nil) :: diff_state()

Initialize a diff state for incremental updates.

diff_state_update(state, tree)

@spec diff_state_update(diff_state(), Emerge.tree()) ::
  {binary(), diff_state(), Emerge.tree()}

Compute patches for a new tree and return {patch_binary, next_state, assigned_tree}.

dispatch_click(state, id_bin)

@spec dispatch_click(diff_state(), binary()) :: :ok

Dispatch a click event to the handler registered for an element id.

dispatch_event(state, id_bin, event)

@spec dispatch_event(diff_state(), binary(), term()) :: :ok

Dispatch an element event to the handler registered for an element id.

dispatch_event(state, id_bin, event, payload)

@spec dispatch_event(diff_state(), binary(), term(), term()) :: :ok

Dispatch an element event with payload to the registered handler.

encode_full(state, tree)

@spec encode_full(diff_state(), Emerge.tree()) ::
  {binary(), diff_state(), Emerge.tree()}

Encode a full tree with ids and return {binary, next_state, assigned_tree}.

encode_full_with_empty_patch(state, tree)

@spec encode_full_with_empty_patch(diff_state(), Emerge.tree()) ::
  {binary(), binary(), diff_state(), Emerge.tree()}

Encode a full tree and return {full_binary, patch_binary, next_state, assigned_tree}.

The patch binary is always empty for initial uploads.

lookup_event(state, id_bin, event)

@spec lookup_event(diff_state(), binary(), term()) :: {:ok, {pid(), term()}} | :error

Lookup the handler payload for an element event.