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
@type diff_state() :: Emerge.Engine.DiffState.t()
Incremental diff state used between tree uploads and patches.
Functions
@spec diff_state_new(Emerge.tree() | nil) :: diff_state()
Initialize a diff state for incremental updates.
@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}.
@spec dispatch_click(diff_state(), binary()) :: :ok
Dispatch a click event to the handler registered for an element id.
@spec dispatch_event(diff_state(), binary(), term()) :: :ok
Dispatch an element event to the handler registered for an element id.
@spec dispatch_event(diff_state(), binary(), term(), term()) :: :ok
Dispatch an element event with payload to the registered handler.
@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}.
@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.
@spec lookup_event(diff_state(), binary(), term()) :: {:ok, {pid(), term()}} | :error
Lookup the handler payload for an element event.