jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/382454 )
Change subject: Chore: improve page data client endpoint modeling
......................................................................
Chore: improve page data client endpoint modeling
Avoid usage of the class keyword and lighten the code for modeling the
all, lead, and body endpoint implementations.
Change-Id: I8995a8700e50f08a5f3b5bf2cdf8f116294d444f
---
M src/common/data-clients/page-data-client.ts
1 file changed, 12 insertions(+), 36 deletions(-)
Approvals:
Niedzielski: Looks good to me, approved
Jhernandez: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/common/data-clients/page-data-client.ts
b/src/common/data-clients/page-data-client.ts
index b38fc69..3dbfeb2 100644
--- a/src/common/data-clients/page-data-client.ts
+++ b/src/common/data-clients/page-data-client.ts
@@ -18,42 +18,18 @@
redirect?: PageRedirect;
}
-type UnmarshalParams = {
- headers: IsomorphicHeaders;
- json: JSONObject;
+const section = {
+ ALL: { path: "page/mobile-sections", unmarshal: unmarshalPage },
+ LEAD: { path: "page/mobile-sections-lead", unmarshal: unmarshalPageLead },
+ BODY: {
+ path: "page/mobile-sections-remaining",
+ unmarshal: ({ json }: { headers: IsomorphicHeaders; json: JSONObject }) =>
+ unmarshalPageBody(json)
+ }
};
-const ALL = new class All {
- get path() {
- return "page/mobile-sections";
- }
- unmarshal({ headers, json }: UnmarshalParams) {
- return unmarshalPage({ headers, json });
- }
-}();
-
-const LEAD = new class Lead {
- get path() {
- return "page/mobile-sections-lead";
- }
- unmarshal({ headers, json }: UnmarshalParams) {
- return unmarshalPageLead({ headers, json });
- }
-}();
-
-const BODY = new class Body {
- get path() {
- return "page/mobile-sections-remaining";
- }
- unmarshal({ json }: UnmarshalParams) {
- return unmarshalPageBody(json);
- }
-}();
-
-type Section = typeof ALL | typeof LEAD | typeof BODY;
-
interface SectionParam {
- section: Section;
+ section: typeof section.ALL | typeof section.LEAD | typeof section.BODY;
}
const url = ({
@@ -79,10 +55,10 @@
.then(([headers, json]) => params.section.unmarshal({ headers, json }));
export const requestPage = (params: Params): Promise<Page> =>
- request({ section: ALL, ...params }) as Promise<Page>;
+ request({ section: section.ALL, ...params }) as Promise<Page>;
export const requestPageLead = (params: Params): Promise<PageLead> =>
- request({ section: LEAD, ...params }) as Promise<PageLead>;
+ request({ section: section.LEAD, ...params }) as Promise<PageLead>;
export const requestPageBody = (params: Params): Promise<PageBody> =>
- request({ section: BODY, ...params }) as Promise<PageBody>;
+ request({ section: section.BODY, ...params }) as Promise<PageBody>;
--
To view, visit https://gerrit.wikimedia.org/r/382454
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8995a8700e50f08a5f3b5bf2cdf8f116294d444f
Gerrit-PatchSet: 4
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits