elm / virtual-dom

The foundation of HTML and SVG in Elm.
https://package.elm-lang.org/packages/elm/virtual-dom/latest
BSD 3-Clause "New" or "Revised" License
209 stars 80 forks source link

Fix #132: Correctly handles empty strings as values of attributes #136

Closed reiner-dolp closed 6 years ago

reiner-dolp commented 6 years ago

The only caller seems to be _VirtualDom_applyFacts, which passes through a value of 'undefined' for attributes and namespaced attributes. Set by line 900-903 in _VirtualDom_diffFacts.

evancz commented 6 years ago

Thank you! Was trying to minimize bits, but did not think about empty strings as values at the time.

lydell commented 6 years ago

Well, if we're talking about saving bits, there are shorter ways of doing this such as value !== undefined (should be equivalent) and value != null (handles both undefined and null in one go).

reiner-dolp commented 6 years ago

@lydell I tried to be consistent with line 22. But its just used there to not crash the program ifdocument is an unknown global variable. Since we know x exists, we could indeed refactor it to something shorter.

But the code is not really optimized for size anyway, right? And a minimizer will probably minimize it more aggressively to something like !function(u) { /* closure around whole code base */ value !== u /* u is undefined since it was not set on closure invokation */ }(); or value !== void 0.