Fork me on GitHub
#re-frame
<
2016-09-01
>
vikeri12:09:49

A question about dynamic subscriptions: If I have a subscription that takes another subscription as input but also allows for a dynamic subscription I get some strange behavior. The subscription is triggered twice, first the directly subscribed value has changed but the dynamic value (of the same subscription) is the same, but then it is triggered again and then both the directly subscribed value and the dynamically subscribed value are the same. To illustrate I have put together a simple repo: https://github.com/vikeri/re-frame-dyn-sub-example/blob/master/src/cljs/re_frame_testing/subs.cljs

vikeri12:09:24

When db is incremented it will print: Times-ten Dynamic: 0 Input: 1 Times-ten Dynamic: 1 Input: 1 (Ideally I would like to have the subscription triggered only once, and thus avoiding the first trigger (naturally it is problematic to have the same subscription deref to different values))

lwhorton17:09:49

does anyone know how to get refs to work in reagent (is it possible?)?

shaun-mahood17:09:47

Oh that's quite different 🙂 No idea with that one.

martinklepsch17:09:53

@lwhorton had the same question recently

martinklepsch17:09:44

@lwhorton the :ref key can be a function. The function gets the element as argument. You can stash that in an atom or whatever and then do stuff with it.