Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: StoneyDSP <nathanjhood@googlemail.com>
  • Loading branch information
nathanjhood committed Oct 16, 2024
1 parent 25763dc commit 4862186
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import env from 'env';
import './App.css';
import logo = require('./logo.svg');

const App = () => {
const App = (): HTMLElement => {
//
const logoSrc = 'data:image/svg+xml;base64,' + logo;
//
if (!window.customElements.get('app-component')) {
console.log('constructing App()');
window.customElements.define(
'app-component',
/**
* The `AppComponent` class.
* @extends {HTMLElement}
*/
class AppComponent extends HTMLElement {
/**
Expand All @@ -23,54 +26,62 @@ const App = () => {
*
*/
private setup(): void {
console.debug('setup()');
const shadowRoot: ShadowRoot = this.attachShadow({ mode: 'open' });
if (shadowRoot) {
shadowRoot.innerHTML = this.render();
// Apply external styles to the shadow dom
const linkElem = document.createElement('link');
linkElem.setAttribute('rel', 'stylesheet');
linkElem.setAttribute(
'href',
`${env['PUBLIC_URL']}/static/css/index.css`
);
// Attach the created elements to the shadow dom
shadowRoot.appendChild(linkElem);
}
shadowRoot.innerHTML = this.render();
// Append external stylesheet to the shadow dom
const linkElem: HTMLLinkElement =
document.createElement<'link'>('link');
linkElem.setAttribute('rel', 'stylesheet');
linkElem.setAttribute(
'href',
`${env['PUBLIC_URL']}/static/css/index.css`
);
// Attach the created elements to the shadow dom
shadowRoot.appendChild<HTMLLinkElement>(linkElem);
console.debug('setup()');
}
/**
*
*/
connectedCallback(): void {
this.setup();
console.debug('<app-component> element added to page.');
console.debug(
'<app-component connectedCallback()> - element added to page.'
);
}

disconnectedCallback(): void {
console.debug('<app-component> removed from page.');
console.debug(
'<app-component disconnectedCallback()> - element removed from page.'
);
}

adoptedCallback(): void {
console.debug('<app-component> moved to new page.');
console.debug(
'<app-component adoptedCallback()> - element moved to new page.'
);
}

attributeChangedCallback(
name: string,
oldValue: string,
newValue: string
): void {
console.debug('<app-component> attributes changed.', {
name: name,
oldValue: oldValue,
newValue: newValue,
});
console.debug(
'<app-component attributeChangedCallback()> attributes changed.',
{
name: name,
oldValue: oldValue,
newValue: newValue,
}
);
}
private render(): string {
return `
<div class="App">
<header class="App-header">
<img
src="data:image/svg+xml;base64,${logo}"
src="${logoSrc}"
class="App-logo"
alt="logo"
/>
Expand Down

0 comments on commit 4862186

Please sign in to comment.