Nex.Store
(nex_core v0.4.3)
Copy Markdown
Page-scoped state management for Nex applications.
Provides simple key-value storage isolated by page view, similar to React/Vue state - refresh the page and state is gone.
Usage
# In a Page module
def mount(_params) do
%{title: "Todos", todos: Nex.Store.get(:todos, [])}
end
def create_todo(%{"text" => text}) do
todo = %{id: unique_id(), text: text, completed: false}
Nex.Store.update(:todos, [], &[todo | &1])
# ...
endState is tied to a _page_id that is generated on first page render.
HTMX requests carry this _page_id to maintain state within the same page view.
Refreshing the page generates a new _page_id, effectively clearing state.
TTL & Cleanup
Each page's state has a TTL (default 1 hour). After TTL expires, state is automatically cleaned up to prevent memory leaks.
Summary
Functions
Returns a specification to start this module under a supervisor.
Delete all state for a page
Clear page_id from process dictionary (called by Nex.Handler after request)
Delete value from page store
Generate a new page ID
Get value from page store
Get current page ID from process dictionary
Put value into page store
Set current page ID in process dictionary (called by Nex.Handler)
Update value in page store
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Delete all state for a page
Clear page_id from process dictionary (called by Nex.Handler after request)
Delete value from page store
Generate a new page ID
Get value from page store
Get current page ID from process dictionary
Put value into page store
Set current page ID in process dictionary (called by Nex.Handler)
Update value in page store