WebReflection / linkedom

A triple-linked lists based DOM implementation.
https://webreflection.medium.com/linkedom-a-jsdom-alternative-53dd8f699311
ISC License
1.62k stars 78 forks source link

Support Node constructors #252

Closed krulod closed 7 months ago

krulod commented 7 months ago

This module does not support Node constructors like new Text currently, enforcing the usage of older APIs like document.createTextNode.

I tried to fix it myself, but gave up because I couldn't figure out how to provide objects with ownerDocument.

WebReflection commented 7 months ago

all constructors need to know which document they belong to and the document is the first argument, meaning you can do something like:

import { Text as RawText } from '...';

const Text = RawText.bind(null, currentDocument);

new Text('content');

and that's pretty much it.

I could infer automatically the document if only one has been created though, but to date these use case are pretty rare as many constructors break out of the box with standard DOM so that "legacy methods" are actually just the start way to create elements while using constructors is a slippery slope for Web interop.

I hope this answers or solve your issue.