We are running into this issue when we call store.scope
and create a view, FooDetailState
, from FooState
. A small example would be
// MARK: - State
struct FooState {
var detail: FooDetail
}
struct FooDetail { ... }
// MARK: - Environment
struct FooEnvironment {
let client: PathMonitorClient
}
struct FooDetailEnvironment {
let client: PathMonitorClient
}
The closure we're referring to is provided in the pullback of fooDetailReducer
let fooReducer: Reducer<FooState, FooAction, FooEnvironment> = Reducer.combine(
fooDetailReducer
.pullback(
state: \.detail,
action: ...
environment: { env in
.init(client: env.client)
}
),
...
)
Then in the view we'd have something like
/// FooView
var body: some View {
...
FooDetailView(store: store.scope(state: \.detail, action: FooAction.detail)
...
}
What we're noticing is that each time an action is sent to the Store and processed in the reducer, the breakpoint set on the closure environment: { env in .init(client: env.client) }
is getting hit--leading us to believe a new instance of FooDetailEnvironment
is being created.