-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathstream_actions.ts
36 lines (28 loc) · 1019 Bytes
/
stream_actions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { StreamElement } from "../../elements/stream_element"
export type TurboStreamAction = (this: StreamElement) => void
export type TurboStreamActions = { [action: string]: TurboStreamAction }
export const StreamActions: TurboStreamActions = {
after() {
this.targetElements.forEach((e) => e.parentElement?.insertBefore(this.templateContent, e.nextSibling))
},
append() {
this.removeDuplicateTargetChildren()
this.targetElements.forEach((e) => e.append(this.templateContent))
},
before() {
this.targetElements.forEach((e) => e.parentElement?.insertBefore(this.templateContent, e))
},
prepend() {
this.removeDuplicateTargetChildren()
this.targetElements.forEach((e) => e.prepend(this.templateContent))
},
remove() {
this.targetElements.forEach((e) => e.remove())
},
replace() {
this.targetElements.forEach((e) => e.replaceWith(this.templateContent))
},
update() {
this.targetElements.forEach((e) => e.replaceChildren(this.templateContent))
},
}