diff --git a/demo/HelloWorld.mjs b/demo/HelloWorld.mjs index beab6b4..7b1a399 100644 --- a/demo/HelloWorld.mjs +++ b/demo/HelloWorld.mjs @@ -1,3 +1,4 @@ +// @ts-check import WebComponent from "../src/index.js"; export class HelloWorld extends WebComponent { diff --git a/package.json b/package.json index 654a6fc..0e9e08c 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ "clean": "rm -rf dist", "copy:meta": "cp package.json ./dist && cp README.md ./dist", "copy:source": "cp ./src/* ./dist", - "build:publish": "npm run clean && npm run build && npm run copy:meta && npm run copy:source && cd ./dist && npm publish --access public", - "publish:patch": "npm version patch && npm run build:publish", - "publish:minor": "npm version minor && npm run build:publish" + "prepare": "npm run clean && npm run build && npm run copy:meta && npm run copy:source", + "publish": " cd ./dist && npm publish --access public", + "publish:patch": "npm version patch && npm run publish", + "publish:minor": "npm version minor && npm run publish" }, "repository": { "type": "git", diff --git a/src/WebComponent.mjs b/src/WebComponent.mjs index fadf187..362c6e1 100644 --- a/src/WebComponent.mjs +++ b/src/WebComponent.mjs @@ -1,6 +1,16 @@ // @ts-check +/** + * A base class with custom element utilities extending HTMLElement + * @class + * @constructor + * @public + */ export class WebComponent extends HTMLElement { + constructor() { + super(); + } + /** * @type Array */ @@ -57,11 +67,10 @@ export class WebComponent extends HTMLElement { * @param {any} currentValue */ attributeChangedCallback(property, previousValue, currentValue) { - const camelCaps = (kebab) => - kebab.replace(/-./g, (x) => x[1].toUpperCase()); + const camelCaps = this.#getCamelCaps(property); if (previousValue !== currentValue) { this[property] = currentValue; - this[camelCaps(property)] = currentValue; + this[camelCaps] = currentValue; this.render(); this.onChanges({ property, previousValue, currentValue }); } @@ -70,4 +79,8 @@ export class WebComponent extends HTMLElement { render() { this.innerHTML = this.template; } + + #getCamelCaps(kebab) { + return kebab.replace(/-./g, (x) => x[1].toUpperCase()); + } }