substance / substance

A JavaScript library for web-based content editing.

Home Page:https://substance.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid using overloaded native API's for DOMElement

michael opened this issue · comments

For instance in some places we use el.nodeType which in our abstraction returns a string:

...
  getNodeType() {
    switch(this.el.nodeType) {
      case window.Node.TEXT_NODE:
        return "text"
      case window.Node.ELEMENT_NODE:
        return 'element'
      case window.Node.DOCUMENT_NODE:
        return 'document'
      case window.Node.COMMENT_NODE:
        return 'comment'
      case window.Node.PROCESSING_INSTRUCTION_NODE:
        return 'directive'
      case window.Node.CDATA_SECTION_NODE:
        return 'cdata'
      default:
        //
    }
  }

We should consider deprecating these problematic native API's and use explicit getters when possible.

E.g. el.isCdataElement() then it is clear this is custom API with different semantics.

We may also want to use symbols for representing node types. E.g.

const { CDATA } = DOMElement.NodeTypes