-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiring-dom-stamp.ts
39 lines (37 loc) · 1.26 KB
/
wiring-dom-stamp.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
37
38
39
import type { Component, ComponentContext } from './component.js'
import type { StampCollection } from './stamp-collection.js'
import { selectBindings } from './stamp-collector.js'
import { buildTree } from './static-dom.js'
import type { DomStrategy } from './wiring-context.js'
const stampOrBuildStrategy: (stamps: StampCollection) => DomStrategy =
(stamps: StampCollection) =>
(
component: Component,
properties: unknown,
context: ComponentContext,
container: Element | DocumentFragment | undefined,
document: Document,
) => {
if (container && stamps.isPrestamp(component, properties, container)) {
return {
...selectBindings(container, component(properties, context)),
isSameContainer: true,
}
}
const stamp = stamps.getStamp(component, properties)
if (stamp) {
const container = stamp.content.cloneNode(true) as
| Element
| DocumentFragment
return {
...selectBindings(container, component(properties, context)),
isSameContainer: false,
}
}
const tree = component(properties, context)
return {
...buildTree(tree, undefined, undefined, undefined, undefined, document),
isSameContainer: false,
}
}
export default stampOrBuildStrategy