-
Notifications
You must be signed in to change notification settings - Fork 429
/
stream_actions.js
55 lines (45 loc) · 1.36 KB
/
stream_actions.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { session } from "../"
import { morphElements, morphChildren } from "../morphing"
export const StreamActions = {
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() {
const method = this.getAttribute("method")
this.targetElements.forEach((targetElement) => {
if (method === "morph") {
morphElements(targetElement, this.templateContent)
} else {
targetElement.replaceWith(this.templateContent)
}
})
},
update() {
const method = this.getAttribute("method")
this.targetElements.forEach((targetElement) => {
if (method === "morph") {
morphChildren(targetElement, this.templateContent)
} else {
targetElement.innerHTML = ""
targetElement.append(this.templateContent)
}
})
},
refresh() {
session.refresh(this.baseURI, this.requestId)
}
}