-
Notifications
You must be signed in to change notification settings - Fork 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
Feature idea: easy classNames #6
Comments
@staltz Well, if it's just about matching the |
Yes, because we can use the underlying logic already existing in hyperscript. Instead of calling |
Could it really be that easy? I thought there was some mystical logic in hyperscript that prevented me from doing that in the first place... No, it was the "figure out whether the first parameter is a selector and maybe act differently" part that felt icky to me. But I do see the value in this proposal. |
Can I give my 👍 for this? |
Sweet! 👯 |
Just wanted to note that this shortcut may be a source of confusion. title("...") Will generate <title class=".."/> instead of <title>...</title> |
Hmm, good find |
I have code like |
@ivan-kleshnin Do you think it is enough to mention this in README or should this be resolved somehow? We could theoretically make the "class name detection" smarter by also checking that the 2nd character is [a-zA-Z], or whatever is in the CSS classname specs. |
@ohanhi yes we could. But I personally prefer to avoid heuristics because they kinda hide the problem under the carpet. For example this check could prevent
surprising output. But it couldn't prevent I like the API of hyperscript-helpers and I'd like to keep this shortcut. It's very convenient. So in my opinion we should just mention this in docs. Something like
|
👍 Would you like to make a PR about that? |
Sure. One more alternative is to require from single argument to be an |
Yes, but I don't think we need to go that far. The gist of this library is anyway to be a simple proxy for the hyperscript implementation. Introducing any syntax rules of our own easily makes the lib less convenient to use and maintain. So I think just the note in README is the best way to go about this. |
Sent a PR. I opened you a push access to fork for case you'll want to change something. |
For HH syntax, even if node has single text child, it should be wrapped in bracked due to ohanhi/hyperscript-helpers#6 (comment) For HH syntax, hovewer it is not required. Brackets around single commend child are not required in both syntaxes.
One feature I like in hyperscript is the ability to easily write the className using CSS selectors:
h('div.foo')
, noth('div', {className: 'foo'})
.In Cycle.js, it's also convenient to have the
.
dot there, because later the classes are used in selectors, e.g.DOM.select('.foo').events('click')
. So it's not great if sometimes you need the dot, and sometimes you don't (in className), that's why I like hyperscript keeping it consistent.Proposal:
How about allowing a string parameter to the hyperscript helper? If the first parameter is a string, then it's interpreted as the selector, so its classes will be parsed out in hyperscript. If the first parameter is an object, we know its the properties object.
E.g.
div('.foo')
instead ofdiv({className: 'foo'})
.Of course one would be able to still provide properties and children:
The text was updated successfully, but these errors were encountered: