hi, I have two selectors, both separate components, the content of last of them depends on the first one. To get its values or options there is a subscription, so if the first one changed I always cleaned the selection of the second. Now the requirements have changed I need to preserve the option selected if it is also present in options related to the first selector, for that I need to use a subscription in an event handler, because it’s not a simple sub but a small logic, how to do that? I was thinking in 3 options 1. move the logic of the subscription to a function that I can call from the sub and from the event 2. inject the subscription as in https://github.com/day8/re-frame/blob/master/docs/FAQs/UseASubscriptionInAnEventHandler.md 3. or when loading the second selector detect that the option it should select is not present in the options and dispatch an event to clean it? Thanks!
For quite some time I was doing option 1. However, I kept facing this issue again and again and this week I had enough :) It's kinda waste of time to first build your subscription chain and then at some point understand that you need this value in an event handler which means that you need to refactor all the subscriptions and extract the computation functions. And of course, things get more complicated with longer subscription chains. So I finally decided to install re-frame-utils and start using the inject-sub. I've been very happy with it. I'd maybe recommend to skip the option 1 and move straight to 2, you'll eventully want to do that anyway :)
thanks @rap1ds, I’ve done the 1st one already, this is a small page/component so maybe this is not going top happen any time soon, but next time I know where to look
I would start with the first option.1👆
@wvelezva I used approach one for a middle sized project some time ago and it does work well.. especially if your state ‘schema’ is subject to change, so you will only need to update one ‘getter’ and job done 🙂
yes, I think the same way