Skip to content

Commit

Permalink
feat: dispatch hydrate events to browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickreese committed Apr 1, 2022
1 parent 754cd94 commit 023336a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elderjs/elderjs",
"version": "1.6.12",
"version": "1.6.13",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"engineStrict": true,
Expand Down
13 changes: 13 additions & 0 deletions src/partialHydration/hydrateComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ const $$ejs = (par,eager)=>{
${decompressCode}
const prefix = '${prefix}';
const initComponent = (target, component) => {
if(!!CustomEvent && target.id){
const split = target.id.split('-ejs-');
document.dispatchEvent(new CustomEvent('ejs', {
detail: {
category: 'elderjs',
action: 'hydrate',
target: target,
label: split[0] || target.id
}
}));
}
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))));
const compProm = import(prefix + '/svelte/components/' + component.component);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/svelteComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const svelteComponent =

const id = getUniqueId();
const lowerCaseComponent = componentName.toLowerCase();
const uniqueComponentName = `${lowerCaseComponent}${id}`;
const uniqueComponentName = `${lowerCaseComponent}-ejs-${id}`;

page.componentsToHydrate.push({
name: uniqueComponentName,
Expand Down

0 comments on commit 023336a

Please sign in to comment.