Fork me on GitHub
#re-frame
<
2017-08-15
>
hkjels11:08:19

Is it bad practise to do multiple dispatches from within a route-definition? I mean, would you expect that work to be located in a handler instead?

danielneal15:08:04

I tend to do multiple dispatches only in handlers, using dispatch-n

mikethompson07:08:30

I like to think about events capturing "intent". Typically, user intent. I don't think about them as a kind of function call. So when the route changes I would tend to think there would be a single event. What "thing" is the user trying to make happen by their action (of causing a route change)

mikethompson07:08:30

So, I'm in agreement with @danieleneal By the same reasoning, the on-click handler for a button shouldn't do multiple dispatches either. Instead, emit the event which captures "the user's intent" behind that button press.

hkjels07:08:27

@U051MTYAB makes perfect sense. Thank you!

captainlexington15:08:37

I'm getting a runtime error when trying to call inject-cofx. Something about "cannot call arity2 of null" . I could provide more detail if necessary, but I am hoping this is some kind of common class of error

danielneal15:08:38

make sure you require the ns that your cofx is in

danielneal15:08:01

I think you're getting the error because the cofx handler is null

danielneal15:08:55

i.e. (get-handler kind id) there is prob returning null, meaning update is being called with a null function

danielneal15:08:07

I've hit that same error - would be good to put a reframe warning in there about "missing cofx" there

captainlexington15:08:44

Hmmm! Thanks, @danieleneal I'm trying to integrate https://github.com/akiroz/re-frame-storage as per the first example in the readme

captainlexington15:08:53

Lemme check my implementation

captainlexington15:08:44

Oh, hmmmm, I wonder if

captainlexington15:08:51

Damn, I can't check it until I get home

captainlexington15:08:57

but I think I know what I was getting wrong

captainlexington16:08:30

Hmmm, nope, that didn't fix it. I seem to be following the README exactly - can you tell from inspection whether it's erroneous, @danieleneal ?

akiroz16:08:26

@captainlexington mind sharing your code?

captainlexington16:08:27

Whoa it's @akiroz in the flesh!! 😄 Haha sure, would a gist do?

captainlexington16:08:01

Now I am certain I am going to have made a silly mistake :nervous-laughter:

akiroz16:08:01

a slack snippet will do if it's easier

captainlexington16:08:11

clojure
(ns pay-it-forward.popup.handlers
  (:require [re-frame.core :as re-frame]
            [akiroz.re-frame.storage :refer [reg-co-fx!]]
            [pay-it-forward.popup.db :as db]))

(reg-co-fx! :pay-it-forward
            {:fx :store
             :co-fx :store})

(re-frame/reg-event-fx
  :initialize-db
  [(re-frame/inject-cofx :store)]
  (fn [cofx event]
    (let [local  (:store cofx)
          db (:db cofx)]
      {:db  (if (not (nil? local))
              local
              db/default-db)})))

captainlexington16:08:25

Thought that language annotations would work

captainlexington16:08:46

Anyway, that's, surprisingly, as much as is required to make it crash (since it's in the initialize-db handler)

akiroz16:08:55

Hmm, that looks fine to me, could've totally been my fault since I've only used method 1 when I wrote the tests for this lib 😆

akiroz16:08:31

let me give it a try...

akiroz16:08:30

@captainlexington Oh nvm, I spot the bug, it's :cofx not :co-fx

captainlexington16:08:58

@akiroz Ho dango! You are correct! Thanks so much 😄

captainlexington16:08:10

And not only does it compile & run, but the behavior actually works!! 😄

mikethompson22:08:28

@captainlexington @danieleneal I've just added a better error message for when a cofx handler can't be found. Will be part of the next release