Fork me on GitHub
#re-frame
<
2019-11-05
>
mkvlr08:11:01

@steedman87 we do dispatch in subscription handlers and it works fine for fetching data, here’s a sample:

mkvlr08:11:02

(re-frame/reg-sub
 :component/output!
 (fn [db [_ {{id :id} :node name :output/name :as output}]]
   (let [output' (-> db :outputs (get id) (get name))]
     (if (:value output')
       output'
       (do
         (when-not (or (:loading? output') (= (:kind output) "file"))
           (re-frame/dispatch [:fetch-output output]))
         output)))))

mkvlr08:11:52

the :fetch-output event handler then sets loading? on the output so it’s only dispatched once…