| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- data PatchElements = PatchElements {}
- patchElements :: Text -> PatchElements
- removeElements :: Text -> PatchElements
- toDatastarEvent :: PatchElements -> DatastarEvent
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
| |
Instances
| Show PatchElements Source # | |
Defined in Hypermedia.Datastar.PatchElements Methods showsPrec :: Int -> PatchElements -> ShowS # show :: PatchElements -> String # showList :: [PatchElements] -> ShowS # | |
| Eq PatchElements Source # | |
Defined in Hypermedia.Datastar.PatchElements Methods (==) :: PatchElements -> PatchElements -> Bool # (/=) :: PatchElements -> PatchElements -> Bool # | |
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"