Skip to content

Instantly share code, notes, and snippets.

@klemola
Last active May 16, 2019 10:35
Show Gist options
  • Save klemola/94504259533a3b26c8e6d4fc04727b1b to your computer and use it in GitHub Desktop.
Save klemola/94504259533a3b26c8e6d4fc04727b1b to your computer and use it in GitHub Desktop.
export function main() {
let userRequest: RemoteData<User, Error> = Loading;
let translationsRequest: RemoteData<Translations, Error> = Loading;
let appState: AppState = Initializing;
fetchUser()
.then(response => {
userRequest = Success(response);
if (isSuccess(userRequest) && isSuccess(translationsRequest)) {
appState = Ready(userRequest.data, translationsRequest.data);
}
})
.catch(error => {
userRequest = Failure(error);
appState = Failing(error);
});
fetchTranslations()
.then(response => {
translationsRequest = Success(response);
if (isSuccess(userRequest) && isSuccess(translationsRequest)) {
appState = Ready(userRequest.data, translationsRequest.data);
}
})
.catch(error => {
translationsRequest = Failure(error);
appState = Failing(error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment