Fork me on GitHub
#re-frame
<
2015-08-29
>
Tom H.01:08:28

Is there a problem with the way I've been handling dynamic subscriptions?

(defn activity-editor
  []
  (let [id       (subscribe [:open :activity])
        activity (reaction @(subscribe [:activity @id]))]
  ...

mikethompson02:08:34

I think you'd be better off doing this:

(defn activity-editor
  []
  (let [id       (subscribe [:open :activity])
        dyn-sub (reaction (subscribe [:activity @id]))
        activity (reaction @@dyn-sub)]
  ...

mikethompson02:08:07

Otherwise, every time the subscription yields a new value, you'll trigger a re-computation which will re-create the subscription itself. Having said that, I find that this stuff messes with my head. I'd like there to be an easier way to use/think-about this stuff. Have it hidden. Robust. That's what https://github.com/Day8/re-frame/pull/108/files is about.

Tom H.02:08:35

>trigger a re-computation which will re-create the subscription itself Ah I see, that makes sense. I'll have a go at using the new PR as well, cheers simple_smile

jonas04:08:08

When working with re-frame + figwheel I get warnings like: “re-frame: overwriting subscription-handler for: …”. Is this normal and can it be safely ignored?

mikethompson06:08:51

Yes, it is normal and can be ignored. When figwheel reloads a namespace (after a recompile), the handlers in that namespace will be reregistered (overwritting their previous registration, when the file was loaded for the 1st time). re-frame sees that it already has a handler registered for the id and warns you (just in case you ever mistakenly registered two handlers with the same id) ... but in the figwheel case we're all good with the overwrites.

jonas10:08:06

@mikethompson: That was my guess too, thanks for confirming!