Skip to content

Commit

Permalink
Merge pull request #16 from nodes-ios/async_tokens
Browse files Browse the repository at this point in the history
Fix: Rename occurrences of Route and route to Destination and destina…
  • Loading branch information
jakobmygind authored Mar 16, 2023
2 parents bfa400b + 108e7a9 commit 9ad9c6c
Show file tree
Hide file tree
Showing 5 changed files with 539 additions and 539 deletions.
14 changes: 7 additions & 7 deletions Modules/Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public struct AppView: View {
}

public var body: some View {
IfLet($viewModel.route) { $route in
Switch($route) {
CaseLet(/AppViewModel.Route.main) { $vm in
IfLet($viewModel.destination) { $destination in
Switch($destination) {
CaseLet(/AppViewModel.Destination.main) { $vm in
NavigationView {
MainView(viewModel: vm)
.transition(
Expand All @@ -36,7 +36,7 @@ public struct AppView: View {
}
.navigationViewStyle(.stack)
}
CaseLet(/AppViewModel.Route.login) { $vm in
CaseLet(/AppViewModel.Destination.login) { $vm in
LoginView(viewModel: vm)
.transition(
.asymmetric(
Expand All @@ -62,11 +62,11 @@ struct AppView_Previews: PreviewProvider {

static var previews: some View {
AppView(viewModel: .init())
.previewDisplayName("No Route")
.previewDisplayName("No Destination")

AppView(
viewModel: .init(
route: .main(
destination: .main(
.init()
)
)
Expand All @@ -76,7 +76,7 @@ struct AppView_Previews: PreviewProvider {
.previewDisplayName("Main")

AppView(
viewModel: .init(route: .login(
viewModel: .init(destination: .login(
.init(
onSuccess: { _, _ in }
)
Expand Down
12 changes: 6 additions & 6 deletions Modules/Sources/AppFeature/AppViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import SwiftUI

public class AppViewModel: ObservableObject {

public enum Route {
public enum Destination {
case login(LoginViewModel)
case main(MainViewModel)
}
@Published var route: Route?
@Published var destination: Destination?

@Dependency(\.apiClient) var apiClient
@Dependency(\.persistenceClient) var persistenceClient
Expand All @@ -33,9 +33,9 @@ public class AppViewModel: ObservableObject {
@Published var bannerState: BannerState?

public init(
route: AppViewModel.Route? = nil
destination: AppViewModel.Destination? = nil
) {
self.route = route
self.destination = destination

Task {
for await token in apiClient.tokensUpdateStream() {
Expand All @@ -58,7 +58,7 @@ public class AppViewModel: ObservableObject {
}

func showLogin() {
route = .login(
destination = .login(
.init(
onSuccess: { [unowned self] in
persistenceClient.tokens.save($0)
Expand All @@ -72,7 +72,7 @@ public class AppViewModel: ObservableObject {
}

func showMain() {
route = .main(
destination = .main(
// Using witghdependencies(from: self) here makes sure that if you have overridden dependencies e.g. for using a mock endpoint, the children use the mocked endpoint and not the liev one
withDependencies(from: self, operation: MainViewModel.init)
)
Expand Down
Loading

0 comments on commit 9ad9c6c

Please sign in to comment.