-
Notifications
You must be signed in to change notification settings - Fork 780
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
@hyperapp/html: use a Proxy? #1087
Comments
In the past I've used a similar However, if I'm not mistaken using a My preference nowadays is to use |
In this case, the Proxy is just a factory for the element creation functions - there is no run-time performance overhead once you've generated your functions. My only reservation is this only works in modern browsers and Proxy can't be polyfilled. |
It's good to know the I actually would like it if |
Unless you need IE11 support (which I don't think hyperapp supports anyway) Proxy is fine! I've used the approach suggested here in the past as well and really it's fine :) The very small issues I've had with it are:
import html from '@hyperapp/html'
const {div, p, text} = html Those aren't huge issues though and I could go either way. 🤷 😄 |
Custom elements is a nice plus. Now, the purpose here would be shipping less code with the package or would there be anything else?
In the land of the multi-line, the one-liner is king. |
One-liner is probably doable with |
pf, using |
@sergey-shpak great minds... heh. I too tried to get around the noisy empty attributes object you have to pass with every call - although, for some reason, my attempts seemed to break the official examples... Such a small thing, but it would make the examples look much better. I guess it's a breaking change though... |
@mindplay-dk the gist is pretty old I haven't updated it for a while, my current implementation is following: import {h, text} from 'hyperapp'
/* Html factory */
export const html = new Proxy({}, {
get: (target, name) => name !== 'text'
? (attrs = {}, child) =>
!Array.isArray(attrs) && !attrs.tag
? h(name, attrs, child)
: h(name, {}, attrs)
: text
}) and the usage const {div, span, text} = html
// no useless array for single element
// and no empty props object
div(text('Some text'))
// or something like
div([
span(text('some text')),
span(text('other text'))
])
// and common usage
div({class: 'active'}, text('no array for single child')) *added later: works with [email protected], I haven't tested with other versions but should be ok |
In modern browsers, can we use a
Proxy
instead of hard coding all the element types?I'm using this right now:
One more line of code, and you have support for custom elements:
Thoughts? :-)
The text was updated successfully, but these errors were encountered: