You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, this is awesome. It lets me work on my electron app with jsx-like code without having any build step. It's great!
I'm just curious as to why self closing tags are whitelisted.
Because right now when I'm a bit lazy (or rushed) I just want to write <div id=bla /> when I know it won't have any children, but then it breaks the dom by not closing it. The fix is easy of course, just close it like <div id=bla></div> but it still gets me every time.
I'm sure there's a reason, obviously there is a nice opportunity to be able to validate the code, so we don't try to put children into a etc.
Another case which I'm currently playing around with an idea in my app to have custom component tags by registering the components (as opposed to the suggestion in #9) and replacing tagName with it in the rendering function, like this:
// hx.js
const {h} = require('preact')
const render = hyperx(hr)
render.register = register
module.exports = render
const components = {}
function hr(tagName, attrs, children) {
return h(components[tagName] || tagName, attrs, children)
}
function register(component) {
components[component.name] = component
return component
}
// Component.js
const hx = require('./hx')
const Component =({onClick}) => hx`<div onClick=${props.onClick} />` // <-- this i would like to be able to "self close" like this
register(Component)
// Parent.js
const hx = require('./hx')
const Parent = props => hx`<Component onClick=${props.onClick} />` // <-- this i would like to be able to "self close" like this
The bad part about this right now it that I have to require all the components somewhere, not necessarily where they're used (unlike when using it like in #9 or in React).
If there's some interest in flipping the whitelist to a blacklist instead (not allowing children for elements which don't support children) I'd love to give a PR a try.
The text was updated successfully, but these errors were encountered:
When writing some tests for this I realised I've mistaken the issue, it does not seem to be related to a whitelist of self closing tags. But instead is seems to be an issue with multiple self closing elements.
First of all, this is awesome. It lets me work on my electron app with jsx-like code without having any build step. It's great!
I'm just curious as to why self closing tags are whitelisted.
Because right now when I'm a bit lazy (or rushed) I just want to write
<div id=bla />
when I know it won't have any children, but then it breaks the dom by not closing it. The fix is easy of course, just close it like<div id=bla></div>
but it still gets me every time.I'm sure there's a reason, obviously there is a nice opportunity to be able to validate the code, so we don't try to put children into a etc.
Another case which I'm currently playing around with an idea in my app to have custom component tags by registering the components (as opposed to the suggestion in #9) and replacing tagName with it in the rendering function, like this:
The bad part about this right now it that I have to require all the components somewhere, not necessarily where they're used (unlike when using it like in #9 or in React).
If there's some interest in flipping the whitelist to a blacklist instead (not allowing children for elements which don't support children) I'd love to give a PR a try.
The text was updated successfully, but these errors were encountered: