This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-10
Channels
- # adventofcode (99)
- # architecture (10)
- # bangalore-clj (1)
- # beginners (65)
- # boot (9)
- # cider (78)
- # clojure (87)
- # clojure-austin (1)
- # clojure-brasil (13)
- # clojure-dev (14)
- # clojure-gamedev (3)
- # clojure-greece (2)
- # clojure-italy (2)
- # clojure-russia (18)
- # clojure-spec (26)
- # clojure-uk (15)
- # clojurescript (62)
- # core-logic (1)
- # cursive (1)
- # datomic (27)
- # emacs (17)
- # fulcro (2)
- # off-topic (44)
- # onyx (25)
- # perun (139)
- # re-frame (40)
- # reitit (2)
- # ring (4)
- # rum (2)
- # shadow-cljs (1)
- # slack-help (14)
- # unrepl (18)
Is this idiomatic re-frame?
(do (dispatch [:add-key %])
(dispatch [:request %]))
Once the user submits a field, I want to automatically make an ajax request to some api.@mohamedhayibor I may be wrong, but I don't remember re-frame giving any particular advice on this.
You have to do the coupling "user submits a fields -> add key and make request" somewhere. There are two obvious choices - in the view, as in your example, and in the event handlers by creating a new event :submit-field
that then uses :dispatch-n
effect to dispatch those two events.
I would say that the second option is better, since the coupling of particular events to particular effects is already being done in the event handlers. So why propagate it to the views when you can leave all coupling in one place?
There are blog posts that describe this much better than I just did, but the ones that I've read all suggest the second approach.
is there a re-frame lib that is used for different components? like i wanted to make tabs because it's needed for dashboard the only thing i could find is https://github.com/Day8/re-com Is there anything i couldn't find? Would any reagent component lib do the job? Are there any that are mobile friendly ?
@mohamedhayibor no, that isn't idiomatic. dispatch
shouldn't be used to perform "function calls"
I’m trying to understand when would I use reg-cofx
instead of reg-fx
. I’m following this:
https://github.com/Day8/re-frame/blob/master/docs/Coeffects.md
and some other examples I found on the web. they seem to be doing the same thing, or am I missing something?
@bravilogy I use it for injecting local-storage. It's a way of injecting additional db
s. You could inject another atom
and it would be a secondary db
@bravilogy reg-cofx
I think overly simplified: is for passing more arguments to your event handler registered via reg-event-fx
.
reg-fx
are “downstream” side-effects that are a result of what is returned by event handlers
I think @joelsanchez has a good example reason for why to use reg-cofx
though
see https://github.com/akiroz/re-frame-storage , which is what I use
ah so reg-cofx
basically registers something that will be received by the event handlers and reg-fx
registers something that will be output by them?
reg-fx
is basically a generic way to describe some side effect right? like
(re-frame/reg-fx
:print-out
(fn [value]
(.log js/console value)))
real example:
(rf/reg-event-fx
::close
[(rf/inject-cofx :local-storage)]
(fn [{:keys [db local-storage]}]
;; do things with either db or local-storage
{}
))
ok that makes sense now 😄 did a simple
(re-frame/reg-cofx
:storage
(fn [cofx _]
(assoc cofx :storage {:todos {}})))
(re-frame/reg-event-fx
::initialize-db
[(re-frame/inject-cofx :storage)]
(fn [{:keys [storage]} _]
{:db (or storage db/default-db)}))
what I still don't know is how to inject a coeffect in a subscription, looks like I can't (and I have to do horrible hacks to work around it)
your component depends on the ::closed?
value in local-storage
I need to get ::closed?
from local-storage
, put it in the db
then subscribe to the db
, and then keep both in sync
@joelsanchez I don’t know of an alternative to that
I think subscriptions are intended to only be “views” over the “single source of truth - the db” or something
it's strange that events can get any coeffect but subscriptions can only get the db coeffect, making the db coeffect special
well if there was a single source of truth, why would we have coeffects?
I’d need to think about this one a bit. I haven’t ran across that sort of situation yet eithert though.
it's not a very big problem, but I don't understand why it's done this way