feat: add jsdoc example and links

This commit is contained in:
Ayo 2023-11-06 23:59:46 +01:00
parent 4aaa93e57a
commit d0e144953a

View file

@ -1,8 +1,26 @@
/** /**
* A base class with custom element utilities extending HTMLElement * A minimal vanilla JS base class to reduce the complexity of creating reactive custom elements
* @class * @license MIT <https://opensource.org/licenses/MIT>
* @constructor * @author Ayo Ayco <https://ayo.ayco.io>
* @public * @see https://www.npmjs.com/package/web-component-base#readme
* @example
* ```js
* import WebComponent from "https://unpkg.com/web-component-base/index.js";
*
* class HelloWorld extends WebComponent {
* dataName = "World";
* emotion = "excited";
*
* static properties = ["data-name", "emotion"];
*
* get template() {
* return `
* <h1>Hello ${this.dataName}${this.emotion === "sad" ? ". 😭" : "! 🙌"}</* h1>`;
* }
* }
*
* customElements.define('hello-world', HelloWorld);
* ```
*/ */
export class WebComponent extends HTMLElement { export class WebComponent extends HTMLElement {
constructor() { constructor() {
@ -50,12 +68,14 @@ export class WebComponent extends HTMLElement {
onChanges(changes) {} onChanges(changes) {}
connectedCallback() { connectedCallback() {
super.connectedCallback();
this.onInit(); this.onInit();
this.render(); this.render();
this.afterViewInit(); this.afterViewInit();
} }
disconnectedCallback() { disconnectedCallback() {
super.disconnectedCallback();
this.onDestroy(); this.onDestroy();
} }