Skip to content

Conversation

@jfmengels
Copy link

This is a minor improvement pull request.

{} creates an empty object but which still contains methods and properties like toString. Checking changes[key] when the key is for instance toString creates false positives in that check.

I was looking whether into whether this caused bugs, but in practice, the algorithms in _VirtualDom_insertNode and _VirtualDom_removeNode end up with the correct behavior because they recurse with a modified key, but do so with an unnecessary iteration.

Object.create(null) creates an empty object without any methods or properties, leading to no false positives and one less unnecessary iteration.

`{}` creates an empty object but which still contains methods and
properties like `toString`. Checking `changes[key]` when the key is
for instance `toString` creates false positives in that check.

In practice, the algorithms in `_VirtualDom_insertNode` and `_VirtualDom_removeNode`
end up with the correct behavior because they recurse with a modified
key, but do so with an unnecessary iteration.

`Object.create(null)` create an empty object without any methods or
properties, leading to no false positives.
@mozfreddyb
Copy link

Why not Map()?

@jfmengels
Copy link
Author

Because Elm currently compiles down to ES5, where Map is not available.

ahankinson added a commit to elm-janitor/virtual-dom that referenced this pull request Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants