Improved first load speed by doing parallel requests

This commit is contained in:
stalov
2018-05-15 23:13:36 +10:00
parent 7fba5f1cec
commit b7570aafe6
+17 -20
View File
@@ -51,28 +51,25 @@ export default class Root extends Component {
componentDidMount() {
const { sort } = this.state;
api.getUser()
.then(data => store.set('user', data))
.catch(() => store.set('user', {}))
.finally(() => {
api.find({ sort, url })
.then(({ comments = [] } = {}) => store.set('comments', comments))
.catch(() => store.set('comments', []))
.finally(() => {
this.setState({
isLoaded: true,
user: store.get('user'),
});
setTimeout(this.checkUrlHash);
});
api.getConfig().then(config => {
api.getConfig().then(config => {
store.set('config', config);
this.setState({ config });
})
});
});
Promise.all([
api.getUser()
.then(data => store.set('user', data))
.catch(() => store.set('user', {})),
api.find({ sort, url })
.then(({ comments = [] } = {}) => store.set('comments', comments))
.catch(() => store.set('comments', [])),
]).finally(() => {
this.setState({
isLoaded: true,
user: store.get('user'),
});
setTimeout(this.checkUrlHash);
})
}
checkUrlHash() {