r/javascript • • Sep 16 '17

1 KB JavaScript library for building frontend applications.

https://github.com/jbucaran/hyperapp
316 Upvotes

50 comments sorted by

7

u/[deleted] Sep 16 '17 edited Sep 16 '17

We have a little community on Slack and welcome anyone that wants to help and share their feedback!

8

u/Meowish Sep 16 '17 edited May 17 '24

Lorem ipsum dolor sit amet consectetur adipiscing, elit mi vulputate laoreet luctus. Phasellus fermentum bibendum nunc donec justo non nascetur consequat, quisque odio sollicitudin cursus commodo morbi ornare id cras, suscipit ligula sociosqu euismod mus posuere libero. Tristique gravida molestie nullam curae fringilla placerat tempus odio maecenas curabitur lacinia blandit, tellus mus ultricies a torquent leo himenaeos nisl massa vitae.

6

u/[deleted] Sep 16 '17

I am always eager to improve the docs and examples, if you have a specific request or something you'd like to see I'd love to work on it. I'm all ears.

2

u/Meowish Sep 16 '17 edited May 17 '24

Lorem ipsum dolor sit amet consectetur adipiscing, elit mi vulputate laoreet luctus. Phasellus fermentum bibendum nunc donec justo non nascetur consequat, quisque odio sollicitudin cursus commodo morbi ornare id cras, suscipit ligula sociosqu euismod mus posuere libero. Tristique gravida molestie nullam curae fringilla placerat tempus odio maecenas curabitur lacinia blandit, tellus mus ultricies a torquent leo himenaeos nisl massa vitae.

17

u/[deleted] Sep 16 '17

6

u/Meowish Sep 16 '17 edited May 17 '24

Lorem ipsum dolor sit amet consectetur adipiscing, elit mi vulputate laoreet luctus. Phasellus fermentum bibendum nunc donec justo non nascetur consequat, quisque odio sollicitudin cursus commodo morbi ornare id cras, suscipit ligula sociosqu euismod mus posuere libero. Tristique gravida molestie nullam curae fringilla placerat tempus odio maecenas curabitur lacinia blandit, tellus mus ultricies a torquent leo himenaeos nisl massa vitae.

3

u/[deleted] Sep 17 '17 edited Sep 18 '17

/u/Meowish: I missed your edit and I hear you. I'll make sure to talk about "code organization" on the docs somewhere and work on a more useful quick start example after "hello world" based on your feedback.

For now, I added another important piece of the puzzle, "building" to document how to setup JSX/Hyperx tooling.

Thanks for your feedback!

5

u/prudan Sep 16 '17

Thanks for the link! I've been looking for something that isn't react or angular, so I was probably going to end up going with Vue.

I'm certainly willing to give this a try though; This does everything I need and nothing I don't, and that's important.

I do love Typescript though, so I'm going to wait until your typings are completed. I read a good bit last night and can appreciate what's taking so long.

Thanks again!

2

u/[deleted] Sep 16 '17

Sweet! Try it out and let us know what you think. There's a Slack where you talk to us and there's even a subreddit where you can share what you built, ask questions or post whatever feedback you have:

1

u/atomheartother Sep 17 '17

I definitely recommend Vue still, I haven't tried hyperapp and it looks really neat but I've had a very good experience using Vue.

17

u/localvoid Sep 16 '17

It would be great if framework authors that has a primary focus on library size at least tried to describe features that available in libraries like React and which they intentionally ignoring to reduce size of the library.

12

u/[deleted] Sep 16 '17 edited Sep 24 '17

This is a link to the repo. Here is a link to an article that touches on what you asked. Hope it helps.

Side note: I am not sure that the "official" docs should go out of their way to discuss how Hyperapp is different from React or other libraries, but I would be happy to hear what more people think and work on it.

Thanks for bringing it up.

0

u/localvoid Sep 16 '17

I understand use cases, edge cases that it won't be able handle, flaws in API and behavior because I've been doing it for a long time, but average web developer will open readme and here is the first thing that it will see "We have aggressively minimized the concepts you need to understand while remaining on par with what other frameworks can do.". Maybe a little bit more honesty? ;) Yes, there is a market for small libraries like this that cover just 80% of use cases and for many projects it will be enough, but saying that it is "on par with what other frameworks can do" isn't fair.

