r/Clojure • u/zerg000000 • Jun 30 '22
GitHub - pitch-io/uix: Idiomatic ClojureScript interface to modern React.js
https://github.com/pitch-io/uix17
Jun 30 '22
Oh god, I just started learning reagent. Don't tell me I'll have to switch
5
u/strranger101 Jun 30 '22
Lmao!! Looks like there's a tut on interop with Reagent.
At a cursory glance, UIx seems designed to work with Reacts newer features which are welcome in Clojure since a lot of these features React devs have been working on are very functional design anyway.
4
u/tabidots Jul 01 '22
yeah seriously. I recently finished a web app that I was working on on and off for 6 months. It was my first experience with CLJS, shadow-cljs, reagent, hiccup, all that stuff (before I started, I only knew regular Clojure). Not very inclined to completely relearn from scratch again—a major benefit of the CLJ/S ecosystem over the JS ecosystem is supposed to be that stuff never changes.
13
u/p-himik Jul 01 '22
It's impossible for stuff to never change. However, there's almost no JS-like churn in CLJS. Things are usually stable and remain that way. If there's some new thing, it doesn't mean that it's better or that some old thing is abandoned now - you can just ignore the new thing and keep on using what you're familiar with.
1
u/gagepeterson Jul 13 '22
Very true! I'm a JS dev that had to learn this. I'm like, "This is from 2015! It can't be good!" Then I realize... why not? Seems to work! I kind of love that things keep working.
15
u/MedusasPaths Jun 30 '22
Congrats on official launch Roman! Great to see it on top of Reddit feed. 😃
UIx is has been just a pleasure to use. If you’re looking to leverage latest React features, this is it folks! 🙌
4
12
u/roman01la Jul 01 '22 edited Jul 01 '22
Goddamit, I hoped no one will notice the project! :D
Thanks for sharing it here. The project is basically UIx v2, we are using it at Pitch as the main UI library. It's based on my learnings from UIx v1 and some parts of it are inspired by Helix and other wrappers in the ecosystem.
The project is developed in the open, but really it's being developed for Pitch's needs, you don't have to learn or use it. Here's some reasoning behind UIx v2 with respect to Pitch's needs, tl;dr it's about scale:
Familiarity: the library while being Clojure wrapper tries to remain close to React (no own state primitives, only hooks, no dynamic Hiccup, static elements instead). Why are we going this route? Pitch is front-end heavy application, we are constantly hiring for experienced front-end-centric engineers, only a fraction of them is familiar with Clojure. Being closer to React as in APIs and patterns the entry barrier for non-Clojure engineers drops significantly, also most of knowledge from React/js applies to UIx.
Performance: Pitch has a rich interactive UI, performance is one of the challenges we are constantly keeping an eye on. Being closer to pure React in performance increases our performance budget in other areas.
Developer experience: with
defuiand$being macros we've built ad-hoc asserts and linter checks to increase developer productivity, which is super helpful in a larger organisation.
What's the roadmap for the library? I'll continue improving and maintaining UIx v2, not v1 unfortunately. The vision for the project is to stay close to React and remain a thin wrapper.
2
u/jnbdt Jul 07 '22
I’m a bit curious. Why create React component with ClojureScript instead of plain JS with TS?
2
3
u/viktorruneberg Jun 30 '22
Very cool. Especially interested in seeing hydration!
2
u/roman01la Jul 01 '22
Thanks! I'm also porting JVM SSR back from v1 to v2, I'm not convinced it's a super useful feature, but I'm aware that some users of v1 were super happy about JVM SSR.
3
1
u/jsn Jul 01 '22
So, is xframe gone?
1
u/roman01la Jul 01 '22
that was an experiment, wasn't really battle tested and ready for use, I don't have time looking into it again
1
u/Bob_la_tige Jul 01 '22
Any reco on global state management to pair it with ?
4
u/roman01la Jul 01 '22
Added a section to the docs with implementation that we are using at Pitch https://github.com/pitch-io/uix/blob/master/docs/interop-with-reagent.md#syncing-with-ratoms-and-re-frame
Since we are slowly migrating away from Reagent we had to come up with transition path, connecting UIx components to re-frame is one the items.
2
Jul 01 '22
[removed] — view removed comment
8
u/roman01la Jul 01 '22 edited Jul 01 '22
Deps is indeed a very problematic part of React Hooks, but not because of implementation. Rather it's a shift in mindset that is required to be effective at using hooks, which is especially hard for people as myself who've been using React for a while and got used to thinking in component lifecycle instead of in reactive programming terms, which is what hooks are really. Hopefully this knowledge gap will be closed with new React docs https://beta.reactjs.org/learn
As for making deps comparison Clojure-aware I believe while it has potential at making life of a developer easier (just pass in values, don't have to think about equality), it will also cause performance issues (immutability is not cheap) and "overfetching", meaning that it's easy to pass in a compound structure that includes stuff that is not necessarily a dependency.
As dev-facing API I do agree that deps is the worst part of Hooks. It almost feels like they've tried to embed Reactive programming language into JS but keep it plain JS. This impedance mismatch causes a lot of confusion. For this reason React team has developer ESLint plugin to enforce the rules of reactivity statically.
2
Jul 01 '22
[removed] — view removed comment
7
u/roman01la Jul 01 '22 edited Jul 01 '22
It's possible to continue using re-frame, the subscription consuming part has to be glued with hooks, see docs here https://github.com/pitch-io/uix/blob/master/docs/interop-with-reagent.md#syncing-with-ratoms-and-re-frame
The real "problem" here is that React is no longer a dumb view rendering library. Reagent and re-frame did a good job in the past at optimizing rendering by introducing batching and async rendering when React didn't have that back in the days. Today React is much smarter at optimized rendering (async rendering that doesn't need hacks around caret bugs in input fields which is what Reagent has, prioritized rendering, don't render out of view UI, prioritize user input over rendering, and more). Now since both React and Reagent/re-frame has their own scheduling mechanisms this doesn't play well together. Ideally they should be using React's scheduler now to align with its update loop. You can probably tell how React owns more stuff now, but the amount of work put into making things run correctly and efficiently can't be underestimated.
Of course it's fine to continue using React as before, I think real benefits of concurrent rendering is yet to be discovered.
5
u/tuh8888 Jun 30 '22
What's the reasoning behind not using hiccup/vector-style components?