Skip to content

Commit

Permalink
cleanup DOMInjector
Browse files Browse the repository at this point in the history
  • Loading branch information
deebloo committed Jan 14, 2025
1 parent fd30636 commit c8acd09
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/di/src/lib/dom-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { INJECTOR_CTX } from './context/injector.js';
import { Injector } from './injector.js';

export class DOMInjector extends Injector {
#element: HTMLElement | null = null;
#controller: AbortController | null = null;

attach(element: HTMLElement): void {
this.#element = element;
this.#controller = new AbortController();

this.#element.addEventListener(
element.addEventListener(
'context-request',
(e: ContextRequestEvent<UnknownContext>) => {
if (e.context === INJECTOR_CTX) {
if (e.target !== this.#element) {
if (e.target !== element) {
e.stopPropagation();

e.callback(this);
Expand All @@ -24,7 +22,7 @@ export class DOMInjector extends Injector {
{ signal: this.#controller.signal }
);

this.#element.dispatchEvent(
element.dispatchEvent(
new ContextRequestEvent(INJECTOR_CTX, (parent) => {
this.setParent(parent);
})
Expand Down

0 comments on commit c8acd09

Please sign in to comment.