Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider making the Node type used throughout XmlRenderer generic #5

Open
DrRataplan opened this issue Mar 4, 2021 · 2 comments
Open

Comments

@DrRataplan
Copy link

Hey there,

I've been using xml-renderer for a bit and I noticed the Node type used in a bunch of places in the codebase is of the type globalThis.Node: the browser built-in variant. This usually works out fine.

I've been using xml-renderer in combination with another DOM implementation: slimdom. At that point, if you want to use some more specific slimdom functions, such as calling XMLSerializer#serializeToString with a node that is coming out of xml-renderer, Typescript warns me about the fact that globalThis.Node is not compatible with slimdom.Node. You'll have to typecast the xml-renderer Node (which is the browser Node type) to slimdom.Node (which is what slimdom accepts).

If xml-renderer would be generic on the Node type, I could pass slimdom.Node and have more powerful typing. Other libraries, such as FontoXPath will then also pick those typings up, making it easier for me to work with xml-renderer.

What would be your thoughts?

Regard,

Martin

@wvbe
Copy link
Owner

wvbe commented Mar 4, 2021

@DrRataplan I think you're completely right and I do plan to make this change. Thanks for logging an issue, it helps me remember!

evaluateXPathToNodes, which xml-renderer depends on, is presumably also generic?

In your opinion, which interface is more intuitive to make generic?

const nerf = new ReactRenderer<slimdom.Node>()

or

nerf.render<slimdom.Node>(createElement, myNode)

@DrRataplan
Copy link
Author

DrRataplan commented Mar 4, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants