Helper functions for using Lavash components in LiveViews.
Summary
Functions
Gets the state for a specific component by ID.
Extracts component states from connect_params and stores them in socket assigns.
Builds the optimistic state map for a component.
Functions
Gets the state for a specific component by ID.
Extracts component states from connect_params and stores them in socket assigns.
Call this in your LiveView's mount/3:
def mount(_params, _session, socket) do
socket = Lavash.Component.Helpers.init_component_states(socket)
{:ok, socket}
endThen pass the state to components:
<.live_component
module={MyComponent}
id="my-component"
__lavash_initial_state__={Lavash.Component.Helpers.get_component_state(@__lavash_component_states__, "my-component")}
/>
Builds the optimistic state map for a component.
This is used to expose component state via data attributes for potential client-side access (without a JavaScript hook).