-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiring-dom-only-stamp.ts
32 lines (30 loc) · 1.05 KB
/
wiring-dom-only-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
import { Component, ComponentContext } from './component.js'
import { StampCollection } from './stamp-collection.js'
import { selectBindings } from './stamp-collector.js'
import { DomStrategy } from './wiring-context.js'
const stampOnlyStrategy: (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 DocumentFragment
return {
...selectBindings(container, component(properties, context)),
isSameContainer: false,
}
}
throw new Error(`Stamp "${component.name}" not found`)
}
export default stampOnlyStrategy