From 6e4467c37963e826fbf47cc2460130aa83608503 Mon Sep 17 00:00:00 2001 From: Kostya Esmukov Date: Thu, 27 Oct 2016 15:35:59 +0300 Subject: [PATCH] react-router: added render prop and fixed applyRouterMiddleware types --- react-router/index.d.ts | 2 +- react-router/lib/Router.d.ts | 20 +++++++++++--------- react-router/lib/applyRouterMiddleware.d.ts | 8 +++++--- react-router/react-router-tests.tsx | 14 +++++++++++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/react-router/index.d.ts b/react-router/index.d.ts index 8dfc205478..f85b121c6a 100644 --- a/react-router/index.d.ts +++ b/react-router/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-router v2.0.0 // Project: https://github.com/rackt/react-router -// Definitions by: Sergey Buturlakin , Yuichi Murata , Václav Ostrožlík , Nathan Brown , Alex Wendland +// Definitions by: Sergey Buturlakin , Yuichi Murata , Václav Ostrožlík , Nathan Brown , Alex Wendland , Kostya Esmukov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export as namespace ReactRouter; diff --git a/react-router/lib/Router.d.ts b/react-router/lib/Router.d.ts index c375f71513..5a4cfacb15 100644 --- a/react-router/lib/Router.d.ts +++ b/react-router/lib/Router.d.ts @@ -1,4 +1,5 @@ import * as React from 'react'; +import RouterContext from './RouterContext'; import { QueryString, Query, Location, LocationDescriptor, LocationState, @@ -48,16 +49,17 @@ declare namespace Router { components: RouteComponent[]; } - interface RouterProps extends React.Props { - history?: History; - routes?: RouteConfig; // alias for children - createElement?: (component: RouteComponent, props: Object) => any; - onError?: (error: any) => any; - onUpdate?: () => any; - parseQueryString?: ParseQueryString; - stringifyQuery?: StringifyQuery; + interface RouterProps extends React.Props { + history?: History; + routes?: RouteConfig; // alias for children + createElement?: (component: RouteComponent, props: Object) => any; + onError?: (error: any) => any; + onUpdate?: () => any; + parseQueryString?: ParseQueryString; + stringifyQuery?: StringifyQuery; basename?: string; - } + render?: (renderProps: React.Props<{}>) => RouterContext; + } interface PlainRoute { path?: RoutePattern; diff --git a/react-router/lib/applyRouterMiddleware.d.ts b/react-router/lib/applyRouterMiddleware.d.ts index a92384bba6..ed87d815db 100644 --- a/react-router/lib/applyRouterMiddleware.d.ts +++ b/react-router/lib/applyRouterMiddleware.d.ts @@ -1,7 +1,9 @@ import * as React from 'react'; +import Router from './Router'; +import RouterContext from './RouterContext'; export interface Middleware { - renderRouterContext: (previous: React.Props<{}>[], props: React.Props<{}>) => React.Props<{}>[]; - renderRouteComponent: (previous: React.Props<{}>[], props: React.Props<{}>) => React.Props<{}>[]; + renderRouterContext?: (previous: RouterContext, props: React.Props<{}>) => RouterContext; + renderRouteComponent?: (previous: Router.RouteComponent, props: React.Props<{}>) => Router.RouteComponent; } -export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: React.Props<{}>) => React.Props<{}>[]; +export default function applyRouterMiddleware(...middlewares: Middleware[]): (renderProps: React.Props<{}>) => RouterContext; diff --git a/react-router/react-router-tests.tsx b/react-router/react-router-tests.tsx index 77262bad50..77a0703462 100644 --- a/react-router/react-router-tests.tsx +++ b/react-router/react-router-tests.tsx @@ -2,7 +2,7 @@ import * as React from "react" import * as ReactDOM from "react-dom" import {renderToString} from "react-dom/server"; -import { browserHistory, hashHistory, match, createMemoryHistory, withRouter, routerShape, Router, Route, IndexRoute, InjectedRouter, Link, RouterOnContext, RouterContext} from "react-router"; +import { applyRouterMiddleware, browserHistory, hashHistory, match, createMemoryHistory, withRouter, routerShape, Router, Route, IndexRoute, InjectedRouter, Link, RouterOnContext, RouterContext} from "react-router"; interface MasterContext { router: RouterOnContext; @@ -105,3 +105,15 @@ const routes = ( match({history, routes, location: "baseurl"}, (error, redirectLocation, renderProps) => { renderToString(); }); + + +ReactDOM.render(( + child + })} + > + +), document.body);