Action handling for hyper applications.
Actions are server-side functions triggered by client interactions.
Action handling for hyper applications. Actions are server-side functions triggered by client interactions.
(build-action-expr action-id used-params js base-path)Build the Datastar/JS expression string for an action. Always uses Datastar's @post() so that all non-underscore signals are automatically sent in the request body. When client params are present, they are URL-encoded into the query string via the hyper.encodeClientParams helper so the server can read them from query-params. Optionally injects a custom Datastar expression to conditionally prevent the post. base-path is prepended to the /hyper/actions endpoint (empty string when not set).
Build the Datastar/JS expression string for an action. Always uses Datastar's @post() so that all non-underscore signals are automatically sent in the request body. When client params are present, they are URL-encoded into the query string via the hyper.encodeClientParams helper so the server can read them from query-params. Optionally injects a custom Datastar expression to conditionally prevent the post. base-path is prepended to the /hyper/actions endpoint (empty string when not set).
(cleanup-tab-actions! app-state* tab-id)Remove all actions for a tab. Used during tab disconnect.
Remove all actions for a tab. Used during tab disconnect.
(execute-action! app-state* action-id)(execute-action! app-state* action-id client-params)Execute an action by ID with error handling. When client-params are provided they are passed to the action fn.
Execute an action by ID with error handling. When client-params are provided they are passed to the action fn.
(register-action! app-state* session-id tab-id action-fn)(register-action! app-state* session-id tab-id action-fn action-id)(register-action! app-state* session-id tab-id action-fn action-id opts)Register an action function and return its ID. Stores in app-state under [:actions action-id].
When action-id is provided it is used as-is (deterministic actions). When omitted a random UUID is generated (legacy / dynamic actions).
opts may include:
Register an action function and return its ID. Stores in app-state under [:actions action-id]. When action-id is provided it is used as-is (deterministic actions). When omitted a random UUID is generated (legacy / dynamic actions). opts may include: - :as — a human-readable name for the action, useful for testing
(sanitize-guard g)Validate an action :when guard at runtime. Returns the guard string,
nil for nil/blank guards, and throws for anything else — a guard must
evaluate to a Datastar expression string (e.g. from expr or a raw
string).
Validate an action :when guard at runtime. Returns the guard string, nil for nil/blank guards, and throws for anything else — a guard must evaluate to a Datastar expression string (e.g. from `expr` or a raw string).
(sweep-stale-tab-actions! app-state* tab-id live-action-ids)Remove actions for a tab that were not re-registered during the last
render cycle. live-action-ids is the set of IDs collected by
*registered-action-ids* during render. Actions in that set are
kept; any other action belonging to this tab is removed.
This replaces the old cleanup-before-render pattern with a cleanup-after-render approach that eliminates the window where actions are missing.
Remove actions for a tab that were not re-registered during the last render cycle. `live-action-ids` is the set of IDs collected by `*registered-action-ids*` during render. Actions in that set are kept; any other action belonging to this tab is removed. This replaces the old cleanup-before-render pattern with a cleanup-after-render approach that eliminates the window where actions are missing.
(warn-deprecated-when!)Emit a deprecation warning for the action :when guard, steering callers to
the h/expr composition. Called at macro-expansion time.
Emit a deprecation warning for the `action :when` guard, steering callers to the `h/expr` composition. Called at macro-expansion time.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |