Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Frame accepts nil in :dispatch-n vector but re-frame-flow fails to handle it and throws errors. #2

Closed
CalebMacdonaldBlack opened this issue May 12, 2021 · 3 comments

Comments

@CalebMacdonaldBlack
Copy link

I can pass nil into :dispatch-n fx vector successfully with re-frame but re-frame-flow fails to deal with this

https://github.com/day8/re-frame/blob/ecb756e66fe30efca896879369a420df1e271605/src/re_frame/fx.cljc#L147

(reg-fx
  :dispatch-n
  (fn [value]
    (if-not (sequential? value)
      (console :error "re-frame: ignoring bad :dispatch-n value. Expected a collection, but got:" value)
      (doseq [event (remove nil? value)] (router/dispatch event)))))

I get errors because of a nil id param being passed into these two re-frame-flow.core functions:

(defn- kw->str [id]
  (if (qualified-keyword? id)
    (str (namespace id) "/" (name id))
    (name id)))


(defn- id->node [id]
  {:id (kw->str id)
   :style {:fontSize 14
           :fontFamily "monospace"
           :wordBreak "break-word"
           :width 200}
   :data {:label id
          :name (name id)
          :namespace (namespace id)}
   :sourcePosition "right"
   :targetPosition "left"
   :position {:x 0 :y 0}})
@ertugrulcetin
Copy link
Owner

Thanks for reaching out @CalebMacdonaldBlack. What is the exact error are you getting? Also, could you send your code snippet that causes the error? I tried passing nil to dispatch-n and did not get any errors;

(reg-event-fx
  ::call-some-stuff
  (fn [{:keys [db]} _]
    {:dispatch-n nil}))

Also, the code ignores if the dispatch-n is nil: https://github.com/ertugrulcetin/re-frame-flow/blob/master/src/re_frame_flow/core.cljc#L27

So nil shouldn't pass these functions, I need more info about this one.

@CalebMacdonaldBlack
Copy link
Author

CalebMacdonaldBlack commented May 12, 2021

Hi @ertugrulcetin. I love your project! Thank you for making it.

the dispatch-n takes a vector. Run this and you should see the error in your console:

(rf/reg-event-fx
  :foo
  (fn [_ _]
    {:dispatch-n [nil]}))

(rf/dispatch [:foo])

Here's the stack trace though:

router.cljc:204 Uncaught Error: Doesn't support name: 
    at Object.cljs$core$name [as name] (core.cljs:9500)
    at Object.re_frame_flow$core$kw__GT_str [as kw__GT_str] (core.cljc:57)
    at re_frame_flow$core$id__GT_node (core.cljc:68)
    at eval (core.cljs:4712)
    at eval (core.cljs:4712)
    at Object.eval [as sval] (core.cljs:3415)
    at Object.eval [as cljs$core$ISeqable$_seq$arity$1] (core.cljs:3472)
    at Object.cljs$core$seq [as seq] (core.cljs:1213)
    at eval (core.cljs:3770)
    at Object.eval [as sval] (core.cljs:3415)

The event key is nil and name cannot accept nil as a value. Re-frame deals with nil values here by filtering them out before dispatching them.

@ertugrulcetin
Copy link
Owner

@CalebMacdonaldBlack thank you for the detailed explanation. I fixed it and released a new version "0.1.3", please try it. If some error occurs, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants