Fork me on GitHub
#cljfx
<
2021-01-15
>
joelkuiper14:01:08

Hey everyone! I'm using this awesome library to build my very first solo founded app πŸ˜›

joelkuiper14:01:15

so far it's amazing!

joelkuiper14:01:59

there's one tricky bit that I'm kinda stuck at. I have a grid of thumbnails that I want to display, generating those thumbnails is done in a separate thread pool and then cached to a file, which means that it might not yet exist when I'm displaying the thumbnail. Right now I'm triggering an event that requests the thumbnails to be generated on application initialization, but I'd rather prefer to dispatch when the thumb enters the scene (so it doesn't end up requesting all of them on app boot). Is there a hacky way to dispatch an event when a node enters the scene (or I guess even hackier, dispatch an event from a subscription?)

vlaaad15:01:59

Are you ready to write a lifecycle? πŸ˜„

joelkuiper15:01:20

sure πŸ˜› I already have a few to integrate with some controlsfx components πŸ˜›

vlaaad15:01:19

Lifecycle receives opts on create/advance/delete, opts has :fx.opt/map-event-handler , you can use it to dispatch events when cljfx component is created

joelkuiper15:01:58

ah I missed the :fx.opt/map-event-handler that seems like it might work, I'll try! Thanks!

joelkuiper15:01:33

not entirely sure if that's the right approach yet, but if it works it works for now 😜

vlaaad15:01:47

I use something like that in reveal

joelkuiper16:01:45

worked fine! I now dispatch the request-thumbnails event on :start that does the background processing and then emits another event that sets some state which the thumbnails subscribe to. Carved out some of the impl details as you suggested πŸ™‚

πŸ‘ 3
vlaaad15:01:14

It has quite some implementation details (e.g. it has knowledge that event handler has a state atom in it)

vlaaad15:01:24

and it uses state and ids to forward global state to the wrapped description, which you probably don’t need

joelkuiper15:01:41

cool! I'll investigate that path for now then! I must say that I truly enjoy this library. Combined with datascript/datahike for persistence it makes cross platform desktop app development far less painful than I initially imagined. It's still a lot of work though, but from the comfort of Clojure it isn't so bad πŸ™‚

πŸ‘ 3
vlaaad15:01:02

my pleasure!