Last active
August 19, 2019 11:01
-
-
Save llinardos/051c8949025656c3e12188d29872bb5e to your computer and use it in GitHub Desktop.
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
func startApp() { | |
onMainDo({ | |
self.activityIndicator.startAnimating() | |
}, onBackgroundDo: { | |
let storage = PersistentSecureStorage.shared() | |
guard let savedToken == storage.token { | |
return .goToAuth | |
} | |
let tokenIsValid = authService.isValidToken(savedToken) | |
if !tokenIsValid { | |
let newToken = authService.updateToken() | |
networking.set(token: newToken) | |
storage.token = newToken | |
} | |
let updatedProfile = profileService.getProfile() | |
user.profile = updatedProfile | |
let prefetchedThings = thingsService.getThings() | |
return .goToHome(prefetchedThings) | |
}, thenOnMainDo: { | |
self.activityIndicator.stopAnimating() | |
switch $0 { | |
case .goToAuth: presentAuth() | |
case .goToHome(let prefetchedThings): presentHome(prefetchedThings) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment