Niedzielski has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387329 )

Change subject: Chore: refactor page and summary data client request methods
......................................................................

Chore: refactor page and summary data client request methods

Try to make the page and page summary data client request method
implementations easier to read by using the function keyword and
restructuring the response with a closure instead of array
destructuring.

Change-Id: I06479a329d5dccebbb3775cce15904a869e6b4c4
---
M src/common/data-clients/page-data-client.ts
M src/common/data-clients/page-summary-data-client.ts
2 files changed, 23 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/29/387329/1

diff --git a/src/common/data-clients/page-data-client.ts 
b/src/common/data-clients/page-data-client.ts
index b762c35..4ed4581 100644
--- a/src/common/data-clients/page-data-client.ts
+++ b/src/common/data-clients/page-data-client.ts
@@ -51,21 +51,22 @@
   unmarshal: (params: UnmarshalParams) => Type
 ): Promise<HttpResponse<Type>> {
   const headers = params.random ? RANDOM_HEADERS : PAGE_HEADERS;
-  return fetch(url(params, endpoint), { headers })
-    .then(response =>
-      response
-        .json()
-        .then(json => [response.status, response.url, response.headers, json])
-    )
-    .then(([status, url, headers, json]) => {
+  return fetch(url(params, endpoint), { headers }).then(response => {
+    return response.json().then(json => {
       const requestTitleID = params.random
         ? undefined
         : decodeURIComponent(params.titlePath);
       return {
-        status,
-        data: unmarshal({ url, requestTitleID, headers, json })
+        status: response.status,
+        data: unmarshal({
+          url: response.url,
+          requestTitleID,
+          headers: response.headers,
+          json
+        })
       };
     });
+  });
 }
 
 export const requestPage = (params: Params): Promise<HttpResponse<Page>> =>
diff --git a/src/common/data-clients/page-summary-data-client.ts 
b/src/common/data-clients/page-summary-data-client.ts
index ad48181..90aeb84 100644
--- a/src/common/data-clients/page-summary-data-client.ts
+++ b/src/common/data-clients/page-summary-data-client.ts
@@ -38,23 +38,22 @@
 
 // todo: this can actually return an empty response when redirect is false. Do
 //       we want to support it? Same question for the other redirect usages.
-export const request = (params: Params): Promise<HttpResponse<PageSummary>> =>
-  fetch(url(params), { headers: params.random ? RANDOM_HEADERS : PAGE_HEADERS 
})
-    .then(response =>
-      response
-        .json()
-        .then(json => [response.status, response.url, response.headers, json])
-    )
-    .then(([status, url, headers, json]) => {
+export function request(params: Params): Promise<HttpResponse<PageSummary>> {
+  const headers = params.random ? RANDOM_HEADERS : PAGE_HEADERS;
+  return fetch(url(params), { headers }).then(response => {
+    return response.json().then(json => {
+      const requestTitleID = params.random
+        ? undefined
+        : decodeURIComponent(params.titlePath);
       return {
-        status,
+        status: response.status,
         data: unmarshalPageSummary({
-          url,
-          requestTitleID: params.random
-            ? undefined
-            : decodeURIComponent(params.titlePath),
-          headers,
+          url: response.url,
+          requestTitleID,
+          headers: response.headers,
           json
         })
       };
     });
+  });
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/387329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I06479a329d5dccebbb3775cce15904a869e6b4c4
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to