Fork me on GitHub
#re-frame
<
2019-10-08
>
manutter5113:10:51

I’m having a problem with subscriptions, and I’m not sure how to proceed to try and resolve it. I’m feeding input signals through a series of subscriptions, and at a certain point they just stop flowing.

(rf/reg-sub
 :user-form/modal-group-filter
 :<- [:forms/user-form]
 (fn [user-form]
   (prn {:filter (get-in user-form [:modal-group-filter :input/value])})
   (:modal-group-filter user-form)))

(rf/reg-sub
 :user-form/modal-group-filter-value
 :<- [:user-form/modal-group-filter]
 (fn [filter-data]
   (println "Intermediate sub returning" (pr-str (:input/value filter-data)))
   (:input/value filter-data)))
This is in the overall context of typing a search string into an input field to filter a large list of groups down to a manageable size. As I type, my debug string is printing out the {:filter "foo"} output, one for each character I type. The debug printout in the dependent subscription, however is never printed. It prints once when the component first renders, but does not update as I type.

jahson18:10:14

For me it looks like reagent somehow counts (:modal-group-filter user-form) as unchanged.

manutter5118:10:35

Yeah, that’s what it looks like. I use the same pattern almost everywhere, and they all work fine. It’s just this one link in the signal tree that fails.

manutter5118:10:29

I wonder if it has anything to do with the fact that the input field subscribes to the sub that does work.

manutter5118:10:57

IOW multiple subscriptions to the same sub. :thinking_face:

jahson19:10:06

AFAIK multiple subscriptions to the same sub shouldn't cause anything like that.

jahson19:10:02

Looking at the reg-sub code you could try to use traces that are baked into re-frame https://github.com/Day8/re-frame/blob/72f06966b0e6bb40c35607629a5301ef3a9e6640/src/re_frame/subs.cljc#L368

jahson19:10:11

Or, as usual, put a println everywhere and remove possible causes one-by-one.

Lu21:10:36

@manutter51 Are you dereferencing the two subscriptions from the same exact place?