Skip to content

Commit

Permalink
move bodyScope to getter and use documentElement instead of body
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Sep 5, 2022
1 parent 4c2c466 commit f967595
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/scope.ts
Expand Up @@ -22,9 +22,7 @@ export class Scope {
this.element = element
this.identifier = identifier
this.guide = new Guide(logger)

const bodyScope = (element === document.body) ? this : new Scope(schema, document.body, identifier, logger)
this.outlets = new OutletSet(bodyScope, element)
this.outlets = new OutletSet(this.documentScope, element)
}

findElement(selector: string): Element | undefined {
Expand All @@ -51,4 +49,12 @@ export class Scope {
private get controllerSelector(): string {
return attributeValueContainsToken(this.schema.controllerAttribute, this.identifier)
}

private get isDocumentScope() {
return this.element === document.documentElement
}

private get documentScope(): Scope {
return this.isDocumentScope ? this : new Scope(this.schema, document.documentElement, this.identifier, this.guide.logger)
}
}

0 comments on commit f967595

Please sign in to comment.