Skip to content

Commit 023336a

Browse files
committed
feat: dispatch hydrate events to browser.
1 parent 754cd94 commit 023336a

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elderjs/elderjs",
3-
"version": "1.6.12",
3+
"version": "1.6.13",
44
"main": "./build/index.js",
55
"types": "./build/index.d.ts",
66
"engineStrict": true,

src/partialHydration/hydrateComponents.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ const $$ejs = (par,eager)=>{
1010
${decompressCode}
1111
const prefix = '${prefix}';
1212
const initComponent = (target, component) => {
13+
14+
if(!!CustomEvent && target.id){
15+
const split = target.id.split('-ejs-');
16+
document.dispatchEvent(new CustomEvent('ejs', {
17+
detail: {
18+
category: 'elderjs',
19+
action: 'hydrate',
20+
target: target,
21+
label: split[0] || target.id
22+
}
23+
}));
24+
}
25+
1326
const propProm = ((typeof component.props === 'string') ? fetch(prefix+'/props/'+ component.props).then(p => p.json()).then(r => $ejs(r)) : new Promise((resolve) => resolve($ejs(component.props))));
1427
const compProm = import(prefix + '/svelte/components/' + component.component);
1528

src/utils/svelteComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const svelteComponent =
5050

5151
const id = getUniqueId();
5252
const lowerCaseComponent = componentName.toLowerCase();
53-
const uniqueComponentName = `${lowerCaseComponent}${id}`;
53+
const uniqueComponentName = `${lowerCaseComponent}-ejs-${id}`;
5454

5555
page.componentsToHydrate.push({
5656
name: uniqueComponentName,

0 commit comments

Comments
 (0)