diff --git a/docs/p06-customElement.html b/docs/p06-customElement.html index e7b295d..af281da 100644 --- a/docs/p06-customElement.html +++ b/docs/p06-customElement.html @@ -44,11 +44,17 @@ customElementWithDDE(HTMLCustomElement); customElements.define(HTMLCustomElement.tagName, HTMLCustomElement); const instance= el(HTMLCustomElement.tagName); -on.connected(e=> console.log("Element connected to the DOM:", e))(instance); +on.connected( // preffered + e=> console.log("Element connected to the DOM (v1):", e) +)(instance); +instance.addEventListener( + "dde:connected", + e=> console.log("Element connected to the DOM (v2):", e) +); document.body.append( instance, ); -

Custom Elements with DDE

import { +

Custom Elements with DDE

The customElementWithDDE function is only (small) part of the inregration of the library. More important for coexistence is render component function as a body of the Custom Element.

import { customElementRender, customElementWithDDE, } from "./esm-with-signals.js"; @@ -69,7 +75,7 @@ export class HTMLCustomElement extends HTMLElement{ import { el, on, scope } from "./esm-with-signals.js"; function ddeComponent({ attr }){ scope.host( - on.connected(e=> console.log(this.outerHTML)), + on.connected(e=> console.log(e.target.outerHTML)), ); return el().append( el("p", `Hello from Custom Element with attribute '${attr}'`) @@ -81,4 +87,4 @@ customElements.define(HTMLCustomElement.tagName, HTMLCustomElement); document.body.append( el(HTMLCustomElement.tagName, { attr: "Attribute" }) ); -

# Mnemonic

\ No newline at end of file +

# Mnemonic

\ No newline at end of file diff --git a/docs_src/components/examples/customElement/customElementWithDDE.js b/docs_src/components/examples/customElement/customElementWithDDE.js index 9ccdade..367a942 100644 --- a/docs_src/components/examples/customElement/customElementWithDDE.js +++ b/docs_src/components/examples/customElement/customElementWithDDE.js @@ -11,7 +11,13 @@ customElementWithDDE(HTMLCustomElement); customElements.define(HTMLCustomElement.tagName, HTMLCustomElement); const instance= el(HTMLCustomElement.tagName); -on.connected(e=> console.log("Element connected to the DOM:", e))(instance); +on.connected( // preffered + e=> console.log("Element connected to the DOM (v1):", e) +)(instance); +instance.addEventListener( + "dde:connected", + e=> console.log("Element connected to the DOM (v2):", e) +); document.body.append( instance, ); diff --git a/docs_src/components/mnemonic/customElement-init.js b/docs_src/components/mnemonic/customElement-init.js index c256893..c253215 100644 --- a/docs_src/components/mnemonic/customElement-init.js +++ b/docs_src/components/mnemonic/customElement-init.js @@ -4,7 +4,7 @@ import { mnemonicUl } from "../mnemonicUl.html.js"; export function mnemonic(){ return mnemonicUl().append( el("li").append( - el("code", "customElementRender(, [, ])"), " — use function to render DOM structure for given ", + el("code", "customElementRender(, , [, ])"), " — use function to render DOM structure for given ", ), el("li").append( el("code", "customElementWithDDE()"), " — register to DDE library, see also `lifecyclesToEvents`, can be also used as decorator", diff --git a/docs_src/p06-customElement.html.js b/docs_src/p06-customElement.html.js index 1913473..d7a3f68 100644 --- a/docs_src/p06-customElement.html.js +++ b/docs_src/p06-customElement.html.js @@ -68,7 +68,16 @@ export function page({ pkg, info }){ el(example, { src: fileURL("./components/examples/customElement/customElementWithDDE.js"), page_id }), el("h3", t`Custom Elements with DDE`), + el("p").append(...T` + The ${el("code", "customElementWithDDE")} function is only (small) part of the inregration of the library. + More important for coexistence is render component function as a body of the Custom Element. For that, you + can use ${el("code", "customElementRender")} with arguments instance reference, target for connection, + render function and optional properties (will be passed to the render function) see later… + `), el(example, { src: fileURL("./components/examples/customElement/dde.js"), page_id }), + el("p").append(...T` + … + `), el(mnemonic)