Fork me on GitHub
#fulcro
<
2022-09-27
>
Quentin Le Guennec21:09:37

Hello, what would be the best way to init a websocket connection after a component load? I’m guessing I should trigger a mutation with use-effect that would initialize the websocket, is that correct? Futhermore, I would like to automatically reconnect the websocket 3 seconds after it’s closed, but I can’t really call the init mutation recursively, right?

tony.kay03:09:00

I don’t understand why you would want to do this. Why not just use polling if you need immediate feedback for the lifetime of an on-screen component? If you really want to create a websocket for a partucular screen and tear it down afterwards, then yes, you can set a remote up in lifecycle. I don’t like to tie rendering with other lifecycles, so I’d probably use a UISM or other control system outside of rendering. I don’t understand your “3 seconds after closed” question. Websockets stay connected, and sente will auto-retry if it fails.

Quentin Le Guennec05:09:04

@U0CKQ19AQ Oh yeah but I’m not using Sente. I guess I could though.

Quentin Le Guennec06:09:08

Yeah but sente does things I don’t need and things that are incorrect to my use case

Quentin Le Guennec06:09:02

“Why not just use polling if you need immediate feedback for the lifetime of an on-screen component” => I don’t know how to do that.

tony.kay15:09:18

polling is just df/load in a setTimeout loop, where you don’t re-up the timeout if the component is no longer mounted.

tony.kay15:09:49

or setInterval…if using hooks setInterval might be cleaner

tony.kay15:09:04

use a use-state to create a local state to track the interval timer’s ID, then use-effect to start it, remember the id, and return a function that stops it

Mateusz Mazurczak22:09:23

;; Anecdote ;; I was trying to integrate fulcro SSR and multi-root for my project landing page (seo reasons), thinking how can I make my other components not cljc files. Then I realized that I can just load separate simple html page on root url and fulcro app on other url endopionts (or use different subdomain for app). Although this is not strictly related to fulcro itself, it reminds me of the fact that that most of my problems while using fulcro is from overthinking or expecting more then just simplicity and easy solutions that fulcro offers. Maybe I need to change my mindset. :face_in_clouds:

👍 1
sheluchin11:09:23

I find the same thing. Much of the time when I get stuck on something, the solution ends up being much simpler than I first thought. I just don't know how to deliberately practice this mindset of keeping things simple. I'm aware of it, but I don't know how to improve it other than just writing more code and gaining experience. It's kinda like thinking "I should just play more songs" when learning how to play an instrument, rather than practicing specific chords.

Mateusz Mazurczak11:09:14

There are three things I found, how to accelerate your growth (it can be used for learning fulcro, but anything generally). 1. Practice, a lot of practice 2. Finding a mentor 3. Finding people you can share your experience with, so you grow faster together. For this case it would be some study/learning group of people, that you share things you learned and teach each other.

sheluchin12:09:48

Good points. I do wonder if there has ever been something like a Fulcro study group. I know that there are a few in the Clojure ecosystem overall, but not sure if there has ever been one specifically focused on Fulcro. I suppose this Slack channel is something of the sort, but something a little more structured could be interesting.

Mateusz Mazurczak12:09:37

Well you could always be the person creating such a group, or finding such a individuals 😄

sheluchin11:09:36

I would be open to committing a bit of time to something like that. I'll keep an eye out to see if any others in the channel express interest. Could be good for everyone involved.