3

u/[deleted] Sep 16 '17 edited Sep 16 '17

To minimize concepts while still remaining on par with what others can do is the mission that I embarked on when I started the project.

I've been doing it for a long time...

Please share what is that have you been doing for a long time. Maybe Hyperapp already takes care of it, or not! If you don't say exactly what is in your mind I won't be able to tell you if it'll work or not.

-3

u/localvoid Sep 16 '17

To minimize concepts while still remaining on par with what others can do is the mission that I embarked on when I started the project.

It is a great that it is a mission for this project, but right now it is far away from its goals, and by the time it will be on par, it won't be 1kb. Covering major use cases is the easiest part when building UI library, dealing with small details is the hardest part and hyperapp can't even assign value for input fields properly to make sure that it will have consistent behavior in all browsers.

Please share what is that have you been doing for a long time.

Working on a design and implementation of UI libraries.

5

u/[deleted] Sep 16 '17

Dealing with the small details is the hardest part and we are dealing with them. What is it exactly that didn't work for you?

can't even assign value for input fields properly to make sure that it will have consistent behavior in all browsers

Do you have an example of that? Input fields have been working great since day one.

-9

u/localvoid Sep 16 '17

If you are building Virtual DOM based UI library, it would be a good idea to read React sources, you'll learn alot, for example how to deal with input values: https://github.com/facebook/react/blob/master/src/renderers/dom/stack/client/wrappers/ReactDOMInput.js

I really don't want to go through every flaw in your library, because many things aren't necessary when you targeting a different audience and there is nothing wrong with it. I just thought that it was intentional decision in your library design.

6

u/[deleted] Sep 16 '17

You don't have to go through every flaw, I would be more than happy if you could just point out a single example where Hyperapp failed to do whatever was you were doing.

You seem to be available since you are engaging in this discussion, so why can't you just say what was exactly the problem you had? If there is genuinely a bug or we are lacking somewhere, I would like to work on it right away.

-7

u/localvoid Sep 16 '17

I would be more than happy if you could point out a single example where hyperapp failed to do what you expected.

https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/renderers/dom/stack/client/wrappers/ReactDOMInput.js#L60-L69

8

u/[deleted] Sep 16 '17

Can you make a pen with the problem? Here is a template.

1

u/okwolf Sep 16 '17

https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/renderers/dom/stack/client/wrappers/ReactDOMInput.js#L60-L69

Keep in mind that a lot of the complexity in your example (and other parts of React) are the synthetic events for supporting legacy IE 8/9 under a single events system. Hyperapp targets IE 10+

→ More replies (0)

0

u/[deleted] Sep 24 '17

[deleted]

1

u/[deleted] Sep 24 '17 edited Sep 24 '17

link is

Link was down indeed! Here you go.

Is there a way to have an interceptor for http requests like I can do in Vue.

¯\(ツ)/¯ I haven't tried something like that, if you do let me know if it worked!

3

u/DOG-ZILLA Sep 16 '17

It's odd isn't it? This absolute obsession with filesize as though that's the number one thing anyone is after? It's not.

Authors would be better positioned to show us how it makes our lives easier.

With minification, gzip, CDN's etc filesize isn't the number one thing I'm looking for.

4

u/[deleted] Sep 16 '17

Me neither, but it's awesome I can read the source and understand what's going on in just a few hours. IMO a normal person can't do that with most other frameworks.

So, what are the things you look for on a JS view framework? :)

2

u/moljac024 Sep 16 '17

Yes but what are you giving up for the opportunity to understand the framework in half an hour?

What I look for in a library/framework is to be saved from thinking about certain problems and know they are solved. I want them to abstract complexity away from me. I would gladly take more abstraction at the cost of understanding. I like to know WHAT it's doing, not HOW.

2

u/[deleted] Sep 16 '17

Yes but what are you giving up for the opportunity to understand the framework in half an hour?

Sounds like encouragement to me.


I like to know what is doing as well as how, that's why I built it. To understand how they work and to choose just the right amount of what that I like.

4

u/okwolf Sep 16 '17

