Last active
May 16, 2019 10:34
-
-
Save klemola/e474c2a6cebc26402a47b7299cac0425 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
export function main() { | |
let userRequest: Data = { type: "Loading" }; | |
fetchData() | |
.then(response => { | |
userRequest = { type: "Success", data: response }; | |
}) | |
.catch(error => { | |
userRequest = { type: "Failure", error }; | |
}); | |
} | |
function render(userRequest: Data) { | |
switch (userRequest.type) { | |
case "Loading": | |
return "Loading..."; | |
case "Success": | |
return `Hello, ${userRequest.data.username}`; | |
case "Failure": | |
return "Could not fetch data!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment