Functions for reading and patching Datastar signals via SSE.
signals = PhoenixDatastar.Signals.read(conn)
sse |> patch(%{count: 42, message: "Hello"})
sse |> patch(%{count: 42}, only_if_missing: true)
Summary
Functions
Patches signals on the client by sending an SSE event.
Patches signals using a raw JSON string.
Reads signals from a Plug connection.
Functions
@spec patch(PhoenixDatastar.SSE.t(), map(), keyword()) :: PhoenixDatastar.SSE.t()
Patches signals on the client by sending an SSE event.
Options
:only_if_missing- Only patch signals that don't exist on the client (default: false):event_id- Event ID for client tracking:retry- Retry duration in milliseconds
Example
sse
|> PhoenixDatastar.Signals.patch(%{count: 42})
|> PhoenixDatastar.Signals.patch(%{message: "Hello"}, only_if_missing: true)
@spec patch_raw(PhoenixDatastar.SSE.t(), String.t(), keyword()) :: PhoenixDatastar.SSE.t()
Patches signals using a raw JSON string.
Example
sse
|> PhoenixDatastar.Signals.patch_raw(~s({"count": 42}))
@spec read(Plug.Conn.t()) :: map()
Reads signals from a Plug connection.
For GET requests, reads from query parameters under the "datastar" key. For other methods, reads from the JSON request body.
Returns a map of signals or an empty map if no signals are present.
Example
signals = PhoenixDatastar.Signals.read(conn)
# => %{"count" => 10, "message" => "Hello"}