-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
359 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Foundation | ||
|
||
/// `ObservableResolver` is a wrapper for the resolver that can be observed by SwiftUI views in the environment. | ||
/// | ||
/// ```swift | ||
/// @main | ||
/// struct MyApp: App { | ||
/// let container = Container(assemblies: [...]) | ||
/// | ||
/// var body: some Scene { | ||
/// WindowGroup { | ||
/// ContentView() | ||
/// .environmentObject(container.toObservable()) | ||
/// } | ||
/// } | ||
/// } | ||
/// | ||
/// // somewhere in the code | ||
/// struct ContentView: View { | ||
/// @DIObservedObject var api: API | ||
/// | ||
/// var body: some View { | ||
/// Button("Make request") { | ||
/// api.request() | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
@MainActor | ||
public final class ObservableResolver: Resolver, ObservableObject { | ||
private let original: Resolver | ||
|
||
init(_ original: Resolver) { | ||
self.original = original | ||
} | ||
|
||
public func optionalResolve<T>(type: T.Type, named: String?, with arguments: Arguments) -> T? { | ||
return original.optionalResolve(type, named: named, with: arguments) | ||
} | ||
} | ||
|
||
public extension Resolver { | ||
/// Returns an observable resolver that can be observed by SwiftUI views in the environment. | ||
func toObservable() -> ObservableResolver { | ||
return ObservableResolver(self) | ||
} | ||
} |
Oops, something went wrong.