cljfx

https://github.com/cljfx/cljfx
jasmin 2021-03-02T12:29:27.003600Z

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?

jasmin 2021-03-02T12:35:36.004900Z

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.

jasmin 2021-03-02T12:36:24.005300Z

What is the most elegant way to approach this?

joelkuiper 2021-03-02T19:19:46.007500Z

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).

joelkuiper 2021-03-02T19:23:58.009600Z

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

vlaaad 2021-03-02T20:39:02.012400Z

@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