Thank you for the responses, I'll check out your suggestions. To clear things up, I have a setup like this:
(def *state
(atom
(fx/create-context
{:some-other-stuff "some-values"
:progress 0}
cache/lru-cache-factory)))
(defmethod event-handler ::do-some-stuff [{:keys [fx/context]}]
(let [src (fx/sub-ctx context subs/source-folder)
dest (fx/sub-ctx context subs/dest-folder)])
(do
;;
;;I would like this function to update :progress every time it copies a single file
(some-namespace/copy-all-files-recursively source dest)
;;
;;
;;when it all finishes
{:context (fx/swap-context context
assoc
:progress
1.0)}))
Do I need to send the context to this copy function?
That’s easier to do with a custom effect. effects receive a function that can be called to dispatch new events
so something like this http-effect
in example18?
yeah
so your event handler definition will look like this:
(-> ...
(fx/wrap-effects
{:context ...
:copy-all-files (fn [{:keys [source dest]} dispatch!]
...)}))
and your ::do-some-stuff
event will look like this:
(defmethod ...
{:copy-all-files {:source src :dest dest}})
Thank you very much! I'll do that right now
Made it work. I've added another atom in the project and put the dispatcher there so I don't have to propagate them as arguments through 10 functions.
(reset! *gui-dispatcher {:dispatch dispatch! :update-progress-event update-progress-event})
Thank you one more time for your help!