StarView.Actions (star_view v0.7.0)

Copy Markdown View Source

Datastar action expression helpers.

These helpers generate strings for data-on:* attributes:

<button data-on:click={StarView.Actions.post(MyAppWeb.CounterController, "increment")}>

Event names and literal module overrides are percent-encoded as one URL path segment. The default dynamic module signal is encoded in the browser too. Empty and exact dot segments are rejected because browsers normalize them.

A :prefix must be a local application path containing no dot segments, backslashes, queries, fragments, controls, or URL scheme. Safe relative paths such as "admin" are normalized to "/admin" for compatibility. A dynamic :module override is a literal value, never JavaScript source. Custom $-prefixed overrides raise; only "$_star_view_module" retains the default dynamic signal behavior. Action strings use JSON double quotes.

Pass :opts to include a Datastar fetch options object, for example opts: "{retry: 'never', retryMaxCount: 0}". This is trusted developer JavaScript emitted verbatim, never submitted signal values. The controller, page and component helpers use the same options contract.

Summary

Functions

Decodes a URL-safe module name into an existing Elixir module.

Generates a @delete(...) Datastar action expression.

Encodes an Elixir module name for URL path usage.

Generates a @get(...) Datastar action expression.

Generates a @patch(...) Datastar action expression.

Generates a @post(...) Datastar action expression.

Generates a @put(...) Datastar action expression.

Functions

decode_module(encoded)

@spec decode_module(String.t()) :: {:ok, module()} | :error

Decodes a URL-safe module name into an existing Elixir module.

delete(module_or_event, event_or_opts \\ [])

Generates a @delete(...) Datastar action expression.

delete(module, event, opts)

encode_module(module)

@spec encode_module(module()) :: String.t()

Encodes an Elixir module name for URL path usage.

get(module_or_event, event_or_opts \\ [])

Generates a @get(...) Datastar action expression.

get(module, event, opts)

patch(module_or_event, event_or_opts \\ [])

Generates a @patch(...) Datastar action expression.

patch(module, event, opts)

post(module_or_event, event_or_opts \\ [])

Generates a @post(...) Datastar action expression.

post(module, event, opts)

put(module_or_event, event_or_opts \\ [])

Generates a @put(...) Datastar action expression.

put(module, event, opts)