This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-13
Channels
- # adventofcode (77)
- # beginners (132)
- # boot (11)
- # cider (40)
- # clara (10)
- # cljsjs (1)
- # cljsrn (4)
- # clojure (148)
- # clojure-android (1)
- # clojure-greece (5)
- # clojure-italy (5)
- # clojure-nl (7)
- # clojure-spec (57)
- # clojure-uk (9)
- # clojurescript (115)
- # core-matrix (1)
- # cursive (3)
- # data-science (1)
- # datomic (1)
- # duct (7)
- # emacs (20)
- # fulcro (29)
- # funcool (4)
- # graphql (31)
- # instaparse (15)
- # java (1)
- # jobs (6)
- # jobs-discuss (95)
- # leiningen (2)
- # off-topic (30)
- # om (4)
- # onyx (7)
- # pedestal (6)
- # quil (4)
- # re-frame (52)
- # reagent (59)
- # rum (1)
- # spacemacs (3)
- # specter (61)
- # test-check (3)
Shameless plug š check out conduit https://github.com/jacekschae/conduit most events manage call to server and based on success or failure update app state
People on here (including me) have asked for some real examples of re-frame
apps that are open source to take a look at. I just found this one https://github.com/district0x/ethlance
@jacek.schae Nice. This this conduit
impl looks interesting to read through.
@mikerod it's heavily inspired by todomvc example when it comes to comments/structure. There is also API spec that could help you understand what we get from the server https://github.com/gothinkster/realworld/tree/master/api
@jaceklach thanks. Yeah Iām familiar with this server spec. Inspiration from the commenting from the todo is a good choice too!
https://github.com/bbatsov/clojure-style-guide#documentation This is the convention to document clojure functions. Is there an idiomatic way to do the same for re-frame handlers?
https://github.com/Day8/re-com/blob/master/src/re_com/misc.cljs#L77
Why is there a note saying avoid nil
?
I thought I had an issue with setting a :value nil
before on an :input
, but I donāt remember anything specific
is there a reason that (rf/reg-sub ::state ::state)
will, when subscribed to, return [::state]
instead of the result of (::state db)
? I thought Iād take a nice shortcut over (fn [db] (::state db))
but it seems re-frame is being clever
So db
has no entry for ::state
key and it is returning the qvec
as the āreturn when missingā value to calling the keyword as a fn
the qvec
for your subscription is just [::state]
since you arenāt passing query args and the first item in the query vector is the name of the subscription itself - ::state
here
(rf/reg-sub ::state (comp ::state (partial apply first)))
works as well but I may as well use the anon fn at that point
@mattly after writing long-hand subscription and event handlers for a while, I ended up just making a few macros
you could do that too, but that has some caveats on the reactivity of the subscription
I didnāt write a macro for a get-in
sort of thing. I ended up feeling the need for them more for subscriptions that have query vec arguments passed in that also are have other subscriptions as signals
a pattern Iāve been inching towards is for each namespace storing their stuff inside ::data
and then helpers around subscribing to that
btw, Iām giving a talk on re-frame at our local clojure group on the 4th of Jan: https://www.meetup.com/clojure-pdx/events/245270782/
This sort of thing is what I meant:
(rf/reg-sub
:mine/mine
(fn [[_ x y]]
(rf/subscribe [:mine/something x y]))
(fn [something [_ x y]] (do-stuff something x y))
I guess you can use rf/reg-sub-raw
to cut down boilerplate on those too, but I still wanted to macro away the boilerplate over reg-sub-raw
in this case š
Iāve tried to resist writing my own little dsl around creating subscriptions & event handlers since thatās never worked out well for me in other areas
> btw, Iām giving a talk on re-frame at our local clojure group on the 4th of Jan
Nice. Iām not in the Portland area. But cool you are giving a talk on re-frame
. I fairly recently switched over an app that was only reagent
to re-frame
. Iām also in the progress of a brand new app that is starting with re-frame
. Iāve definitely become a fan of re-frame
now.
> Iāve tried to resist writing my own little dsl So did I, but then I gave inā¦ Perhaps bad choice. Remains to be seen. š
Hi everyone. can you guys help me refactor my app a bit please? So basically I have a little application that needs to poll a few different APIs every x (letās say 4) seconds.
So I created this tick
event
(defn- get-events-to-run [section]
(when-not (:waiting-for-data section)
(:ticker-event section)))
(re-frame/reg-event-db
::initialize-db
(fn [_ _]
db/default-db))
(re-frame/reg-event-fx
::initialize
(fn [cofx _]
{:dispatch-n [[::initialize-db] [::tick]]}))
(re-frame/reg-event-fx
::tick
(fn [cofx _]
(let [events (->> (map (:db cofx) [:accounts :balances :orders])
(map get-events-to-run)
(remove nil?)
(into []))]
{:dispatch-n (if (empty? events) [] [events])
:dispatch-later [{:ms 4000
:dispatch [::tick]}]})))
It uses dispatch-later
on itself and it basically checks, whether accounts
, balances
and orders
are waiting for data (sometimes API calls may take more than 4 seconds) and if so, it excludes them from polling. And then for each section that is not waiting for data, it runs whatever is in ticker-event
, which is the name of the event that should be run basically. For example get-account-balances
or get-orders
.
But I have a feeling that Iām not dealing with this right and thereās a better option out there šA bit late to the party but here's another re-frame open source app: https://github.com/lambdaclass/holiday_ping (re-frame code is under directory priv/ui
)