Fork me on GitHub
#re-frame
<
2018-10-10
>
aarkerio00:10:14

Hi! I'm trying to run an "after" interceptor:

aarkerio00:10:29

(def ^:private reorder-after-interceptor (re-frame/after (partial order-questions)))

aarkerio00:10:31

what should I put inside "order-questions" to update: (:questions db) ??

aarkerio00:10:32

(update-in questions new-ordered-questions) ??

aarkerio00:10:35

after the initial ajax load, I need to re-order the ordered-map (:questions db)

danielstockton09:10:57

Can I register a default subscription? Getting tired of retrieving simple keys from the root of the app-db.

lwhorton16:10:08

i suppose you could write a macro that outputs code for this purpose

lwhorton16:10:01

i use a macro to do some fancy footwork with exposing a rest-style entity interface with a set of default reg-event-db and reg-subs for get/post/put/delete etc.

danielstockton09:10:48

I guess it makes it hard to detect when a particular part of state is updated, and tie it to a component.

samueldev10:10:14

@danielstockton not sure what you mean by default, but I’ve got a dead simple subscription for stuff like that, that is ostensibly “what key in a specific path in the db do I want to fetch”

samueldev10:10:34

The key being a parameter to the sub

danielstockton10:10:23

@samueldev That's what I'm looking for, but I only see how to register subscriptions using a particular key.

danielstockton10:10:52

If you have one subscription doing that, then that's what I'm looking for really

frenata11:10:55

@danielstockton You can give subscriptions arguments, so it wouldn't be too technically difficult to implement such a thing... but you'd lose all the benefits of subscription cacheing, which is why iirc the docs discourage this approach. Still could be reasonable to do it while prototyping.

(re-frame/reg-sub
 ::default
 (fn [db [_ k]
   (k db)))

danielstockton11:10:51

Thanks @andrew354, thought it might come with some downsides.

frenata11:10:56

The other way that I've thought about would be a macro that generates simple subs.

frenata11:10:06

(make-subs [:a :b :c]) which could expand to:

(rf/reg-sub
  ::a
  (fn [db]
    (:a db)))

...

frenata11:10:45

haven't gotten around to doing so, but that could cut down on a lot of boilerplate

danielstockton11:10:23

Yeah, still have to explicitly name all the keys though. Nevermind, it's a bit tedious, but at least it's simple.

frenata11:10:46

Hmm, I wonder if you could generate simple subscriptions of this sort from a spec.

heyarne12:10:09

so when I'm having an event handler that looks like (fn handler [fx _] (-> (assoc-in fx [:db :foo] :bar) (assoc :dispatch [:not-important]))) I'm getting "no handler registered for effect event"

heyarne12:10:29

i thought writing the handlers like them would make them more flexible, but it seems that it's not intended

heyarne12:10:09

because fx has information about the current event and just passing it on causes the above error

heyarne12:10:13

so is this an anti-pattern?

heyarne12:10:33

it seems kind of clunky to explicitly (dissoc fx :event) first

frenata13:10:14

Interesting pattern to pass on the fx with some changes @arne-clojurians. I've generally been destructuring in the arg vector for just the db and returning a map literal. (fn handler [{db :db} _] {:db (-> db (assoc ... But your approach might be useful in certain situtations: is there more than just the db you'd like to pass through?

heyarne13:10:43

i have to say i did not actually end up using it yet. it was something i thought of when i started familiarizing myself with re-frame