Fork me on GitHub
#cljfx
<
2021-03-03
>
jasmin08:03:09

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

jasmin08:03:54

Do I need to send the context to this copy function?

vlaaad08:03:21

That’s easier to do with a custom effect. effects receive a function that can be called to dispatch new events

jasmin08:03:02

so something like this http-effect in example18?

vlaaad08:03:13

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

jasmin08:03:20

Thank you very much! I'll do that right now

jasmin10:03:17

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!

👍 3