Skip to content

Commit

Permalink
Merge pull request #284 from github/use-shadowroot-host-instead-of-we…
Browse files Browse the repository at this point in the history
…akmap

use shadowroot.host instead of weakmap
  • Loading branch information
keithamus authored Oct 10, 2022
2 parents c220489 + 02f60fa commit 09a63b3
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/targetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ const [targets, getTargets, initializeTargets] = createMark<Element>(

function setTarget(el: Element, controller: Element | ShadowRoot, tag: string, key: string): void {
const get = tag === 'data-targets' ? getTargets : getTarget
if (controller instanceof ShadowRoot) {
controller = controllers.get(controller)!
}
if (controller instanceof ShadowRoot) controller = controller.host

if (controller && get(controller)?.has(key)) {
;(controller as unknown as Record<PropertyKey, unknown>)[key] = {}
}
Expand All @@ -67,7 +66,6 @@ function setTarget(el: Element, controller: Element | ShadowRoot, tag: string, k
registerTag('data-target', (str: string) => str.split('.'), setTarget)
registerTag('data-targets', (str: string) => str.split('.'), setTarget)
const shadows = new WeakMap<Element, ShadowRoot>()
const controllers = new WeakMap<ShadowRoot, Element>()

const findTarget = (controller: Element, selector: string, many: boolean) => () => {
const nodes = []
Expand Down Expand Up @@ -113,7 +111,6 @@ export const targetable = createAbility(
[attachShadowCallback](root: ShadowRoot) {
super[attachShadowCallback]?.(root)
shadows.set(this, root)
controllers.set(root, this)
observeElementForTags(root)
}
}
Expand Down

0 comments on commit 09a63b3

Please sign in to comment.