datastar-hs-0.1.0.1: Haskell bindings for Datastar
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hypermedia.Datastar.PatchElements

Description

"Patch elements" is Datastar's primary mechanism for updating the page: the server sends an HTML fragment and the browser morphs it into the DOM. The morphing algorithm preserves focus, scroll position, and CSS transitions, so partial page updates feel seamless.

The simplest case — send HTML and let Datastar match elements by id — needs only patchElements:

sendPatchElements gen (patchElements "<div id=\"count\">42</div>")

To customise the patching behaviour, use record update syntax on the result of patchElements:

sendPatchElements gen
  (patchElements "<li>new item</li>")
    { peSelector = Just "#todo-list"
    , peMode = Append
    }

To remove elements from the DOM, use removeElements with a CSS selector:

sendPatchElements gen (removeElements "#flash-message")
Synopsis

Documentation

data PatchElements Source #

Configuration for a datastar-patch-elements SSE event.

Construct values with patchElements or removeElements, then customise with record updates.

Constructors

PatchElements 

Fields

patchElements :: Text -> PatchElements Source #

Build a PatchElements event with sensible defaults.

The HTML is sent as-is and Datastar matches target elements by their id attribute.

patchElements "<div id=\"greeting\">Hello!</div>"

removeElements :: Text -> PatchElements Source #

Remove elements from the DOM matching a CSS selector.

removeElements "#notification"
removeElements ".stale-row"