Skip to content

Commit

Permalink
refactor: BaseComponent log
Browse files Browse the repository at this point in the history
  • Loading branch information
ochairo committed Mar 27, 2024
1 parent 8c3556b commit 7883617
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/app/infrastructure/base-component/base.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/**
* Base class for custom elements that provides lifecycle hooks.
* Base class for custom elements
*/
export default class BaseComponent extends HTMLElement {
connectedCallback() {
this.onInit(); // Custom hook for initialization
console.log("[BaseComponent] Element connected to the DOM");
this.onInit();
}

disconnectedCallback() {
this.onDestroy(); // Custom hook for cleanup
console.log("[BaseComponent] Element disconnected from the DOM");
this.onDestroy();
}

attributeChangedCallback(
name: string,
oldValue: string | null,
newValue: string | null
) {
this.onAttributeChanged(name, oldValue, newValue); // Custom hook for attribute changes
console.log("[BaseComponent] Attribute changed");
this.onAttributeChanged(name, oldValue, newValue);
}

// Custom lifecycle hooks, can be overridden in child classes
Expand All @@ -28,12 +31,13 @@ export default class BaseComponent extends HTMLElement {
}

protected onAttributeChanged(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
name: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
oldValue: string | null,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
newValue: string | null
) {
console.log(
`Attribute '${name}' changed from '${oldValue}' to '${newValue}'`
);
// Default implementation for attribute changes
}
}

0 comments on commit 7883617

Please sign in to comment.