Raynos / min-document

A minimal DOM implementation
MIT License
109 stars 27 forks source link

Elements missing outerHTML #14

Open gsf opened 10 years ago

gsf commented 10 years ago

Because toString() on an element in the browser returns something like "[object HTMLDivElement]", I have a helper function like this in my tests that run on both server and browser:

function toStr (el) {
  return el.outerHTML || String(el);
}

Could elements in min-document have an outerHTML as well for parity?

Raynos commented 10 years ago

That would be a pain in the ass because outerHTML would have to be a getter. I've avoided getters so far.

gsf commented 10 years ago

I figured there might be a catch. Any other ideas on how to test element output across server and browser?

shama commented 9 years ago

I would also like support for outerHTML so the exact same code can run client/server.

This seems like a good use for a getter in the constructor to so I'm curious why you want to avoid it:

Object.defineProperty(this, 'outerHTML', {
  get: function() { return this.toString() }
})

Otherwise this lib would have to monitor changes to itself and render upon each to the property; which sounds a lot more horrible IMO.

chromakode commented 8 years ago

@Raynos out of curiousity, what is your reason for avoiding getters in this codebase? I've been looking at adding some additional properties to nodes (e.g. attributes, firstChild, nextSibling, DOMText.nodeValue) which would be simpler to implement with getters (and avoid duplicate data consistency bugs). What's the best approach to adding such properties to this library? Would you accept a pull request that implemented them using getters, or simply assigning duplicate properties?

Raynos commented 8 years ago

@chromakode

getters have been avoided for ES3 compatibility. Generally all modules I author use ES3 + (subset of ES5 that is shimmable).

chromakode commented 8 years ago

Thanks for the clarification :+1: