Question about async and store
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
Hello everyone.
I just started using react/alt so probably I'm doing something wrong.
I can figure out what's wrong.
I have a store that uses a data source to gather information from a remote server
``` js
let alt = require('../alt'),
AppSource = require('../sources/AppSource');
class {
constructor() {
this.state = {value: ''};
this.registerAsync(AppSource);
this.bindListeners({
handleActivateBackend: AppActions.ACTIVATE_BACKEND
});
}
handleActivateBackend(url) {
this.currentBackendUrl = url;
AppStore.fetchApps();
}
}
module.exports = alt.createStore(AppStore, 'AppStore');
```
and the datasource
``` js
let axios = require('axios');
let AppActions = require('../actions/AppActions');
const AppSource = {
fetchApps: {
remote(state) {
let url = state.backendURL + '/apps';
return axios.get(url);
},
success: AppActions.updateApps,
error: AppActions.errorUpdateApps,
shouldFetch(state) {
return true;
}
}
};
module.exports = AppSource;
```
The problem is that i receive this error
`TypeError: AppStore.fetchApps is not a function`
(I've also tried to use "this" but it doesn't work anyway)
Can you help me? Thanks!
Contributor guide
Research direction
Start by tracing the store setup in the shown AppStore code and the fetchApps data-source entry in ../sources/AppSource, then check how AppActions is wired. Reproduce the TypeError and verify whether the store exposes the async method; done means the remote /apps request can be triggered without the error and its success or error action runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100