From 2624789ef8d70baf1ff40401734f7b0e73cd79dd Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Sat, 14 Oct 2023 15:47:08 -0400 Subject: [PATCH] constructor props --- src/wcc.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wcc.js b/src/wcc.js index b27278f..f9b3998 100644 --- a/src/wcc.js +++ b/src/wcc.js @@ -126,7 +126,7 @@ async function getTagName(moduleURL) { return tagName; } -async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry) { +async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry, props = {}) { if (!tagName) { const depth = isEntry ? 1 : 0; registerDependencies(elementURL, definitions, depth); @@ -138,7 +138,11 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti ? customElements.get(tagName) : (await import(pathname)).default; const dataLoader = (await import(pathname)).getData; - const data = dataLoader ? await dataLoader() : {}; + const data = props + ? props + : dataLoader + ? await dataLoader(props) + : {}; if (element) { const elementInstance = new element(data); // eslint-disable-line new-cap @@ -160,11 +164,11 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti } } -async function renderToString(elementURL, wrappingEntryTag = true) { +async function renderToString(elementURL, wrappingEntryTag = true, props = {}) { const definitions = []; const elementTagName = wrappingEntryTag && await getTagName(elementURL); const isEntry = !!elementTagName; - const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry); + const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props); const elementHtml = elementInstance.shadowRoot ? elementInstance.getInnerHTML({ includeShadowRoots: true })