From b7570aafe6520bff3b0ac7bd066395204c4011ae Mon Sep 17 00:00:00 2001 From: stalov Date: Tue, 15 May 2018 23:13:36 +1000 Subject: [PATCH] Improved first load speed by doing parallel requests --- web/app/components/root/root.jsx | 37 +++++++++++++++----------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index d2c11f0d..c31d208a 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -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() {