day8 / re-frame

A ClojureScript framework for building user interfaces, leveraging React
http://day8.github.io/re-frame/
MIT License
5.42k stars 715 forks source link

docs on subscriptions not ideal #711

Closed henryw374 closed 1 year ago

henryw374 commented 3 years ago

Take a situation where you have a subscription A, who's parameters will be obtained from subscription B.

One way of achieving that I know of would be using dynv - for which the docs say " This argument exists for historical reasons and is borderline deprecated these days."

(re-frame.core/subscribe [::A args] [(re-frame.core/subscribe [::B])])

What the docs don't say is what this has been deprecated in favour of - that is the first issue that I would like to see addressed.

For a situation like this, I would reach for reg-sub-raw - for which the docstring says: "This is a low level, advanced function. You should probably be using reg-sub instead."

I found that last bit quite off-putting, so I didn't look into it as early as I should have done and went down the dynv route - which gets tricky when you also have C, D.. and more dependent-parameterized subs. For the situation described, reg-sub-raw is the right solution afaik.

(rf/reg-sub-raw ::A 
  (fn [_db [_ args]]
    (ratom/reaction 
      (when-let [a @(rf/subscribe [::B args])]
        ;do stuff
        ))))

The docstring does also link to http://day8.github.io/re-frame/flow-mechanics/ which was helpful - and set me on the right path eventually :). I would suggest the docs said something along the lines of : reg-sub-raw should only be used when dealing with more advanced use cases such as ... xyz.. maybe mention the above scenario or something more general?

Thanks

kimo-k commented 1 year ago

Hey, thanks for the feedback. It's been a while.

I added mention of reg-sub-raw and the signal function into dynv's explanation. Feel free to reopen this ticket if you feel more could be done.

henryw374 commented 1 year ago

looks good. thanks