goatslacker / goatslacker/alt

Async samples from Docs (Error)

Open
#682 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
312
PR merge metrics
No merged PRs in 30d

Description

I'm following the guide from here: http://alt.js.org/guide/async/

This part:

```
fetchLocations() {
return (dispatch) => {
// we dispatch an event here so we can have "loading" state.
dispatch();
LocationSource.fetch()
.then((locations) => {
// we can access other actions within our action through `this.actions`
this.updateLocations(locations);
})
.catch((errorMessage) => {
this.locationsFailed(errorMessage);
});
}
}
locationsFailed(errorMessage) {
return errorMessage;
}

```

The dispatch() above LocationSource.fetch() returns the error.

Here's how I do my promise:

```

class Source{

fetch(id){
return new Promise(function(resolve, reject){
$.ajax({
url: '/source/'+id,
success: (response) => resolve(response),
error: () => {
console.error('Fetching source failed. Please check API response.');
reject();
}
})
});
}

}

export default new Source()
```

Also in here:

```
class LocationActions {
updateLocationThatDoesItAsync(city) {
return (dispatch) => {
setTimeout(() => dispatch(city));
};
}
}
```

what i the dispatch doing on the setTImeOut? Isn't that will tell that the async request is complete?
Where's the setting/dispatching of "loading" or "will fetch" state here?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.