OctaStar.Signals (octa_star v0.1.0)

Copy Markdown

Datastar signal reading and datastar-patch-signals helpers.

Summary

Functions

Formats a signal patch without writing to a connection.

Formats a raw JSON signal patch without writing to a connection.

Formats a signal removal without writing to a connection.

Sends a signal patch from a map.

Sends a signal patch from a JSON string.

Reads Datastar signals from a Plug connection.

Reads Datastar signals and raises on errors.

Removes one or more signals by setting dot-notated paths to null.

Functions

format_patch(signals, opts \\ [])

@spec format_patch(
  map(),
  keyword()
) :: String.t()

Formats a signal patch without writing to a connection.

format_patch_raw(signals_json, opts \\ [])

@spec format_patch_raw(
  String.t(),
  keyword()
) :: String.t()

Formats a raw JSON signal patch without writing to a connection.

format_remove(paths, opts \\ [])

@spec format_remove(
  String.t() | [String.t()],
  keyword()
) :: String.t()

Formats a signal removal without writing to a connection.

patch(conn, signals, opts \\ [])

@spec patch(Plug.Conn.t(), map(), keyword()) :: Plug.Conn.t()

Sends a signal patch from a map.

patch_raw(conn, signals_json, opts \\ [])

@spec patch_raw(Plug.Conn.t(), String.t(), keyword()) :: Plug.Conn.t()

Sends a signal patch from a JSON string.

read(conn)

@spec read(Plug.Conn.t()) :: {:ok, map()} | {:error, term()}

Reads Datastar signals from a Plug connection.

GET and DELETE requests read the datastar query parameter. Other methods read JSON from the request body unless a parser has already populated conn.body_params.

read!(conn)

@spec read!(Plug.Conn.t()) :: map()

Reads Datastar signals and raises on errors.

remove_signals(conn, paths, opts \\ [])

@spec remove_signals(Plug.Conn.t(), String.t() | [String.t()], keyword()) ::
  Plug.Conn.t()

Removes one or more signals by setting dot-notated paths to null.