Skip to content

Commit 2bb63f8

Browse files
authored
Merge pull request #7 from ryansolid/hydration
Hydration
2 parents fc82a66 + 4ae449c commit 2bb63f8

File tree

5 files changed

+764
-648
lines changed

5 files changed

+764
-648
lines changed

index.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,32 @@ const SVGElements = new Set([
349349
"vkern"
350350
]);
351351

352-
export { Attributes, SVGAttributes, NonComposedEvents, SVGElements };
352+
/*
353+
(function() {
354+
window._$HYDRATION = { events: [], completed: new Set() };
355+
function lookup(el) {
356+
return el && (el.getAttribute("_hk") || lookup((el.host && el.host instanceof Node) ? el.host : el.parentNode));
357+
}
358+
function hydrationEventHandler(e) {
359+
let node = (e.composedPath && e.composedPath()[0]) || e.target;
360+
const id = lookup(node);
361+
if (id && !window._$HYDRATION.completed.has(id)) window._$HYDRATION.events.push([id, e]);
362+
}
363+
["${eventNames.join(
364+
'","'
365+
)}"].forEach(name => document.addEventListener(name, hydrationEventHandler));
366+
})();
367+
*/
368+
function generateHydrationEventsScript(eventNames) {
369+
return `!function(){function t(t){const e=function t(e){return e&&(e.getAttribute("_hk")||t(e.host&&e.host instanceof Node?e.host:e.parentNode))}(t.composedPath&&t.composedPath()[0]||t.target);e&&!window._$HYDRATION.completed.has(e)&&window._$HYDRATION.events.push([e,t])}window._$HYDRATION={events:[],completed:new Set},["${eventNames.join(
370+
'","'
371+
)}"].forEach(e=>document.addEventListener(e,t))}();`;
372+
}
373+
374+
export {
375+
Attributes,
376+
SVGAttributes,
377+
NonComposedEvents,
378+
SVGElements,
379+
generateHydrationEventsScript
380+
};

0 commit comments

Comments
 (0)