Improvements to namespaces and attributes in serialization#20
Improvements to namespaces and attributes in serialization#20
Conversation
Attributes can now be get and set through both elem.[attr] or elem.getAttribute("[attr]"). Added test-case that shows this behaviour
Ie elem.style.backgroundColor="xxx" now translate to style="background-color: xxx; ". Test-cases added to test this behavior
The namespace-id shouldn't be part of the attribute-name. Test-case updated
that's not how the DOM works. |
There was a problem hiding this comment.
We cannot write to this. We must write to this._attributes['default-namespace'] or something. We can even have this._attributes and this._nsAttributes
|
Other then props vs attributes the rest looks good to me. |
|
Well, at least for HTML documents, and supported attributes is does. E.g el = document.createElement('div')
el.id = "foo"
el.getAttribute("id") === "foo" // <- trueI considered having a white-list of attributes that if the namespaceURI was the html-namespace, then have this behaviour, but I figured it would start pushing this project away from being a minimal DOM implementation. But if you don't want this behaviour, then I'll remove that commit, add a commit that fixes serialisation of things like el = document.createElement('div')
el.foo = "bar"
el.setAttribute("foo", "baz")and force-push to this feature-branch to update the PR. The problem with the code above is that it would serialise to -M. |
|
The problem you are running into is the need to have a property -> attribute mapping. Because You also need deduping, i.e. if an attribute is written once dont write it again. I recommend:
However let's not simplify the problem down to "attributes and properties are the same" that is a wrong implementation. I'd rather have an incomplete or subset implementation then a wrong one. |
Hi,
I started out by adding test-cases for the serialisation, and found a few issues once I compared to how browsers (ehh, phantomjs) does it. I found a few discrepancies that I have addressed. Additionally I ensured that
elem.[attr]is equivalent toelem.getAttribute("[attr]").So the new or fixed features are:
elem.[attr]is equivalent toelem.getAttribute("[attr]")elem.style.backgroundColorand other CSS properties that include hyphens are now serialised correctlyKnown differences between min-document and browsers:
document.createElement('input').getAttribute('type')isnullin browsers, buttextin min-document. This is because in both browsers and min-document,document.createElement('input').typeistext- ie, in browsers there is a difference between.typeand.getAttribute('type');.document.createElement('input')is serialised as<input>in browsers, and<input type="text">in min-document. This is the same issue as the previous discrepancy.Kind regards
Morten