uhtml factory function
TylorS opened this issue Β· comments
Hello π
I just wanted to say I really appreciate your various OSS libaries greatly! I'm usually careful about my dependencies and all your *html and related projects are a no-brainer for me and I've been using them for rendering as much as I can, thank you π
I'm working on my own tooling that would does some orchestration around when to render some "components" using requestAnimationFrame/requestIdleCallback/etc, and I'd love to be able to run uhtml
directly within my tests using linkedom
as the DOM implementation, but I quickly ran into issues where uhtml
makes use of the document
global.
I wouldn't ask to change the API, it works great as it is for the standard case, but I wonder if it'd be possible to create a factory function which is capable of making isolated runtimes with their own caches and other state and reference to globals more condusive to testing? Maybe I'm using it wrong? Either way I'd love to hear what you think
The primary use case for uhtml is to run on browsers, where document is expected, for the server side there is uhtml-ssr. However, adding an export a part that puts uhtml in a closure where you can pass all expected globals might be a way to solve your issue. Would that work?
Yes, a closure which takes all of the globals was exactly the idea I had in mind
It's up ...
// const uhtml = require('uhtml/init');
import uhtml from 'uhtml/init';
const {render, html, svg} = uhtml({document});
It's also tested and covered, so it should work fine π
Thank you so much, can't wait to use it!