From 04abf31354f8409519dbba2f20dd6922b6bf23d1 Mon Sep 17 00:00:00 2001 From: vrde Date: Mon, 12 Oct 2015 16:51:03 +0200 Subject: [PATCH] Remove ProxyRoute --- js/components/ascribe_routes/proxy_route.js | 80 ------ .../proxy_routes/redirect_proxy_handler.js | 4 +- .../whitelabel/prize/prize_routes.js | 64 +++-- .../whitelabel/wallet/wallet_routes.js | 227 ++++++++---------- js/routes.js | 41 ++-- 5 files changed, 146 insertions(+), 270 deletions(-) delete mode 100644 js/components/ascribe_routes/proxy_route.js diff --git a/js/components/ascribe_routes/proxy_route.js b/js/components/ascribe_routes/proxy_route.js deleted file mode 100644 index 1e29de46..00000000 --- a/js/components/ascribe_routes/proxy_route.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -import React from 'react'; -import invariant from 'invariant'; -import { createRoutes } from 'react-router'; - -const { string, bool, func, object, oneOfType } = React.PropTypes; - -const ProxyRoute = React.createClass({ - propTypes: { - path: string, - ignoreScrollBehavior: bool, - handler: oneOfType([ func, string ]), - component: oneOfType([ func, string ]), - components: oneOfType([ oneOfType([ func, string ]), object ]), - getComponents: func, - proxyHandler: func - }, - - statics: { - createRouteFromReactElement(element) { - /** - * Generally creating custom `Route`s is not supported by react-router. - * - * However, if we take a look at how `Route`s are declared/generated in their github repo, - * we see that it's fairly straight forward: - * - https://github.com/rackt/react-router/blob/master/modules/Route.js#L21 - * - * ``` - * const route = createRouteFromReactElement(element) - * - * [...] - * - * return route; - * ``` - * - * Unfortunately, though `createRouteFromReactElement` is not exported by - * react-router, as can be seen here: - * - https://github.com/rackt/react-router/blob/master/modules/index.js#L19 - * - * Still there is a trick we can use to call this method manually. - * We call the public method `createRoutes`: - * - (https://github.com/rackt/react-router/blob/master/modules/RouteUtils.js#L91) - * which then calls `createRoutesFromReactChildren` - * - * For each route element submitted as an array, this method checks if - * `element.type.createRouteFromReactElement` is `true` or `false`. - * - * So what we can do is just simply set our element's `type.createRouteFromReactElement` - * property to `false`, so that the if statement falls into the methods `else` case - * and calls `createRouteFromReactElement`: - * - https://github.com/rackt/react-router/blob/master/modules/RouteUtils.js#L77 - * - * After returning from `createRoutes`, we set `element.type.createRouteFromReactElement` - * to its original value and replace route's `component`, with our manually inserted - * component. - */ - - const createRouteFromReactElementCopy = element.type.createRouteFromReactElement; - element.type.createRouteFromReactElement = false; - const [ route ] = createRoutes(element); - element.type.createRouteFromReactElement = createRouteFromReactElementCopy; - - const Component = route.component; - const ProxyHandler = element.props.proxyHandler; - route.component = ProxyHandler(Component); - - return route; - } - }, - - render() { - invariant( - false, - ' elements are for router configuration only and should not be rendered' - ); - } -}); - -export default ProxyRoute; \ No newline at end of file diff --git a/js/components/ascribe_routes/proxy_routes/redirect_proxy_handler.js b/js/components/ascribe_routes/proxy_routes/redirect_proxy_handler.js index 055abb79..91cf48a7 100644 --- a/js/components/ascribe_routes/proxy_routes/redirect_proxy_handler.js +++ b/js/components/ascribe_routes/proxy_routes/redirect_proxy_handler.js @@ -12,7 +12,7 @@ import AppConstants from '../../../constants/application_constants'; const { object } = React.PropTypes; /** - * Can be used in combination with `ProxyRoute` as an intermediate Handler + * Can be used in combination with `Route` as an intermediate Handler * between the actual component we want to display dependent on a certain state * that is required to display that component. * @@ -102,4 +102,4 @@ export default function RedirectProxyHandler({to, when}) { } }); }; -} \ No newline at end of file +} diff --git a/js/components/whitelabel/prize/prize_routes.js b/js/components/whitelabel/prize/prize_routes.js index f00e1abb..b59ac537 100644 --- a/js/components/whitelabel/prize/prize_routes.js +++ b/js/components/whitelabel/prize/prize_routes.js @@ -19,7 +19,6 @@ import ErrorNotFoundPage from '../../../components/error_not_found_page'; import App from './prize_app'; import AppConstants from '../../../constants/application_constants'; -import ProxyRoute from '../../../components/ascribe_routes/proxy_route'; import RedirectProxyHandler from '../../../components/ascribe_routes/proxy_routes/redirect_proxy_handler'; @@ -29,44 +28,37 @@ function getRoutes() { return ( - - - - - + + + + + + + - - - - - - + + + + ); } -export default getRoutes; \ No newline at end of file +export default getRoutes; diff --git a/js/components/whitelabel/wallet/wallet_routes.js b/js/components/whitelabel/wallet/wallet_routes.js index 2908f554..9900a9a6 100644 --- a/js/components/whitelabel/wallet/wallet_routes.js +++ b/js/components/whitelabel/wallet/wallet_routes.js @@ -30,7 +30,6 @@ import IkonotvContractNotifications from './components/ikonotv/ikonotv_contract_ import CCRegisterPiece from './components/cc/cc_register_piece'; -import ProxyRoute from '../../../components/ascribe_routes/proxy_route'; import RedirectProxyHandler from '../../../components/ascribe_routes/proxy_routes/redirect_proxy_handler'; import WalletApp from './wallet_app'; @@ -43,140 +42,114 @@ let ROUTES = { 'cyland': ( - - - - - - - - - - - - + + + + + + + + + + + + ), 'cc': ( - - - - - - - - - - - - + + + + + + + + + + + + ), 'ikonotv': ( - - - - - - - - - - - - - - + + + + + + + + + + + + + + ) }; @@ -191,4 +164,4 @@ function getRoutes(commonRoutes, subdomain) { } -export default getRoutes; \ No newline at end of file +export default getRoutes; diff --git a/js/routes.js b/js/routes.js index e7dd8b68..fefb95e1 100644 --- a/js/routes.js +++ b/js/routes.js @@ -25,7 +25,6 @@ import ErrorNotFoundPage from './components/error_not_found_page'; import RegisterPiece from './components/register_piece'; -import ProxyRoute from './components/ascribe_routes/proxy_route'; import RedirectProxyHandler from './components/ascribe_routes/proxy_routes/redirect_proxy_handler'; import AppConstants from './constants/application_constants'; @@ -35,42 +34,34 @@ let baseUrl = AppConstants.baseUrl; let COMMON_ROUTES = ( - - + - - - + + component={RedirectProxyHandler({to: '/', when: 'loggedOut'})(LogoutContainer)}/> - - + - + + component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(ContractSettings)}/>