Lavash.Socket (Lavash v0.3.0-rc.1)

Copy Markdown View Source

Helpers for accessing Lavash private socket data.

Both state and derived values live in socket.assigns (leveraging Phoenix change tracking). Metadata (dirty set, field name sets, flags) lives in socket.private.lavash.

Summary

Functions

Bumps the optimistic version counter.

Clears the dirty set.

Clears socket changed flag.

Clears URL changed flag.

Gets full state merged with derived values.

Gets the entire Lavash private data map.

Gets a specific key from Lavash private data.

Gets a value from state.

Initializes the Lavash private data structure on the socket.

Marks fields as dirty.

Puts a value into Lavash private data.

Puts a derived value directly into assigns. Raw values (including Lavash.Form, AsyncResult) are stored as-is.

Puts a value into state, marking the field as dirty. Also tracks URL/socket changes if applicable. Eagerly writes to assigns so projection is not needed.

Registers a child component for invalidation forwarding.

Gets all registered components.

Updates a value in Lavash private data using a function.

Functions

bump_optimistic_version(socket)

Bumps the optimistic version counter.

Called when processing an event that triggers optimistic updates. The version is included in the rendered HTML and compared by the client to detect and reject stale DOM patches.

clear_dirty(socket)

Clears the dirty set.

clear_socket_changed(socket)

Clears socket changed flag.

clear_url_changed(socket)

Clears URL changed flag.

derived(socket)

dirty(socket)

dirty?(socket)

full_state(socket)

Gets full state merged with derived values.

get(socket)

Gets the entire Lavash private data map.

get(socket, key)

Gets a specific key from Lavash private data.

get_state(socket, field)

Gets a value from state.

init(socket, opts \\ %{})

Initializes the Lavash private data structure on the socket.

mark_dirty(socket, fields)

Marks fields as dirty.

optimistic_version(socket)

props(socket)

put(socket, key, value)

Puts a value into Lavash private data.

put_derived(socket, field, value)

Puts a derived value directly into assigns. Raw values (including Lavash.Form, AsyncResult) are stored as-is.

put_state(socket, field, value)

Puts a value into state, marking the field as dirty. Also tracks URL/socket changes if applicable. Eagerly writes to assigns so projection is not needed.

register_component(socket, id, module, resources)

Registers a child component for invalidation forwarding.

registered_components(socket)

Gets all registered components.

socket_changed?(socket)

socket_field?(socket, field)

state(socket)

update(socket, key, fun)

Updates a value in Lavash private data using a function.

url_changed?(socket)

url_field?(socket, field)