Skip to content

How can I make this code with AsyncData better? #46

Closed Answered by bloodyowl
muratkeremozcan asked this question in Q&A
Discussion options

You must be logged in to vote

hi!

in the way the code is written, AsyncData doesn't serve a real purpose because you don't have somewhere where the async status is tracked. a good use case for it is for example when using React and needing to display the various stages of loading/receiving (like in this example: https://swan-io.github.io/boxed/react-request).

In your example, I'd go for something like the following:

Future.fromPromise(axios({
  method: 'GET',
  baseURL: 'http://localhost:4000/notificationData',
}))
  .mapOk(json => Result.fromExecution(() => Serializer.decode(json)))
  .mapOk(dataForTemplate)
  .onResolve(result => {
    result.match({
      Ok: data => {
        // do something with data
      },
      

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bloodyowl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants