Skip to content

Shave some bytes#105

Merged
keithamus merged 3 commits intomainfrom
shave-some-bytes
Jan 25, 2021
Merged

Shave some bytes#105
keithamus merged 3 commits intomainfrom
shave-some-bytes

Conversation

@keithamus
Copy link
Copy Markdown
Contributor

@keithamus keithamus commented Jan 25, 2021

Whilst looking over some of the code I noticed a couple of spots that could be tightened up. This only reduces the compiled code by 7 bytes gzipped (I know, big deal right?) but the code remains functionally identical and I think it's also a slight readability improvement.

@keithamus keithamus requested a review from a team as a code owner January 25, 2021 09:08
Comment thread src/bind.ts
}
}
})
observer.observe(el, {childList: true, subtree: true, attributes: true, attributeFilter: ['data-action']})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If either options’s attributeOldValue or attributeFilter is present and options’s attributes is omitted, then set options’s attributes to true.

https://dom.spec.whatwg.org/#dom-mutationobserver-observe

Comment thread src/auto-shadow-root.ts
.attachShadow({
mode: template.getAttribute('data-shadowroot') === 'closed' ? 'closed' : 'open'
})
.appendChild(template.content.cloneNode(true))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • ParentNode.append() allows you to also append DOMString objects, whereas Node.appendChild() only accepts Node objects.
  • ParentNode.append() has no return value, whereas Node.appendChild() returns the appended Node object.
  • ParentNode.append() can append several nodes and strings, whereas Node.appendChild() can only append one node.

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append

Copy link
Copy Markdown
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@keithamus keithamus merged commit 3acbb9a into main Jan 25, 2021
@keithamus keithamus deleted the shave-some-bytes branch January 25, 2021 10:40
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