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:
- Whether it should go in State or Environment (I think Environment)
- 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