Live data from Hacker News

Show HN: A JavaScript UI library for imperative JSX

npmjs.com

31–40 of 55 posts

Re: Show HN: A JavaScript UI library for imperative JSX

#31
Thanks for sharing, neat. This makes me curious about the psychology of declarative vs imperative, and why some people gravitate towards one or the other (at least with UI code).

Back in the jQuery days, a lot of my hatred towards "JavaScript" was actually imperative UI code in hindsight. In the years since, I now enjoy declarative UI more but see some developers bang their head against declarative UI frameworks. It's an interesting contrast.

Re: Show HN: A JavaScript UI library for imperative JSX

#32

Earlier quoted context omitted.

I have to strongly agree with this. The entire point of react was to avoid all the challenges of old imperative coding of syncing up state with render state. The Dom digging was an absolutely genius idea to stop that nonsense and just render the correct state and let the framework handle the rest. I wrote a ton of backbone code, and was a major fan of jquery before Dom querying was even a feature of browsers. And onc…

Same, used jQuery for years and had a love/hate relationship with it. You're correct that React solved the imperative problems from before, but that's not the only factor to consider. You have to weigh the problems it solves against the problems that it causes.

Eh. For me, it was vastly worth it. Yes there are drawbacks to react. But I feel like the gains far far far outweigh them.

Re: Show HN: A JavaScript UI library for imperative JSX

#33
post #28

> The structure of your application state ends up being shaped by the UI, when it should be the other way around I don’t understand this premise at all. Are you saying your UI should be shaped by your application state? That doesn’t make any sense to me, surely the application state exists to implement a desired UI?

I could've said that better, what I really meant is that UI is (a) downstream of state, and (b) has a different structure than state. The UI is a tree but state is basically a graph, and it doesn't make sense to couple the two. This is the same position that SolidJS takes, for instance.

To respond to your last statement though, I feel the opposite is true. UI's don't exist for their own sake, they only exist to support the application and its behavior.

Re: Show HN: A JavaScript UI library for imperative JSX

#34
I would never want to write it the same element in multiple places like this.

That's one of the main points of templating in the first place: to write the code for a piece of output once, with all of the bindings that can affect it.

What happens here if you update the JSX for an element in one place and forget to do so in the others?

Re: Show HN: A JavaScript UI library for imperative JSX

#35
post #31

Thanks for sharing, neat. This makes me curious about the psychology of declarative vs imperative, and why some people gravitate towards one or the other (at least with UI code). Back in the jQuery days, a lot of my hatred towards "JavaScript" was actually imperative UI code in hindsight. In the years since, I now enjoy declarative UI more but see some developers bang their head against declarative UI frameworks. It'…

I also enjoy declarative UI. I hated imperatively building up the interface with jQuery, even with the helpers it just felt so tedious. This library is my attempt to have my cake and eat it too.

Like I love being able to just write

hello world

in my javascript, it feels very nice. At the same time, with React I absolutely hate it when I do things that are inherently imperative.

A prime example is the following: I have a list of items that can be named by the user, so each item's display name will be a text input. When the user clicks the "create new item" button, a new item is added to the list, and the text input of the new item is immediately focused as soon as it's added to the DOM.

^ doing this in React sucks.

Re: Show HN: A JavaScript UI library for imperative JSX

#36

Mithril seems like it can do something pretty similar: https://mithril.js.org/jsx.html (Not trying to discourage you, just linking it)

No this is great, thanks for sharing. I've had several people point me to things in this thread that I'd never seen before, and I appreciate it.

Re: Show HN: A JavaScript UI library for imperative JSX

#37

JSX without React is also kind of fun: https://medium.com/@victor.dramba/can-you-do-jsx-without-rea... and it's working example at: https://github.com/dvictor/jsx-no-react/blob/master/index.ts...

Agreed! About 5 or 6 years ago I wrote a library to demonstrate to my teams that JSX a) was not magic b) not limited to React. After that was done I became a little obsessed with making the library the fastest JSX renderer - which I think is still true: https://github.com/i-like-robots/hyperons

Add me to this club of JSX hackers: https://crwi.uk/posts/hiccup/

I used this approach to make a syntax highlighted text editor in https://crwi.uk/experiments/text-editor/

Re: Show HN: A JavaScript UI library for imperative JSX

#38
post #29

Earlier quoted context omitted.

This is IMO a great example for React and declarative programming. > There's no special concept to understand By not understanding that you need to cleanup timers when your view unmounts, you've introduced a subtle bug that your coworker will discover in 6 months when users report that the counter sometimes increases twice as fast. I've worked on Angular-like apps before, and storing and cleaning up timers was always…

> By not understanding that you need to cleanup timers when your view unmounts I think this library eschews the entire concept of mounting so that point is kind of moot. Will you likely re-invent it again in any non-trivial app, sure, but when you're writing imperative JS it's probably a MPA where code runs top to bottom. Clean up will happen when everything gets thrown away on navigation.

Yep, and if you are writing an SPA where cleanup is an issue, personally I think a web component would be a better fit. It's native to the platform and offers lifecycle hooks out of the box. I'm currently playing around with how my library might be used for web components.

Re: Show HN: A JavaScript UI library for imperative JSX

#39
post #37

Earlier quoted context omitted.

Agreed! About 5 or 6 years ago I wrote a library to demonstrate to my teams that JSX a) was not magic b) not limited to React. After that was done I became a little obsessed with making the library the fastest JSX renderer - which I think is still true: https://github.com/i-like-robots/hyperons

Add me to this club of JSX hackers: https://crwi.uk/posts/hiccup/ I used this approach to make a syntax highlighted text editor in https://crwi.uk/experiments/text-editor/

These are awesome (both parent comments). Love seeing that I'm not alone in my JSX curiosity.

Re: Show HN: A JavaScript UI library for imperative JSX

#40

If you want to use JSX without React see this 500-line lib: https://github.com/wisercoder/uibuilder And here's an app built using this lib: https://github.com/wisercoder/eureka/tree/master/webapp/Clie...

This is great, I'm gonna have to start making a list because this is like the 5th or 6th library I've been linked to in this thread. Love it, thanks for sharing.
Post reply on HN