StarView.Dispatch (star_view v0.7.0)

Copy Markdown View Source

Marker-based Datastar dispatch for Phoenix controllers.

A controller is dispatchable when it uses use StarView, which injects __star_view_handler__/0.

What this plug does

  1. Fetches object-only signals from JSON body or the Datastar query parameter.
  2. Starts the SSE response (StarView.start/1).
  3. Calls handle_event/3 on the target controller.
  4. Lets signal/3 patch browser signals immediately as your handler runs.

This means your handle_event/3 callbacks never need to call StarView.start/1 or manually send signal patches -- just use signal/3 and patch_element/3.

Malformed signals return HTTP 400 and oversized signals return 413 before SSE or the handler starts. A typed StarView.SSE.TransportError with reason :closed, :econnreset, or :epipe halts normally; other exceptions are logged and re-raised. Route authentication and per-event authorization remain the application's job.

An optional :only module list narrows marker dispatch for a route. It never bypasses the marker requirement. The default preserves legacy dispatch; the new router macros use this list for explicit read-only GET component routes.