on master help sign in
search: trial with promise.all
168e888Matilde Park
components/Search.js+9−3
@@ -87,7 +87,7 @@ class Search extends Component {
87 ]
87 ]
88 : [];
88 : [];
89
89
90− const glossaryResults = await fetch(this.glossarySearch(query))
90+ const glossarySearch = fetch(this.glossarySearch(query))
91 .then((res) => res.json())
91 .then((res) => res.json())
92 .then((res) => {
92 .then((res) => {
93 return res.results.map((item) => ({
93 return res.results.map((item) => ({
@@ -96,7 +96,7 @@ class Search extends Component {
96 }));
96 }));
97 });
97 });
98
98
99− const devResults = await fetch(this.devSearch(query))
99+ const devSearch = fetch(this.devSearch(query))
100 .then((res) => res.json())
100 .then((res) => res.json())
101 .then((res) => {
101 .then((res) => {
102 return res.results.map((item) => ({
102 return res.results.map((item) => ({
@@ -105,7 +105,7 @@ class Search extends Component {
105 }));
105 }));
106 });
106 });
107
107
108− const opsResults = await fetch(this.opsSearch(query))
108+ const opsSearch = fetch(this.opsSearch(query))
109 .then((res) => res.json())
109 .then((res) => res.json())
110 .then((res) => {
110 .then((res) => {
111 return res.results.map((item) => ({
111 return res.results.map((item) => ({
@@ -114,6 +114,12 @@ class Search extends Component {
114 }));
114 }));
115 });
115 });
116
116
117+ const [glossaryResults, devResults, opsResults] = await Promise.all([
118+ glossarySearch,
119+ devSearch,
120+ opsSearch,
121+ ]);
122+
117 const list = [
123 const list = [
118 ...glossaryResults,
124 ...glossaryResults,
119 ...patpResult,
125 ...patpResult,