Fork me on GitHub
#helix
<
2020-05-18
>
Eliraz16:05:44

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 ?

Eliraz16:05:12

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

lilactown16:05:37

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

Eliraz17:05:53

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.

Aron17:05:06

there are, you can use those too I think

Eliraz17:05:52

can re-frame work with helix?

lilactown17:05:25

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

Aron17:05:26

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

lilactown17:05:50

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

lilactown17:05:13

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

Eliraz17:05:25

okay I understand.

Eliraz17:05:46

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?

lilactown17:05:40

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

lilactown17:05:37

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

Eliraz17:05:05

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

Eliraz17:05:52

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

lilactown17:05:18

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

Eliraz17:05:37

oh of course it could

Eliraz17:05:47

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

lilactown17:05:27

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

lilactown17:05:49

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

lilactown17:05:59

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

lilactown17:05:50

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

Eliraz17:05:01

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

lilactown17:05:17

that’s my experience, though

orestis17:05:37

@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.

Eliraz17:05:35

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

orestis17:05:52

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

Eliraz17:05:36

Sure I'll give it a shot

orestis17:05:56

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

Eliraz17:05:48

@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.

alidlorenzo17:05:09

i wonder how well wrapping Recoil would go

lilactown17:05:21

depends wholly on the JS library

lilactown17:05:33

and what you want the syntax to be

lilactown17:05:39

you can call any JS function like a CLJS function

lilactown17:05:55

you can create JS objects/arrays

Eliraz18:05:27

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

lilactown18:05:07

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

lilactown18:05:31

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

lilactown18:05:36

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

smt21:05:54

@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.

lilactown23:05:46

are people using git deps for helix?

lilactown23:05:52

I’m thinking of changing my github username

orestis06:05:36

Haha I always search for lilactown hx and then I remember :)