News for hackers. Stuff that matters.
Re:_hyperscript: A jQuery and JavaScript Alternative by epr on Wednesday April 21, 2021 @12:23PM (#26891748)
Several years back, when I was learning my first web stack, I got some very good advice from a seasoned developer.

"Focus on the fundamentals of HTML, CSS and JS. Everything else is ephemeral."

I don't mean to pick on whomever wrote these examples, but the ~7 lines of JS for the first example (fading out) shows either a lack of basic understanding or intentional complication to make hyperscript appear better in comparison. A more reasonable solution is 3 lines of code.

    .fade { transition: opacity 500ms ease-out; }

    <div class="fade" onclick="
      this.style.opacity=0;
      this.addEventListener('transitionend', () => this.remove());
    ">Remove Me</div>
Re:_hyperscript: A jQuery and JavaScript Alternative by supakeen on Wednesday April 21, 2021 @12:26PM (#26891768)
This doesn't remove the object from the DOM after the animation is over, which the example on the website does. You'll need to add something that removes the element after the transition is over which would be a bunch more code (the eventlistener for transitionend) :)
Re:_hyperscript: A jQuery and JavaScript Alternative by epr on Wednesday April 21, 2021 @12:33PM (#26891876)
Thanks for the heads up before the Hacker News edit window closed. +1 LOC
Re:_hyperscript: A jQuery and JavaScript Alternative by jolux on Wednesday April 21, 2021 @12:39PM (#26891950)
FYI you can set a "delay" in your profile of up to 10 minutes before your comments are shown, giving you more time to edit. May not have helped in this case but it's a cool feature.
Re:_hyperscript: A jQuery and JavaScript Alternative by SebastianKra on Wednesday April 21, 2021 @04:31PM (#26895053)
thats's a nice tip. Thanks
Re:_hyperscript: A jQuery and JavaScript Alternative by jolux on Wednesday April 21, 2021 @04:43PM (#26895187)
one can learn a lot from reading the FAQ: https://news.ycombinator.com/newsfaq.html :)
Re:_hyperscript: A jQuery and JavaScript Alternative by SebastianKra on Wednesday April 21, 2021 @04:58PM (#26895371)
:D that's fitting for HN.

Instead of finding a more descriptive name or adding a short description below, they put it on a completely different site.

Re:_hyperscript: A jQuery and JavaScript Alternative by recursivedoubts on Wednesday April 21, 2021 @12:57PM (#26892239)
Thank you, I'll update the example. I usually stay in es5 for IE11 compatibility (htmx is still supporting IE11) so I tend to write js in a more archaic style.
Re:_hyperscript: A jQuery and JavaScript Alternative by epr on Wednesday April 21, 2021 @01:08PM (#26892423)
That 1% market share of IE gets smaller every day, as we wait with bated breath.
Re:_hyperscript: A jQuery and JavaScript Alternative by recursivedoubts on Wednesday April 21, 2021 @01:14PM (#26892506)
:) I know, I am looking forward to using IntersectionObserver in htmx.

But I'm a bit of a contrarian and every time someone tells me to drop IE support I think "Maybe I won't."

Re:_hyperscript: A jQuery and JavaScript Alternative by city41 on Wednesday April 21, 2021 @02:37PM (#26893715)
Also a heads up, the vanilla fade out demo doesn't work correctly (immediately disappears) as in the actual code it looks to be missing the transition line.
Re:_hyperscript: A jQuery and JavaScript Alternative by deniz-a on Wednesday April 21, 2021 @02:58PM (#26893984)
Thanks for reporting, fixed.
Re:_hyperscript: A jQuery and JavaScript Alternative by lyjackal on Wednesday April 21, 2021 @05:26PM (#26895647)
I generally agree that practically, focusing on the heavy weight technologies will be the most useful in the long run. In defense of DSLs, I do love them. It's the magic of doing a task specifically as the most intuitive magical incantation. A beginner can pick the DSL up easily and get excited about learning the underlying fundamentals. An expert can code complex scenarios more efficiently.

Still, there's a pretty steep curve to developing them, and that generally translates into a shorter lifetime unless they take off in popularity. For example, tooling support, for things like autocomplete, highlighting, debugging will need to be implemented. There's also a lack of community answering questions, making it difficult to pick up for beginners (no stack overflow, etc).

Re:_hyperscript: A jQuery and JavaScript Alternative by bobbylarrybobby on Wednesday April 21, 2021 @05:51PM (#26895912)
Won't the arrow function not bind `this` to the DOM element, causing it to refer to the window object? I think you have to use a real `function`, `function(){this.remove()}`
Re:_hyperscript: A jQuery and JavaScript Alternative by deniz-a on Thursday April 22, 2021 @05:54AM (#26900783)
Arrow functions have the same `this` as the scope where they are declared (in this case, an onclick attribute). Both would work in this case.
Re:_hyperscript: A jQuery and JavaScript Alternative by cerved on Thursday April 22, 2021 @03:52AM (#26900005)
Yes, I'm sorry but that JavaScript example code is terrible.

I realize this sounds harsh but truthfully, it made me immediately disregard the library. If this is how you would solve these issues in JavaScript I'm not taking you seriously.

The web API offers an elegant separation of content, style and logic and these examples are just stuffing everything into logic. Don't do this

Re:_hyperscript: A jQuery and JavaScript Alternative by deniz-a on Thursday April 22, 2021 @06:03AM (#26900877)
For a trivial example like fading out, you're right, but if you want to make dynamically generated animations, hyperscript's features are very helpful (The Web Animations API is a boon, but browser support isn't there yet).

Separation of HTML/CSS/JS doesn't always mean separation of concerns. Every application has a different definition of a "concern", and if it doesn't align with the separation between languages, you don't get decoupled code, you intensify the symptoms of tight coupling.

Re:_hyperscript: A jQuery and JavaScript Alternative by Lorin on Wednesday April 21, 2021 @02:05PM (#26893261)
Do you remember who said the quote? That's fantastic.
Re:_hyperscript: A jQuery and JavaScript Alternative by epr on Wednesday April 21, 2021 @02:19PM (#26893476)
I'm not sure to be honest, but the above quote is the result of me distilling the seed he planted in my mind into as concise a statement as possible. Unless I am mistaken, his original (I think it was a StackOverflow post related to JQuery) was much longer.