This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-15
Channels
- # architecture (2)
- # beginners (16)
- # boot (2)
- # cider (4)
- # clara (6)
- # cljs-dev (78)
- # cljsrn (3)
- # clojure (158)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-dusseldorf (19)
- # clojure-italy (8)
- # clojure-russia (3)
- # clojure-spec (77)
- # clojure-uk (61)
- # clojurescript (341)
- # cursive (9)
- # data-science (12)
- # datomic (18)
- # emacs (9)
- # fulcro (109)
- # hoplon (10)
- # juxt (2)
- # leiningen (2)
- # lumo (31)
- # off-topic (1)
- # om (4)
- # onyx (40)
- # parinfer (17)
- # re-frame (36)
- # reagent (19)
- # spacemacs (10)
- # vim (60)
- # yada (20)
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?
I tend to do multiple dispatches only in handlers, using dispatch-n
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)
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.
@U051MTYAB makes perfect sense. Thank you!
A reminder that re-frame-test
can be very useful:
https://www.youtube.com/watch?v=G1JWYxvucZ4&feature=youtu.be&t=792
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
make sure you require the ns that your cofx is in
I think you're getting the error because the cofx handler is null
i.e. (get-handler kind id)
there is prob returning null, meaning update is being called with a null function
I've hit that same error - would be good to put a reframe warning in there about "missing cofx" there
Hmmm! Thanks, @danieleneal I'm trying to integrate https://github.com/akiroz/re-frame-storage as per the first example in the readme
Lemme check my implementation
Oh, hmmmm, I wonder if
Damn, I can't check it until I get home
but I think I know what I was getting wrong
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 ?
@captainlexington mind sharing your code?
Whoa it's @akiroz in the flesh!! 😄 Haha sure, would a gist do?
Now I am certain I am going to have made a silly mistake :nervous-laughter:
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)})))
Gol dang it
Thought that language annotations would work
Anyway, that's, surprisingly, as much as is required to make it crash (since it's in the initialize-db handler)
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 😆
@captainlexington Oh nvm, I spot the bug, it's :cofx
not :co-fx
@akiroz Ho dango! You are correct! Thanks so much 😄
And not only does it compile & run, but the behavior actually works!! 😄
@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