Fork me on GitHub
#re-frame
<
2017-04-17
>
joshkh14:04:13

another question, maybe for the re-frame devs? i'm playing again with the :<- [:some-sub] macro. in my scenario i have a one sub that accepts a single parameter (a key pointing to somewhere in app-db). i have another subscription that accepts the same parameter (in fact all my subs do.. this is an embeddable component). it looks to me like the macro doesn't forward the parameters that are given to the "parent" subscription. is that correct?

joshkh14:04:36

for example, i can't use the macro here because db-path isn't passed to the three subscriptions:

(reg-sub
  ::visible-results
  (fn [[_ db-path]]
    [(subscribe [:im-grid.subs.pager/page-num db-path])
     (subscribe [:im-grid.subs.pager/page-limit db-path])
     (subscribe [::results db-path])])
  (fn [[page-num page-limit results]]
    (when (and page-num page-limit)
      (take page-limit (drop (* (dec page-num) page-limit) results)))))

curlyfry17:04:13

@joshk I believe that is correct and that you have to use the pattern in your example.

benny16:04:15

currently trying to figure out how to refresh an access token upon launch, and it seems like a coeffect is the direction I should be heading but how does that work with asynchronous calls like a rest call since the result of a coeffect should be the updated state not a promise?

musheddev16:04:53

@benny there are two different ways suggested to make requests, an effect that makes the requests and bind the promise functions to dispatch events on success and failure. And a subscription. https://github.com/Day8/re-frame/blob/master/docs/Subscribing-To-External-Data.md

benny17:04:17

perfect, that helps a ton, thanks @musheddev

joshkh19:04:13

@benny i have an app that requires a token and a few other assets as well (in order), and i also delay all routing until the assets are fetched. i use an effect provided by the re-frame folks that helps keep everything in order: https://github.com/Day8/re-frame-async-flow-fx

benny19:04:00

I was just looking into that now that I’ve gone through more documentation on effects, coeffects, interceptors, etc

benny19:04:16

do you then use a timeout to refresh?

joshkh19:04:02

i think we just swallow the routing event until the finished-loading-assets event is seen

benny19:04:28

wow, very helpful! thanks @joshkh

benny19:04:52

if nothing else, validation around some things that i’m only trying to understand conceptually right now

joshkh19:04:59

no worries. i ask a lot of dumb questions here so take my advice with a grain of salt 😉

benny19:04:47

more specifically 43

benny19:04:49

so thanks again!

joshkh19:04:23

happy to help!