cljfx

https://github.com/cljfx/cljfx
jasmin 2021-03-03T08:33:09.014200Z

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

jasmin 2021-03-03T08:34:54.014900Z

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

vlaaad 2021-03-03T08:35:21.015400Z

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

jasmin 2021-03-03T08:36:02.016100Z

so something like this http-effect in example18?

vlaaad 2021-03-03T08:36:12.016400Z

yeah

vlaaad 2021-03-03T08:39:13.019100Z

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

jasmin 2021-03-03T08:42:20.019600Z

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

jasmin 2021-03-03T10:37:17.021600Z

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!

👍 1