Skip to content

Commit

Permalink
fix: web components tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hanako-eo committed Nov 18, 2023
1 parent 017cf16 commit 9026c5e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export function define<T extends Record<string, any>>(name: string, component: N
this.#reactiveProps[reactiveAttribute] = createReactor<string>(component.defaultProps?.[reactiveAttribute])
}

for (let i = 0; i < this.attributes.length; i++) {
const name = this.attributes[i].nodeName
const value = this.attributes[i].nodeValue
const attributes = Array.from(this.attributes)
for (let i = 0; i < attributes.length; i++) {
const name = attributes[i].name
const value = attributes[i].value

if (attributeCast && reactiveAttributes && reactiveAttributes.includes(name)) {
if (name in attributeCast)
this.props[name] = this.#reactiveProps[name].compute((value) => {
Expand All @@ -58,7 +60,9 @@ export function define<T extends Record<string, any>>(name: string, component: N
else if (attributeCast[name] === Boolean)
this.props[name] = true
else this.props[name] = (attributeCast[name] as Function)(this, value)
} else this.props[name] = value
} else {
this.props[name] = value
}
}

for (const name in this.#reactiveProps) {
Expand All @@ -79,10 +83,9 @@ export function define<T extends Record<string, any>>(name: string, component: N

setContextParent(this.#context)
this.#parent.append(...generateDOM(
toArray(hComp(component, this.props, null, Array.from(this.childNodes))),
toArray(hComp(component, this.props, null, Array.from(this.childNodes), this.#context)),
this.#parent as Element
))
this.#context.mounted.forEach((handle) => handle())
}

disconnectedCallback() {
Expand Down Expand Up @@ -226,7 +229,8 @@ function hComp(
component: NoConditionalComponent<any>,
props: Props,
fallback: any,
children: Array<JSX.Element>
children: Array<JSX.Element>,
executionContext?: InternalContext
): ElementGiver<HTMLElement, any> {
const properties = Object.assign({}, component.defaultProps, props)

Expand All @@ -236,7 +240,7 @@ function hComp(
}

return extend(unique((parent: Element, previousSibling?: Element | Text) => {
const context = createInternalContext(component, null)
const context = executionContext ?? createInternalContext(component, null)

context.moduleContext.props = properties
if ("when" in props && !component.metadata?.noconditional) context.assemblyCondition = props["when"]
Expand Down

0 comments on commit 9026c5e

Please sign in to comment.