Observing state outside of TCA using Observable/Publisher

I'm starting to integrate TCA into a project that currently uses RxSwift and UIKit. The project currently "observes" some IoT devices whose state can be changed from outside of my application. I use an MQTT client that observes broadcasted state changes for the device. For this purpose RxSwift Observables (Publishers) make a lot of sense.

Now I want to add TCA to a small feature that needs to observe some of these devices. I'd like to pass an Observable<[Device]> to my feature but I'm not sure:

  1. Whether it should go in State or Environment (I think Environment)
  2. How/When/Where to subscribe to next events emitted by the observable and map them into actions fed into the reducer.

I think I could make the Observable into an Effect but I'm not sure how to subscribe to it. My hunch would be to create some kind of action tied to the view lifecycle like viewDidLoad or viewWillAppear, handle that action in the Reducer and return Effect there.

Does that sound right? What if the effect can produce values at any time?

Thanks in advance

1 Like

I found another post that seems to have a similar situation here:

Looks like I had the right idea. Put the publisher in the environment and then subscribe to it during some lifecycle event and have it send actions to the store.