helix

https://github.com/Lokeh/helix
Eliraz 2020-05-18T16:55:44.328100Z

Hello, I'm pretty new to ClojureScript and I'd like to start a new project with it, I came across this library, how would one manage a state in helix ?

Eliraz 2020-05-18T16:57:12.329300Z

I mean. reagent has re-frame and atoms , is there anything that works with helix ?

lilactown 2020-05-18T16:57:37.329700Z

hey Eliraz! helix is meant to be a pretty small syntax wrapper around React

lilactown 2020-05-18T16:59:10.330100Z

you can check out the docs here: https://github.com/Lokeh/helix/blob/master/docs/hooks.md#maintaining-state

lilactown 2020-05-18T16:59:59.331Z

those docs talk about syntax mainly. to understand managing state w/ React Hooks, this is a good starter: https://reactjs.org/docs/hooks-state.html

Eliraz 2020-05-18T17:04:53.332800Z

oh, yeah well I'm a react developer for the past 7 years. I know how to manage state in react's world. however in clojurescript I, for some reason, imagined to myself that there are solutions.

Aron 2020-05-18T17:05:06.333400Z

there are, you can use those too I think

Eliraz 2020-05-18T17:05:52.334500Z

can re-frame work with helix?

lilactown 2020-05-18T17:06:25.335600Z

like I said, helix is meant to be a very thin wrapper. local component state works great for a majority of cases.

Aron 2020-05-18T17:06:26.335800Z

but I would say that being in the same position as you are, started cljs recently in a more serious manner and did lots of react before already, being able to just use hooks and functional components really simplified a lot

lilactown 2020-05-18T17:06:50.336300Z

if you’re looking for a global state management solution, helix doesn’t have one built in other than what React gives you

lilactown 2020-05-18T17:07:13.336900Z

re-frame can work with helix. you’ll need to write some hooks to work with it

Eliraz 2020-05-18T17:07:25.337100Z

okay I understand.

Eliraz 2020-05-18T17:08:46.338500Z

I'm just trying to figure what will work best for me and honestly I feel kind of lost, I mean if i'd like to use a library like effector so I'll need to convert cljs to js everytime right?

lilactown 2020-05-18T17:09:40.338900Z

I’m not sure, I haven’t used effector

lilactown 2020-05-18T17:10:37.339700Z

is there a reason you need a global state management solution?

Eliraz 2020-05-18T17:11:05.340200Z

yes actually, the nature of my app requires some state to be globally

Eliraz 2020-05-18T17:11:52.341200Z

I mean, I could manage without a global state, I just think it will be bit of a hustle

lilactown 2020-05-18T17:12:18.341600Z

is it something that could be handled via React Context + local state?

Eliraz 2020-05-18T17:12:37.342100Z

oh of course it could

Eliraz 2020-05-18T17:13:47.343900Z

React context is very non-efficient though, it will render every listener even if the bit that changed does not concern that listener

lilactown 2020-05-18T17:14:27.344700Z

yeah. it’s a tradeoff: less complexity / dependencies, but worse out of the box performance

lilactown 2020-05-18T17:14:49.345100Z

I agree with being lost w.r.t. making decisions about picking libs for managing state 😅

lilactown 2020-05-18T17:14:59.345400Z

which is why I don’t really suggest anything other than React right now, since it’s a lot easier to migrate away from that if it becomes bad

lilactown 2020-05-18T17:15:50.347100Z

if you start with React Context, wrapped in a custom hook, it’s easier to refactor that to use e.g. re-frame, effector, or even just a CLJS atom with a watcher

Eliraz 2020-05-18T17:16:01.347300Z

The only reason I didn't go with reagent is that it won't leverage the functional components of react.

lilactown 2020-05-18T17:16:17.347900Z

that’s my experience, though

orestis 2020-05-18T17:16:37.348800Z

@eliraz.kedmi157 If you’re willing to pre-alpha-test something, I’m working on https://github.com/orestis/reseda . The whole thing is 200-300 lines of code, so you should be able to just fork or copy the relevant bits at some point.

Eliraz 2020-05-18T17:17:35.349600Z

I dont mind trying new things, I already jumped into the rabbit hole anyways 🙂

orestis 2020-05-18T17:18:52.350300Z

No promises that this is even makes sense but as @lilactown says the API is what matters — you can easily replace the underlying bits.

Eliraz 2020-05-18T17:19:36.350800Z

Sure I'll give it a shot

orestis 2020-05-18T17:19:38.351Z

Here’s the Reagent BMI demo, converted: https://github.com/orestis/reseda/blob/master/src/reseda/demo/bmi.cljs

orestis 2020-05-18T17:19:56.351600Z

We should move this discussion to #react since it’s not Helix specific.

Eliraz 2020-05-18T17:20:34.351800Z

sure

Eliraz 2020-05-18T17:21:48.352700Z

@lilactown how hard is it to write a wrapper to a js library? I mean, maybe I could wrap effector ? I really like it, I think it's really good.

alidlorenzo 2020-05-18T17:23:09.353100Z

i wonder how well wrapping Recoil would go

lilactown 2020-05-18T17:27:21.353400Z

depends wholly on the JS library

lilactown 2020-05-18T17:27:33.353700Z

and what you want the syntax to be

lilactown 2020-05-18T17:29:39.354100Z

you can call any JS function like a CLJS function

lilactown 2020-05-18T17:29:55.354400Z

you can create JS objects/arrays

Eliraz 2020-05-18T18:24:27.355500Z

I understand. BTW, how costly is the conversion from cljs data structures to js objects / arrays? is it being done on runtime?

lilactown 2020-05-18T18:29:07.356100Z

helix does takes a best-effort approach to do no runtime conversion of immutable data to JS objects / arrays

lilactown 2020-05-18T18:30:31.357100Z

when defining a component with helix, props get converted to a data type that can be used easily with destructuring/etc. without doing a recursive conversion

lilactown 2020-05-18T18:30:50.357400Z

it uses cljs-bean: https://github.com/mfikes/cljs-bean

lilactown 2020-05-18T18:31:36.358300Z

when creating elements, your props will get converted to a JS object automatically. if it can be done, helix will actually rewrite the props map you pass in as a JS object at compilej-time

lilactown 2020-05-18T18:31:41.358500Z

docs here: https://github.com/Lokeh/helix/blob/master/docs/creating-elements.md

2020-05-18T21:52:54.360600Z

@eliraz.kedmi157 What has brought you to ClojureScript? Are there some specific problems cljs helps you to solve? You being an experienced React dev, I'd really like to hear your perspective.

lilactown 2020-05-18T23:46:46.361200Z

are people using git deps for helix?

lilactown 2020-05-18T23:46:52.361400Z

I’m thinking of changing my github username