-
Notifications
You must be signed in to change notification settings - Fork 109
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
Ability to pass just a single object #65
Comments
i agree, both ways are good, ought to be supported: |
so I did up a gist over at: https://gist.github.com/balupton/c807a9be215723f0e849697097b99a50 I'm not actually sure this suggestion results in better code, it sure makes understanding the hierarchy easier, but it does double the lines of code |
that gist makes things look more readable using the |
I could tolerate (what this will do to the implementation internals) if this only applies when the object is the first arg (if the tag name is not the string) and if all fields are under properties. h({tag: ..., classes: ..., attributes: {...}, events: {...}, children: [...] }) with only a fixed number of accepted properties on the top object. then the code for handling any of those things can be refactored into a function and just called on the object. I disagree that it's more "readable" but that is very subjective. |
yes of course, so it may not be more "readable" but there is something less subjective here if we believe in the following premise:
|
also if we do h({tag: ..., classes: ..., attributes: {...}, text: ... }) |
@ahdinosaur I am looking for the issue that you opened regards consolidating the hyperscript api, but can't find it. |
@dominictarr thanks for the ping: #66 |
Passing objects is also easier from the Functional Programming perspective, if you want to compose var link = {tag: 'a', href: 'http://check.it', text: 'Check my link!'}
var applyStyle = style => elm => {...elm, style}
var styledNode = h(applyStyle(link))
//=> h({tag: 'a', href: 'http://check.it', style: style, text: 'Check my link!'}) would be easier than var textInput = {tag: 'input, href: 'http://check.it', text:'Check my link!'}
var applyStyle = style => elm => {...elm, style}
var removeProps = props => obj => {
... // write function removing the props from the object
}
var toArray = obj => [obj.tag, obj, obj.text]
var styledNode = h.apply(h, toArray(removeProps(['tag', 'text'])(applyStyle(link))))
//=> h('a', {href: 'http://check.it', style: style}, 'Check my link!') that you need now with the current implementation of |
It could be nice if we could just pass one object, that contains a
tag
andchildren
properties, like so:I'm doing a gist now to test this assumption.
The text was updated successfully, but these errors were encountered: