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

Self closing tag whitelist vs blacklist #33

Closed
slaskis opened this issue Sep 4, 2016 · 2 comments
Closed

Self closing tag whitelist vs blacklist #33

slaskis opened this issue Sep 4, 2016 · 2 comments

Comments

@slaskis
Copy link
Collaborator

slaskis commented Sep 4, 2016

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.

@slaskis
Copy link
Collaborator Author

slaskis commented Sep 6, 2016

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.

@slaskis
Copy link
Collaborator Author

slaskis commented Sep 6, 2016

Closing this for #34

@slaskis slaskis closed this as completed Sep 6, 2016
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

No branches or pull requests

1 participant