Fork me on GitHub
#re-frame
<
2019-11-26
>
rgm03:11:03

I'm thinking of splitting out a bunch of heavy work to a webworker, and am feeling a bit lost over in the webworker without re-frame event flow. Does anyone know if there's a sort of headless re-frame (maybe citrus?) to help with coordinating coeffects and effects, etc., and letting me model inbound postMessage as something like a re-frame dispatch?

rgm04:11:29

I guess I could wire up a bunch of channels but the whole interceptors-cofx-fx state management set up is just so nice.

lilactown04:11:16

you can use re-frame without subscriptions

lilactown04:11:43

like you said just events, cofx, fx with interceptors

lilactown04:11:53

I've done it before. it worked alright

rgm04:11:05

really? That's awesome.

rgm04:11:13

I just assumed the reagent dep would drag in a bunch of DOM stuff, but clearly I assumed wrong.

lilactown04:11:14

reagent at the very least works in Node.js. I haven't tried it in a web worker

lilactown04:11:23

if you're concerned about bundle size, it will be a bummer tho

lilactown04:11:36

since it will include all of reagent + react + react-dom

rgm04:11:47

hm, ok, maybe a bit less awesome. Been meaning to see if I could figure out how to do that cljsjs stub trick and yank all of react out into a few <script> tags

lilactown04:11:51

it's also not too much work to fork re-frame and remove the reagent dependency... which I've also done before...

lilactown04:11:54

I don't have any intention to open source it stand alone, but it's there as a POC for you

lilactown04:11:08

(I also tore out the tracing bits since I knew I wouldn't use it)

rgm04:11:33

that's fantastic, thank you!

lilactown04:11:30

there's only like a few places that re-frame directly depends on reagent. the subscriptions, and I think the event queue also had one part that was easily removed

rgm05:11:09

huh, cool. Be nice to have a decoupled version some day.

rgm05:11:30

though it seems like DIY'ing is also not to tricky, so that's probably fine too.

rgm05:11:11

holy dinah, got working event reg and dispatch in a serviceworker

rgm05:11:51

300K uncompressed / 85K compressed with re-frame, for my serviceworker script. I think I can live with that.

rgm05:11:11

I did not expect that that would just work.

rgm05:11:41

plus now I can symmetrically model postMessage either from main -> worker or worker -> main as an effect handler, leave my UI dispatches alone and just change the event handlers.

rgm05:11:34

this is ... amazing.

Ramon Rios16:11:24

Have you tried to get a value from a checkbox before?

lilactown16:11:35

you can pass in an event handler to tell you the value on change

lilactown16:11:12

[:input {:type "checkbox" :on-change #(js/console.log (.. % -target -value))}]

Ramon Rios17:11:25

Thank you. It worked

lilactown16:11:37

the (.. % -target -value) is pulling the value of the checkbox out of the React event

y.khmelevskii20:11:29

Hi, reframe contributors. What do you think of removing reagent as a dependency. I’m not sure that it’s a good idea to use reagent approach in 2020 when we have react hooks, suspense and time slicing in future. But reframe is awesome lib as a state manager, etc and it would be great to use it without additional not relevant dependency in bundle

shaun-mahood20:11:07

@y.khmelevskii I'd be very surprised reagent was removed from re-frame, but based on the messages above it looks like it wouldn't be that hard to do in a fork.

mikethompson21:11:02

@y.khmelevskii re-frame won't be made independent of reagent any time soon

mikethompson21:11:17

From my point of view, features like hooks are solutions to problems that re-frame doesn't have or, at least, already solves in different ways. I'm sure they are useful to pure React developers, but they don't seem to fit into re-frame well. And, as for suspense, to the extent I understand it, I certainly appreciate the goal and marvel at the glorious hack (throwing promises as exceptions, right?) but I don't like the attempt to implement statefulness (one state, suspense, another state) in the view itself. I feel like that should be handled in the logic/state of the program itself, with the view being a rendering of that state.

12
lilactown21:11:42

suspense is neat, but the thing that really effects reagent and re-frame is concurrent mode and time slicing

lilactown21:11:51

which is essentially an improvement on reagent’s async rendering

mikethompson21:11:13

I've not looked into that at all, I'm afraid

mikethompson21:11:00

I've got some quite time coming up, which means I'll have some time, do you have any links?

lilactown21:11:01

it’s the most important change. suspense is cool, but works without concurrent mode. concurrent mode enables much better UX along with it, though

mikethompson21:11:33

Links for "much better UX" would be appreciated.

dpsutton21:11:38

hooks are going to be more and more required when consuming npm libs going forward though, right?

lilactown21:11:17

Dan Abramov’s talk from React Iceland 2018 is relatively short and motivating: https://www.youtube.com/watch?v=nLF0n9SACd4

👍 4
lilactown22:11:44

the first 15 min is about concurrent mode, the last is about suspense

lilactown22:11:35

this is a good dive specifically on the scheduler and what’s going on in Dan’s demo: https://philippspiess.com/scheduling-in-react/

lilactown22:11:57

another video specifically about concurrent mode, a bit longer https://www.youtube.com/watch?v=ByBPyMBTzM0