Fork me on GitHub
#cljfx
<
2021-03-02
>
jasmin12:03:27

Hi, can I use an atom from another namespace, so when it changes there, my renderer updates? Can I make it trigger an event every time it changes or do I need to make my whole app be based on a subscription model?

jasmin12:03:36

In my example I hit a button which runs a function that maps a subfunction. I would like to update a progress bar every time this subfunction finishes.

jasmin12:03:24

What is the most elegant way to approach this?

joelkuiper19:03:46

I believe the general idea comes from the re-frame model where the whole app state is derived from a single "source of truth" (https://day8.github.io/re-frame/a-loop/), so the easiest way to accomplish that in that model is to have a (nested) map in the central state atom that coordinates those events/subscriptions. This model tends to work well for javafx as the visual rendering happens in a single thread anyways (just like javascript).

joelkuiper19:03:58

but it might be worth looking into https://github.com/vlaaad/reveal/blob/0ae45590a3792d05160ba0359e9c98691a43ec6d/src/vlaaad/reveal/fx.clj which mimics local mutable state with a *state atom in the global state

vlaaad20:03:02

@jasmin I'm not quite understanding your setup... I think it's better to have a single atom for the whole UI state. If your "logic" has multiple mutable references (e.g. multiple loaders that report progress), it's probably a good idea to add watchers to these refs that update value in UI state ref