Inject AvatarViewMode as EnvironmentObject

This commit is contained in:
Alfonso Grillo
2023-01-13 12:57:21 +01:00
parent 908c911eaf
commit 9df4a5a10b
52 changed files with 70 additions and 74 deletions
@@ -20,10 +20,14 @@ import Foundation
/// Simple ViewModel that supports loading an avatar image
class AvatarViewModel: InjectableObject, ObservableObject {
@Inject var avatarService: AvatarServiceProtocol
private let avatarService: AvatarServiceProtocol
@Published private(set) var viewState = AvatarViewState.empty
init(avatarService: AvatarServiceProtocol) {
self.avatarService = avatarService
}
private var cancellables = Set<AnyCancellable>()
/// Load an avatar
@@ -58,3 +62,9 @@ class AvatarViewModel: InjectableObject, ObservableObject {
.store(in: &cancellables)
}
}
extension AvatarViewModel {
static func withMockedServices() -> AvatarViewModel {
.init(avatarService: MockAvatarService.example)
}
}