Fork me on GitHub
#re-frame
<
2020-01-21
>
isak16:01:23

is it safe to dereference a subscription inside :component-will-mount?

p-himik16:01:11

I don't think so.

p-himik16:01:34

Unless you also dereference it inside the render function as well.

isak16:01:21

ok, good

isak16:01:31

anyone tried to get around the 'dont reference a subscription inside event-handler' problem by messing with *ratom-context* ? (i know the other ways, but this may be better)

p-himik16:01:17

I wouldn't do that. *ratom-context* is an implementation detail as it doesn't appear to be in the public API.

isak16:01:34

thats ok, it might be something that makes sense to add to re-frame

p-himik16:01:17

What do you mean "thats ok"? It's an implementation detail of Reagent, not re-frame.

isak16:01:25

I just mean there are worse things than relying on implementation details of some project - it can be a problem, but not necessarily a fatal flaw

p-himik16:01:58

But why would you want to do that, given that there is a solution already that doesn't do that?

isak16:01:04

I'm not satisfied with the existing solutions, they seem awkward

isak16:01:30

and I can't see a good technical reason why they should be needed

p-himik16:01:48

For me, "[the existing perfectly working solutions] seem awkward" and "there are worse things" are not good enough justifications to rely on something that I ought not to rely on. A good technical reason is that *ratom-context* is an implementation detail. BTW your solution would probably break dispatch-sync. But I'm not sure about that.

djanus16:01:17

conceptually, you should not be referencing subscriptions inside event-handlers anyway; a handler gets passed a snapshot of state of the world and should not depend on anything else – in particular not on a subscription which is a reactive stream of changes to some of that state.

isak16:01:14

@p-himik ok, well let's agree to disagree

isak16:01:36

@dj942 it would be a problem if there is no way to ensure you have an up-to-date value

isak16:01:32

right now I was mostly thinking of the leak issue, but good point, would also need to solve that

mikethompson22:01:10

@isak There are existing methods which require no hackery. This link should help: https://github.com/day8/re-frame/blob/master/docs/Using-Stateful-JS-Components.md

mikethompson22:01:24

Very different documents for very different purposes

mikethompson22:01:46

You want to get at a subscribed value in :component-will-mount, yes?

isak22:01:16

oh right, that question. makes sense :thumbsup::skin-tone-2:

isak22:01:07

so dereferencing instead is unsafe?