Ignore false as a child in h
Rmaan opened this issue · comments
Currently I couldn't write
function render() {
return h('div#root', [
renderLoginBar(),
userId != null &&
renderRestOfThePage()
]);
}
Cause if userId
is null children array will be [..., false]
and false is not a proper vnode nor a string but I could pass undefined
and null
in the array and they will be ignored.
It would be a nice addition to ignore false (and maybe 0) so boolCondition && node
could be used in render functions. Currently I should use ternary operators all over the place.
If it's a decision to not support false/0/... it would be much better to show more descriptive errors in better places (at least in debug environments). Like a stack trace when we call h
instead of Cannot read property 'length' of undefined
deep inside maquette code at render time.
Sounds like a good idea to me to allow the &&
construct in render functions. This should have little impact. In order to allow Typescript users to also use &&
this should be explicitly allowed in the interfaces.
Throwing a more meaningful error at runtime would mean more boilerplate code. If you were to use Typescript you would already get a nice error message earlier on.
Thanks for the fast response. Unfortunately I'm not currently using Typescript hence the error.
Do you think 153fe56 solves your issue?
Yes, it fixes my case. Thank you!