If the source code is approachable enough that you can understand it on the first try and keep all of its functionality in your head at once, then you already know everything it can do and where there are gaps in functionality you would need to implement for your use cases.

2

u/okwolf Sep 16 '17

In the same amount of time it took me to read 5% of the React source I was able to understand the entirety of Hyperapp, and make proposals on API improvements for core. It turns out that the Hyperapp API happens to be extremely extensible, and most functionality you can dream up that's not in core can be added via mixins.

0

u/[deleted] Sep 16 '17

[deleted]

1

u/DOG-ZILLA Sep 16 '17

I want those things TOO. What I'm saying is that for anyone building something, you have to help people see where the real value is in using it. Show us why it solves X problem. A fixation on file size is not really explaining anything.

1

u/[deleted] Sep 16 '17

Ok, sorry for posting the file size on the title of the post. I will make sure not to mention this feature of the framework in the future.

0

u/[deleted] Sep 16 '17

[deleted]

4

u/[deleted] Sep 17 '17

I didn't arrive at that number by sheer luck. The most challenging aspect of building Hyperapp has always been fixing bugs and adding new features while maintaining the bundle size in check.

2

u/pygy_ @pygy Sep 16 '17

A small code size is a major feature if your audience uses mobile phones.

3

u/[deleted] Sep 16 '17

I've used hyperapp at work for some time and is absolutely amazing!

1

u/[deleted] Sep 16 '17

Sweet! How did it go? and are you still using it?

What did you find lacking and would you like to see in the future?

2

u/[deleted] Sep 18 '17

it was really nice, worked very well my boss is happy i am happy and really liked the Elm architecture, definitively i will be using hyperapp at work and in personal projects. i would like to use hyperapp in all my projects but for that i really need seo.

3

u/[deleted] Sep 18 '17

Good news! You can hydrate your pre-rendered HTML with Hyperapp ;)

This is a relatively new feature (a month or so), so maybe it wasn't available when you first tried it out or you never heard of it mentioned on our docs.

3

u/[deleted] Sep 18 '17

yes, i'm already using that feature is really nice and so simple! what i don't know how to do is the ssr part but with routes. i have in mind something like staticRouter from ReactRouter4 using the match function from the hyperapp router.

5

u/zaceno Sep 16 '17

In response to the general question of: "What does React have that Hyperapp doesn't, to let Hyperapp be so small?" - Any framework will make a tradeoff of what it does for you, and what it leaves up to you.

It's not only that Hyperapp is small -- it's that it's simple. You can just pick it up and go -- no CLI-tool to scaffold out a project, no bundlers necessary. Essentially zero boilerplate. Just start making your app.

I hear some say: "Well that's all well and good, but how far can you take it before it starts getting in your way? Before you start wishing you wrote your app in something else?"

So far I haven't encountered anything you can't do in Hyperapp (with the exception of supporting legacy browsers). (Disclaimer: my only previous experience with any of the current "big" frameworks is with Vue.js -- and at a hobbyist level) This is where the simplicity tradeoff comes into play:

Every time I've encountered something Hyperapp doesn't do built-in, it's been a cinch to work in a custom solution. Every time Hyperapp did something I didn't understand or expect, five minutes of looking at the source has been enough to figure out my mistake.

In contrast, similar situations with Vue or Knockout have had me either give up or use a cookie-cutter solution that's only almost what I was trying to do.

So, if I were to start on a big, complex, business critical app today, I would actually be more confident doing it in Hyperapp, than in any of the other bigger, more complex frameworks -- despite how young it is.

