Fork me on GitHub

should this still work? I tried the interceptor workaround, but still getting the warning from using subscribe outside reactive context (as per issue #740)


or is there a way to get subscription value for a given app db value? there are some subscriptions chains that have logic I would rather not duplicate


I made the following hack workaround to get the value of a sub:

(defn- get-subscription-value [db sub]
  (let [handler-fn (re-frame.registrar/get-handler :sub (first sub))]
    (handler-fn db sub)))

(defn subscribe-val
  "Get value of subscription for the given db."
  [db subv]
  (with-redefs [re-frame.subs/subscribe (partial get-subscription-value db)]
    @(rf/subscribe subv)))
you can pass a db value and a subscription vector to that and it returns the value (bypassing cached values)


That hack should still produce a warning if one of those subs uses a signal sub. And if it doesn't, it's not entirely correct because the cache wouldn't be purged. I think. I ended up writing my own wrappers or alternative variants for most of re-frame API that I use. Can definitely recommend - it gives great flexibility. E.g. for this particular case, I've introduced a dynamic variable that, when set, is just like subscribe but without caching.


it doesn’t with the redef


Oh, hmm. Does that work properly with advanced optimizations as well?


that remains to be seen


ah yes, it seems re-frame.subs/subscribe should have ^:dynamic meta for it to work in advanced compilation


Right. I pretty much never use with-redefs so my memory is always fuzzy when it comes to it.


I might need to make my own wrapper for subscribe and use that when I need this


Although, docstrings in both CLJ and CLJS don't mention :dynamic. How did you come to the conclusion that it's needed?


or setting static-fns to false, but I don’t want a performance hit everywhere


Thanks! Yeah, makes sense.


Ok here’s a new one for me: I load a page that should display content, check the subscription and it has content post-page load, but the DOM does not show it, however if I hot reload any code, the subscription updates.


Same applies for a form-3 component.


@U2FRKM4TW a-HA, I just changed a form 1 to form 2!


That was precisely it

👍 2