Skip to content

Commit fd49b12

Browse files
committed
Add elements-sugar and elements files with merge functionality and tests
1 parent cd270ed commit fd49b12

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

sdk/go/datastar/fragments-sugar.go renamed to sdk/go/datastar/elements-sugar.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,24 @@ func PatchSSE(urlFormat string, args ...any) string {
180180
func DeleteSSE(urlFormat string, args ...any) string {
181181
return fmt.Sprintf(`@delete('%s')`, fmt.Sprintf(urlFormat, args...))
182182
}
183+
184+
// RemoveElement is a convenience method for removing elements from the DOM.
185+
// It uses MergeElements with the remove merge mode and the specified selector.
186+
func (sse *ServerSentEventGenerator) RemoveElement(selector string, opts ...MergeElementOption) error {
187+
// Prepend the remove mode option
188+
allOpts := append([]MergeElementOption{WithMergeRemove(), WithSelector(selector)}, opts...)
189+
return sse.MergeElements("", allOpts...)
190+
}
191+
192+
// RemoveElementf is a convenience wrapper for RemoveElement that formats the selector string
193+
// using the provided format and arguments similar to fmt.Sprintf.
194+
func (sse *ServerSentEventGenerator) RemoveElementf(selectorFormat string, args ...any) error {
195+
selector := fmt.Sprintf(selectorFormat, args...)
196+
return sse.RemoveElement(selector)
197+
}
198+
199+
// RemoveElementByID is a convenience wrapper for RemoveElement that removes an element by its ID.
200+
// Equivalent to calling RemoveElement("#"+id).
201+
func (sse *ServerSentEventGenerator) RemoveElementByID(id string) error {
202+
return sse.RemoveElement("#" + id)
203+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)