Skip to content

Commit 97304ef

Browse files
authored
Prepare dependencies a single time when creating Store. (#2695)
1 parent 8e3ff3d commit 97304ef

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/ComposableArchitecture/Store.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ public final class Store<State, Action> {
153153
withDependencies prepareDependencies: ((inout DependencyValues) -> Void)? = nil
154154
) where R.State == State, R.Action == Action {
155155
if let prepareDependencies = prepareDependencies {
156-
let (initialState, reducer) = withDependencies(prepareDependencies) {
157-
(initialState(), reducer())
156+
let (initialState, reducer, dependencies) = withDependencies(prepareDependencies) {
157+
@Dependency(\.self) var dependencies
158+
return (initialState(), reducer(), dependencies)
158159
}
159160
self.init(
160161
initialState: initialState,
161-
reducer: reducer.transformDependency(\.self, transform: prepareDependencies)
162+
reducer: reducer.dependency(\.self, dependencies)
162163
)
163164
} else {
164165
self.init(

0 commit comments

Comments
 (0)