Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/undom.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,24 @@ export default function undom() {
}
appendChild(child) {
this.insertBefore(child);
return child;
}
insertBefore(child, ref) {
child.remove();
child.parentNode = this;
if (!ref) this.childNodes.push(child);
else splice(this.childNodes, ref, child);
!ref ? this.childNodes.push(child) : splice(this.childNodes, ref, child);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is pretty much what Uglify does (haven't checked).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eslint complained when I simply added return after the if/else as it thought the return was only for the else case. So I switched to the ternary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that changing simply because eslint says so is the right thing, but in this case it does seem to make things clearer with the ternary imo.

return child;
}
replaceChild(child, ref) {
if (ref.parentNode===this) {
this.insertBefore(child, ref);
ref.remove();
return ref;
}
}
removeChild(child) {
splice(this.childNodes, child);
return child;
}
remove() {
if (this.parentNode) this.parentNode.removeChild(this);
Expand Down