[MediaWiki-commits] [Gerrit] marvin[master]: Chore: remove state typing from Route and RouteResponse
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/380662 ) Change subject: Chore: remove state typing from Route and RouteResponse .. Chore: remove state typing from Route and RouteResponse Replace Route and RouteResponse's State generic type parameter with any. Neither has a dependency on or interactions with the Component's state so it seems simpler to avoid typing it. Change-Id: I5f1eb3c299be4893a071c83f475f9aceddf45178 --- M src/client/index.tsx M src/common/routers/api.ts M src/common/routers/route.ts M src/common/routers/router.ts M src/server/index.tsx 5 files changed, 21 insertions(+), 25 deletions(-) Approvals: Jhernandez: Looks good to me, approved jenkins-bot: Verified diff --git a/src/client/index.tsx b/src/client/index.tsx index 554a266..821b62a 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -14,7 +14,7 @@ throw new Error('Missing element with "root" ID.'); } -const renderPageRoot = ({ Component, props }: RouteResponse) => { +const renderPageRoot = ({ Component, props }: RouteResponse) => { render( diff --git a/src/common/routers/api.ts b/src/common/routers/api.ts index 873ae7c..b562789 100644 --- a/src/common/routers/api.ts +++ b/src/common/routers/api.ts @@ -1,5 +1,4 @@ import { Props as WikiProps, Params as WikiParams } from "../pages/wiki"; -import { State as AboutState } from "../pages/about"; import { AnyRoute, Route, newRoute } from "./route"; export const home: Route = newRoute({ @@ -9,14 +8,14 @@ chunkName: "pages/home" }); -export const about: Route = newRoute({ +export const about: Route = newRoute({ path: "/about", importModule: () => import(/* webpackChunkName: "pages/about" */ "../pages/about"), chunkName: "pages/about" }); -export const wiki: Route = newRoute({ +export const wiki: Route = newRoute({ path: "/wiki/:title", importModule: () => import(/* webpackChunkName: "pages/wiki" */ "../pages/wiki"), diff --git a/src/common/routers/route.ts b/src/common/routers/route.ts index 639adcf..57fba9f 100644 --- a/src/common/routers/route.ts +++ b/src/common/routers/route.ts @@ -11,9 +11,9 @@ * pages/ subdirectory should implicitly implement this interface or typing will * fail in routers/api. */ -export interface PageModule { +export interface PageModule { /** A Preact view component. */ - Component: AnyComponent ; + Component: AnyComponent ; /** * A function that returns a Promise for the dependencies needed to construct @@ -22,29 +22,29 @@ initialProps?: (params: RouteParams) => Promise; } -export interface RouteConfiguration { +export interface RouteConfiguration { path: string; - importModule: () => Promise >; + importModule: () => Promise ; chunkName: string; status?: number; } -export interface Route - extends RouteConfiguration { +export interface Route + extends RouteConfiguration { status: number; /** Generates a URL from parameters. */ url: (params?: Params) => string; } -export type AnyRoute = Route ; +export type AnyRoute = Route ; -export const newRoute = ({ +export const newRoute = ({ path, importModule, chunkName, status = 200 -}: RouteConfiguration ): Route => ({ +}: RouteConfiguration): Route => ({ path, importModule, chunkName, diff --git a/src/common/routers/router.ts b/src/common/routers/router.ts index 2de064b..8a563d8 100644 --- a/src/common/routers/router.ts +++ b/src/common/routers/router.ts @@ -2,10 +2,10 @@ import { AnyComponent } from "../components/preact-utils"; import { AnyRoute, PageModule, RouteParams } from "../../common/routers/route"; -export interface RouteResponse { +export interface RouteResponse { chunkName: string; status: number; - Component: AnyComponent ; + Component: AnyComponent ; props: { path: string; url: string; @@ -15,7 +15,7 @@ } export interface Router { - route(url: string): Promise >; + route(url: string): Promise ; } interface ParsedRoute extends AnyRoute { @@ -46,21 +46,18 @@ ); function requestInitialProps( - module: PageModule , + module: PageModule, params: RouteParams -): Promise { - if (module.initialProps) { -return module.initialProps(params); - } - return Promise.resolve({}); +): Promise { + return module.initialProps ? module.initialProps(params) : Promise.resolve(); } const respond = ( route: ParsedRoute, url: string, params: RouteParams -): Promise > => - route.importModule().then((module:
[MediaWiki-commits] [Gerrit] marvin[master]: Chore: remove state typing from Route and RouteResponse
Niedzielski has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380662 ) Change subject: Chore: remove state typing from Route and RouteResponse .. Chore: remove state typing from Route and RouteResponse Replace Route and RouteResponse's State generic type parameter with any. Neither has a dependency on or interactions with the Component's state so it seems simpler to avoid typing it. Change-Id: I5f1eb3c299be4893a071c83f475f9aceddf45178 --- M src/client/index.tsx M src/common/routers/api.ts M src/common/routers/route.ts M src/common/routers/router.ts M src/server/index.tsx 5 files changed, 21 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/62/380662/1 diff --git a/src/client/index.tsx b/src/client/index.tsx index 554a266..821b62a 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -14,7 +14,7 @@ throw new Error('Missing element with "root" ID.'); } -const renderPageRoot = ({ Component, props }: RouteResponse) => { +const renderPageRoot = ({ Component, props }: RouteResponse) => { render( diff --git a/src/common/routers/api.ts b/src/common/routers/api.ts index 873ae7c..b562789 100644 --- a/src/common/routers/api.ts +++ b/src/common/routers/api.ts @@ -1,5 +1,4 @@ import { Props as WikiProps, Params as WikiParams } from "../pages/wiki"; -import { State as AboutState } from "../pages/about"; import { AnyRoute, Route, newRoute } from "./route"; export const home: Route = newRoute({ @@ -9,14 +8,14 @@ chunkName: "pages/home" }); -export const about: Route = newRoute({ +export const about: Route = newRoute({ path: "/about", importModule: () => import(/* webpackChunkName: "pages/about" */ "../pages/about"), chunkName: "pages/about" }); -export const wiki: Route = newRoute({ +export const wiki: Route = newRoute({ path: "/wiki/:title", importModule: () => import(/* webpackChunkName: "pages/wiki" */ "../pages/wiki"), diff --git a/src/common/routers/route.ts b/src/common/routers/route.ts index 639adcf..57fba9f 100644 --- a/src/common/routers/route.ts +++ b/src/common/routers/route.ts @@ -11,9 +11,9 @@ * pages/ subdirectory should implicitly implement this interface or typing will * fail in routers/api. */ -export interface PageModule { +export interface PageModule { /** A Preact view component. */ - Component: AnyComponent ; + Component: AnyComponent ; /** * A function that returns a Promise for the dependencies needed to construct @@ -22,29 +22,29 @@ initialProps?: (params: RouteParams) => Promise; } -export interface RouteConfiguration { +export interface RouteConfiguration { path: string; - importModule: () => Promise >; + importModule: () => Promise ; chunkName: string; status?: number; } -export interface Route - extends RouteConfiguration { +export interface Route + extends RouteConfiguration { status: number; /** Generates a URL from parameters. */ url: (params?: Params) => string; } -export type AnyRoute = Route ; +export type AnyRoute = Route ; -export const newRoute = ({ +export const newRoute = ({ path, importModule, chunkName, status = 200 -}: RouteConfiguration ): Route => ({ +}: RouteConfiguration): Route => ({ path, importModule, chunkName, diff --git a/src/common/routers/router.ts b/src/common/routers/router.ts index 2de064b..8a563d8 100644 --- a/src/common/routers/router.ts +++ b/src/common/routers/router.ts @@ -2,10 +2,10 @@ import { AnyComponent } from "../components/preact-utils"; import { AnyRoute, PageModule, RouteParams } from "../../common/routers/route"; -export interface RouteResponse { +export interface RouteResponse { chunkName: string; status: number; - Component: AnyComponent ; + Component: AnyComponent ; props: { path: string; url: string; @@ -15,7 +15,7 @@ } export interface Router { - route(url: string): Promise >; + route(url: string): Promise ; } interface ParsedRoute extends AnyRoute { @@ -46,21 +46,18 @@ ); function requestInitialProps( - module: PageModule , + module: PageModule, params: RouteParams -): Promise { - if (module.initialProps) { -return module.initialProps(params); - } - return Promise.resolve({}); +): Promise { + return module.initialProps ? module.initialProps(params) : Promise.resolve(); } const respond = ( route: ParsedRoute, url: string, params: RouteParams -): Promise > => - route.importModule().then((module: