-
Notifications
You must be signed in to change notification settings - Fork 102
allow child to be undefined or null #40
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is one issue with the implementation, if the value of child
is 0 (number), the will be filtered out.
I'm thinking of the implementation like:
children.map(c => c ?? []).flat(Infinity).forEach(...)
Thanks so much for your contribution! I will do the merging this or next Friday, depending on my availability (currently only on Fridays I have convenient available personal time to work on this project).
Good catch, the filtering should be placed after the flattening, shoudn't it ? |
After For example [undefined, 1].map(c => c ?? []) // [[], 1] [[], 1].flat(Infinity) // [1] |
Thanks! This is great! |
@@ -42,7 +42,7 @@ let state = initVal => ({ | |||
let toDom = v => v.nodeType ? v : new Text(v) | |||
|
|||
let add = (dom, ...children) => ( | |||
children.flat(Infinity).map(c => c ?? []).forEach(child => dom.appendChild( | |||
children.flat(Infinity).filter(c => c != undefined).forEach(child => dom.appendChild( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!= null
is shorter and achieves the same thing.
This PR was manually merged in 0.12.1 release. However, @FredericHeem doesn't show up as the contributor of this repo despite I explicitly listed @FredericHeem as the co-author of the commit. Not sure why. This method worked previously in another commit, though. Nonetheless, I manually added @FredericHeem in the contributor list of the README.md file. |
This PR solves #16, allowing simpler client's code.