react

"mulling over state management stuff"
orestis 2020-05-17T15:56:10.184100Z

Here’s finally my working version of useMutableSource - flavored state in global atom.

👀 1
orestis 2020-05-17T15:57:07.185400Z

Essentially: put your state in an atom, subscribe to changes via functions, your component rerenders.

orestis 2020-05-17T15:57:48.186200Z

Concurrent Mode friendly, but there is a stable flavor of the api too.

orestis 2020-05-17T15:58:33.187600Z

I still need to test that it works with the currently stable React, but I’m pretty certain it does with the few code changes.

orestis 2020-05-17T15:59:17.188600Z

Baby woke up just as I pushed so need to delay any further exploration 👶:skin-tone-2:

lilactown 2020-05-17T16:02:33.188900Z

looks neat!

lilactown 2020-05-17T16:02:46.189300Z

do you feel the protocol indirection adds a lot of value yet?

lilactown 2020-05-17T16:03:34.190Z

compared to e.g. a hook that wraps an atom with useMutableSource directly?

orestis 2020-05-17T16:05:22.190700Z

Is there a way to get a list of all the watchers of an atom?

orestis 2020-05-17T16:07:34.191800Z

But mainly I want a protocol so I can do things like support custom equality functions per subscription, tooling, and so forth.

alidlorenzo 2020-05-17T16:47:32.193200Z

Am I correct in understanding that reagent does not pre-compile hiccup templates at all? couldn’t find indication in docs/code that it did. The reason I ask is cause declaring components as vectors of data (versus function calls) has grown on me now that I’m more familiar with Clojure. Could similar performance as Helix not be achieved by pre-compiling hiccup too? @lilactown I guess this would be more inline with your experiments with Thump, though it seems like data readers aren’t fully supported*, nor recommended, in shadow-cljs. but same could be done with one initial macro call. here’s what i’m experimenting with now

(r/h [rn/View {:style []} 
        [rn/Text "Foo"]
        [rn/Text "Bar"]])
versus
($ rn/View {:style []}
     ($ rn/Text "Foo")
     ($ rn/Text "Foo"))
I’m liking the former for composing elements, but I imagine latter is more predictable in more complex situations that involve for loops, etc

lilactown 2020-05-17T16:54:25.194100Z

yeah. reagent doesn’t do anything at compile-time

lilactown 2020-05-17T16:54:48.194600Z

you could create a macro to do it, but yeah it gets a little unwieldly when it’s not just a static thing

lilactown 2020-05-17T16:55:26.195500Z

(r/h [rn/View
      (if something?
        (r/h [rn/Text "Foo"])
        (r/h [rn/Text "Bar"]))])

lilactown 2020-05-17T16:57:22.195900Z

you also have to handle compiling all the same props stuff as helix’s macros

lilactown 2020-05-17T16:57:44.196400Z

if you want, you could re-use helix.impl.props/native-props and helix.impl.props/props

alidlorenzo 2020-05-17T16:58:20.197Z

would almost be same in Helix though, no?

($ rn/View
   (if something?
     ($ rn/Text "Foo")
     ($ rn/Text "Bar")))
except as hiccup can include more components at once

lilactown 2020-05-17T16:59:01.197700Z

yeah, helix is sort of a “lowest common denominator” you always have to call the macro

lilactown 2020-05-17T16:59:41.198300Z

like users might be inclined to do

(r/h [rn/View
      (if something?
        [rn/Text "Foo"]
        [rn/Text "Bar"])])

lilactown 2020-05-17T16:59:51.198900Z

which will throw a runtime error because you’re handing a vector to react

dominicm 2020-05-17T16:59:59.199200Z

@alidcastano take a look at hicada which achieves this pretty well

dominicm 2020-05-17T17:00:19.199700Z

Actually, I have an example of using it with hx

dominicm 2020-05-17T17:00:42.199900Z

https://git.sr.ht/~severeoverfl0w/hxadapound

alidlorenzo 2020-05-17T17:03:36.202700Z

@dominicm thanks will take a look @lilactown my thinking is hiccup could provide better alternative for composing than just function calls, so exploring ways of overcoming drawbacks. from research yesterday discovered clojurescript’s inferred-type and saw that helix also uses it. maybe that could be used to guard/prevent those runtime errors

lilactown 2020-05-17T17:04:30.203300Z

you might be able to but it relies on CLJS type inference which is a black box to me

lilactown 2020-05-17T17:05:41.204500Z

my current feeling is that if I change from using $ to something, it will be using factory function

lilactown 2020-05-17T17:06:07.205100Z

so

(rn/view
  (if something?
    (rn/text "foo")
    (rn/text "bar")))

alidlorenzo 2020-05-17T17:06:41.206Z

but that’s only for primitive components

lilactown 2020-05-17T17:06:46.206200Z

you can do it for anything

alidlorenzo 2020-05-17T17:08:23.207700Z

oh with a factory function yeah. but that’s more boilerplate

lilactown 2020-05-17T17:08:50.207900Z

(defnc MyComponent [props]
  ,,,)

(def my-component (helix.core/cljs-factory MyComponent))

alidlorenzo 2020-05-17T17:09:44.209200Z

i really liked the idea of using reader literals because they made the conversion really transparent, and makes using #js less awkward for me

alidlorenzo 2020-05-17T17:09:56.209500Z

wish they had more support in shadow-cljs

lilactown 2020-05-17T17:10:12.209700Z

does thump not work in shadow-cljs?

alidlorenzo 2020-05-17T17:11:40.210400Z

i tried following the way you setup it up in thump but couldn’t get it working

alidlorenzo 2020-05-17T17:11:52.210900Z

and found an issue with @thheller saying he doesn’t recommend them

alidlorenzo 2020-05-17T17:12:05.211400Z

because of build caching and that you can just use macro call

lilactown 2020-05-17T17:12:15.211900Z

i remember there being some tricky stuff with the namespace dependency graph

lilactown 2020-05-17T17:12:33.212500Z

there should be a way to write something like thump which doesn’t get hurt too badly by that

alidlorenzo 2020-05-17T17:13:26.213500Z

cool thing about reader literals is that they’d make other conversions really transparent, like in React Native converting styles had something like this in mind

#r/h [rn/View 
        [rn/Text #js {:style #r/sh [:ai-c :flx-1]}]]

lilactown 2020-05-17T17:18:56.215400Z

yeah, I like the aesthetics of reader literals for things like react elements, I think they map well to JSX. but right now I feel good just using $ everywhere so not something I’m going to invest a lot of time into personally

lilactown 2020-05-17T17:19:28.216Z

happy to provide any advice if you want to fix up thump / create a lib that better supports your use-cases w/ helix

alidlorenzo 2020-05-17T17:21:14.216700Z

thanks, will let you know 🙂

alidlorenzo 2020-05-17T17:39:04.217500Z

this is actually similar to what I was trying to do… except I was writing it myself without helix and hicada 😅 thanks for the reference

2020-05-17T20:47:49.218400Z

What's the story for using react with shadow dom? Or web components?

2020-05-17T20:48:22.219300Z

I'm finding I'm struggling a bit with how to best manage css

Aron 2020-05-17T21:05:46.220300Z

@didibus I would either use postcss or https://emotion.sh/docs/introduction

Aron 2020-05-17T21:06:45.221100Z

shadow dom and web components shouldn't have much to do with CSS though, they are orthogonal