Replies: 4 comments
-
Hi there, I'm going to convert this to a discussion since it's not an issue with the library. |
Beta Was this translation helpful? Give feedback.
-
Question 1: Question 2: A draft to get you started:
|
Beta Was this translation helpful? Give feedback.
-
Here's what your dependency could look like: enum Connectivity {
case online
case offline
}
struct PathMonitorClient {
var start: () -> Effect<Connectivity, Never>
var stop: () -> Effect<Never, Never>
}
extension PathMonitorClient {
static var live: Self {
var pathMonitor: NWPathMonitor?
return Self(
start: {
.run { subscriber in
pathMonitor = NWPathMonitor()
pathMonitor?.pathUpdateHandler = { path in
switch path.status {
case .satisfied:
subscriber.send(.online)
case .unsatisfied:
subscriber.send(.offline)
}
}
pathMonitor?.start(queue: queue)
return AnyCancellable {
pathMonitor?.cancel()
pathMonitor = nil
}
}
},
stop: {
.fireAndForget {
pathMonitor?.cancel()
pathMonitor = nil
}
}
)
}
static let mock = Self( /* ... */ )
}
private let queue: DispatchQueue {
var increment: Int = 0
defer { increment += 1 }
return DispatchQueue(label: "PathMonitorQueue-\(increment)")
} The static You'd hold the I know you didn't want any copy-paste solutions (😅 sorry), but modelling dependencies in TCA is definitely difficult – I'd advise scanning through the isowords codebase (check out any folders ending "...Client"), and also the Examples directory in this repo for more examples of how to harness dependencies in TCA. Let me know if you have any other questions! |
Beta Was this translation helpful? Give feedback.
-
Just my 2-cents, and for what it's worth I'm using TCA 0.16.0 You can model You'd need to have each submodule/substate you care about subscribe to the Publisher and also remember to cancel that subscription (otherwise you may get fatal assertion errors if you receive these events when your submodule is I've found it so much easier to pass around the Connectivity status as an |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
I'd like to implement "reachability" feature into my app. I modeled
AppState
to contain a property telling entire app if there is network connection or not. Also I'd like to switch to Airplane mode on iPhone and see immediate changes in UI.I don't need copy-paste-ready solutions but some guidelines/tips would be welcome. I have no idea how to deal with that using Composable Architecture.
I was looking for similar examples in repository but couldn't find anything.
Questions (see marker in code):
Main file
** ContentView**
Beta Was this translation helpful? Give feedback.
All reactions