The last big, complex, business-critical app I was involved in was written in Backbone (yeah -- it's been a while ;) ) In a way, I kind of see Hyperapp as the Backbone of 2017. When we selected Backbone for the project, it was for all the same reasons above. It's not sexy, but tiny, straightforward and unmagical. Customizing behavior is trivial. That app is still going strong, still under active development. Although the current devs sometimes have wished for some more modern constructs, the framework itself has never been an impediment.

0

u/[deleted] Sep 16 '17

[deleted]

7

u/[deleted] Sep 16 '17 edited Sep 16 '17

I think Mithril is somewhere in the middle, but closer to React in the spectrum.

Hyperapp has a built-in state management solution out of the box. All of it is implemented in these 100 LOC. The rest is the VDOM. The entire "framework" is under 300 LOC.

Compared to React, Hyperapp is a simplified, Elm-inspired React+ReactDOM+Redux+ReduxThunk. Since all of it is built-in, there is literally zero boilerplate.

5

u/pygy_ @pygy Sep 16 '17

Mithril core contributor here

In terms of capabilities, Mithril is comparable to a DOM-only React (without PropTypes) + React Router + a Fetch polyfill (and it comes with an optional stream lib).

There are good TypeScript typings that support declaring types for the attrs (~props in Mithril lingo) and the state though, to make up for the lack of PropTypes.

AFAIK Mithril has a better keyed diff engine, stateful components and hooks that fire both before and after the view is rendered.

The Hyper state management is very well though out, and Mithril doesn't have anything like that builtin but it can be emulated.

I really appreciate the way /u/jbucaran managed to integrate the state and DOM updates with so little code.

4

u/[deleted] Sep 16 '17

I read that article a few weeks ago. Great writeup. With that approach you still end up without a single state tree, so it doesn't work for me.

The author said he failed to implement a fractal architecture, and I can't blame him, but we have come a long way since the project was first released when none of these ideas had been explored yet.

Fractal state in a single state atom can be done.

2

u/lhorie Sep 17 '17 edited Sep 17 '17

As others said, Mithril falls somewhere between hyperapp and react in terms of functionality. Some of the things that it provides over hyperapp:

  • onbeforeupdate lifecycle method (analogous to shouldComponentUpdate in React)

  • onbeforeremove lifecycle method (basically for "run this animation and then remove the dom element" cases)

  • fragment vnode type, basically you can return arrays from components (similar to React Fiber)

  • lifecycle methods in every node, including text node, fragments, html nodes and of course components

  • data fetching (optional)

It doesn't provide any code for state management per se, but rather documents a pattern that works for 95% of projects. It's possible to use other patterns and libraries, as u/pygy_ pointed out.

3

u/[deleted] Sep 17 '17

Hi /u/lhorie! :)

Sounds good, but it is not completely accurate: we also offer an "official" router, VDOM events in every node (you are right about text nodes), and oncreate, onupdate and onremove can be used for animation just as well, so I didn't choose to complicate the API with onbeforeupdate, onbeforeremove, etc.

I am not going to blame you for not knowing every detail about Hyperapp! Thanks for sharing your feedback.

3

u/lhorie Sep 17 '17 edited Sep 17 '17

Ah thanks for the correction. I'll fix my other comment

Do you have an example of animations before removal? It didn't seem to be supported from looking at the source (at least not without doing extra work in app space)

EDIT: btw, I forgot to say this earlier, but I really like what you did w/ hyperapp, it's a really cool project :)

4

u/zaceno Sep 17 '17

There aren't animation features per se in Hyperapp, but this line: https://github.com/hyperapp/hyperapp/blob/712516a7ca2355f0a5dd7671e30f13b01c70173a/src/app.js#L176 tells you that if you use the onremove VDOM event, then hyperapp will not remove it -- that's up to you.

So you can do your own fade-out (or whatever) animation, and then remove the element once it's done. So you are correct in that it leaves extra work to be done in app-space.

It's not too much work, in the simple cases anyway. Incidentally, for the more complex cases, I made https://github.com/zaceno/hyperapp-transitions

3

u/pygy_ @pygy Sep 17 '17 edited Sep 17 '17

Now that's smart :-)

Edit: it may be nice to pass the parent as well to the onremove hook.

3

u/[deleted] Sep 18 '17

Yup! We are deliberating it! :P

0

u/[deleted] Sep 16 '17

[deleted]

5

u/[deleted] Sep 16 '17

/u/AndyJessop Thanks, sure, the most popular nowadays is js-framework-benchmark and Hyperapp is there.

2

u/okwolf Sep 16 '17

The best thing about this is that it's so small you can literally read the source and understand what's going on pretty well within half an hour.

+1 to this. If you spend the same effort trying to understand React+ReactDOM+Redux+ReduxThunk, you'll probably think there's Voodoo magic powering them. By being so much more approachable we can get contributions from a much larger community, which I believe will lead to a healthy ecosystem.