-
Notifications
You must be signed in to change notification settings - Fork 84
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
Expose DOM Level 2 Elements #40
Comments
To clarify my issue, I can submit a PR, just wanted to make sure you're open to a PR for this issue. Looks like yes based on the labels. Thanks! |
Thanks, yes. Added to intermediate milestone before 1.0.0 for now (see milestones here). Unfortunately I do not have much time right now to review and merge contributions right now, hope another maintainer will have a chance. |
I'm also caught by this issue. My workaround is to rely on typescript types for the dom: function isAttr(attr: any): attr is Attr {
return attr.constructor.name === 'Attr';
} |
Actually, ignore my workaround. I was just hit by a bug in production code, as minified code will change the constructor's name (it's a private class after all) and the check won't work |
Sorry for joining the conversation so late, but there is one issue that we need to be aware of: If somebody knows how to "mark the constructors as private" or how other projects do that, please let us know. So we would only export const doc = new DOMParser().parse('<xml/>');
if (doc instanceof DOMImplementaiton.Document) { // true If DOMImplementaiton is "to long/unpractical" we could export a (read only) object called if (doc instanceof DOM.Document) { Since we are planning to move the types definition into the repo, based on the actual doc comments and types present in this code base (see #191), we might also be able to mark the constructors as What do you think? |
That would be lovely! I just found myself with the same need. I think both would work fine and don't have a strong preference – a longer name like |
The priority for this is very low at our end, but if somebody creates a PR with one of the two solutions we will follow up on it. |
@karfau In general i do have two aproaches in my mind to make the "constructor private": Use of inheritance: It would be possible to implement the "Interface" empty without a logic e.g. "Node" and additionally a "NodeImpl" which inherits from node and contains the logic. Only the "Node" but not the "NodeImpl" is exported. This allows you to check the node, but not create a new one. Simple Example: Use of symbols: A symbol is passed in the constructor, which is compared with an "internal symbol". If it is not the same, an error is thrown. Simple Example: What do you think? |
@karfau I would be down to implement any of the two suggested approaches mentioned by @kpalatzky |
If the internal symbol solution is possible in ES5, it sounds like that is the solution which requires less code and is easier to follow. |
Closes #40. Exposes all fundamental and extended interfaces according to the [specs](https://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html) while keeping the constructors for `Node`, `Document`, `Element`, `Attr`, `CharacterData`, `Text`, `Comment`, `CDATASection`, `DocumentType`, `Notation`, `Entity`, `EntityReference`, `DocumentFragment`, `ProcessingInstruction` private by checking a symbol in the constructor. --------- Co-authored-by: Oliver Swienty <oliver.swienty@xpublisher.com> Co-authored-by: Christian Bewernitz <coder@karfau.de>
Glad you all have forked and are maintaining
xmldom
, thank you!There were several issues in the old unmaintained repo dealing with exposing DOM Level 2 object interfaces, such as
Node
,Element
,NodeLike
. Right now, those classes are private.There are multiple library that deal with the browser
DOMParser
that make use of these for things likeinstanceof
checks. As one example, I'm usingbs-xml
, which wrapsDOMParser
for Bucklescript/ReasonML, and which has to check if an object is aNode
orElement
.Would you be open to a very simple PR that exposes those classes? Specifically, the ones listed as fundamental interfaces in the Level 2 DOM Core spec?
The text was updated successfully, but these errors were encountered: