Fork me on GitHub
#re-frame
<
2017-08-20
>
lumpy15:08:02

what is there the idomatic way to call an fx that doesn’t take any params?

lumpy15:08:13

(reg-fx
  :ga/variation
  (fn [_]
    (let [variation (js/cxApi.chooseVariation)]
      (js/console.log "var: " variation)
      (reset! re-frame.db/app-db (assoc @re-frame.db/app-db :variation variation)))))

souenzzo16:08:56

same tutorial/example about re-frame + spec?

curlyfry16:08:29

@lumpy Not quite sure if there is an established idiomatic way, perhaps :ga/variation nil, or :ga/variation []

curlyfry16:08:50

@souenzzo Could you clarify your question a bit? Are you looking for a tutorial on how to use spec with re-frame?

souenzzo16:08:42

I'm looking for "patterns"

(defn foo [])
(s/fdef foo ...)
(rf/reg-event-db :foo foo)
I'm doing that at the moment. Just wanna see if this is the way or there is some smarter way to do.

curlyfry17:08:44

I've had some trouble using s/fdef with re-frame too. The docs and todomvc example suggest using an interceptor to validate app-db after every event: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/db.cljs https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/events.cljs

curlyfry17:08:24

I think you can also try registering the original var e.g (rf/reg-event-db :foo 'foo) to be able to register events, fdefs, and defns in any order you want. Not sure how idiomatic/efficient/safe that is though!

souenzzo17:08:05

So for now, there is not an idiomatic way to spec functions. Ok. I will keep my pattern 😄

pesterhazy18:08:34

Lumpy, the docs say nil

lumpy18:08:58

@pesterhazy great find thanks