Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge case with rendering children as number 0 #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dburles
Copy link

@dburles dburles commented Mar 18, 2019

Passing in number 0 as a child would result in nothing being rendered. See test:

https://github.com/dburles/vhtml/blob/88278a1fb47f93edb40e974ab4eaf6923169f4a4/test/vhtml.js#L169-L178

@@ -36,7 +36,7 @@ export default function h(name, attrs) {

while (stack.length) {
let child = stack.pop();
if (child) {
if (child !== undefined && child !== null) {
Copy link
Owner

Choose a reason for hiding this comment

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

This would allow <div>{true}</div> to render <div>true</div>. Do we want that? The VDOM libs ignore booleans.

In any case, this statement can compress to:

Suggested change
if (child !== undefined && child !== null) {
if (child != null) {

Copy link
Author

Choose a reason for hiding this comment

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

It also allowed it before so we could leave as is or correct it, up to you. The shorter version while shorter is not explicit, it's better to always use the === and !== operators. Just my thoughts.

Choose a reason for hiding this comment

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

I would concur with @dburles that being more explicit is often clearer. Also on the <div>{true}</div> debate mimicking the behaviour of React/Preact etc. seems intuitive.

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.

3 participants