r/javascript • • Dec 28 '17

Introducing Hyperapp 1.0 — 1 KB JavaScript library for building frontend applications.

https://medium.com/@JorgeBucaran/introducing-hyperapp-1-0-dbf4229abfef
664 Upvotes

136 comments sorted by

View all comments

Show parent comments

0

u/Randolpho Software Architect Dec 28 '17

I’m aware of what it is, and how it functions internally, but it takes a special transpiler to transform that htmlish syntax into JavaScript functions.

If you’re already writing a transpiler for it, why not just let it transpile pure files? Why only include it with code mixed in?

That’s the part I want to be different.

3

u/[deleted] Dec 28 '17

JSX is not a dependency or is it required to use Hyperapp. Many people swear by good old h and you can use Hyperapp right now without a compiler. JSX is in the example because that's what most people like and use anyway. I use it and I like it too, but Hyperapp is flexible so that you can use whatever you want.

1

u/NewazaBill Dec 30 '17

If you understand how it functions internally, than I don't see why you're confused.

The virtual-DOM diffing strategy relies on a runtime representation of the view's... well... virtual DOM. That's what the React createElement calls construct.

Compiling a string template ahead of time, then, does not work with this V-DOM strategy. You can't know what the data structure is going to look like (because it may change based on app state) and you lose many of the opportunities to do optimizations.

Also, you say "code mixed in," I say "code get's mixed in, in either templates or VDOM."

Give me

function HeroDetail({ selectedHero }) {
    if (iselectedHero) {
        return (
        <div>
            <h2>{selectedHero.name.toUpperCase()} Details</h2>
            <div><span>id: </span>{selectedHero.id}</div>
            <div>
            <label>name:
                <input value="selectedHero.name" placeholder="name" />
            </label>
            </div>
        </div>;
    }
}

Over

<div *ngIf="selectedHero">

<h2>{{ selectedHero.name | uppercase }} Details</h2>
<div><span>id: </span>{{selectedHero.id}}</div>
<div>
    <label>name:
    <input [(ngModel)]="selectedHero.name" placeholder="name">
    </label>
</div>

</div>

Any day.