Async samples from Docs (Error)
- 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
Assessment
This issue has not been assessed yet.