1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Remove ProxyRoute

This commit is contained in:
vrde 2015-10-12 16:51:03 +02:00
parent 356e0e368a
commit 04abf31354
5 changed files with 146 additions and 270 deletions

View File

@ -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,
'<ProxyRoute> elements are for router configuration only and should not be rendered'
);
}
});
export default ProxyRoute;

View File

@ -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}) {
}
});
};
}
}

View File

@ -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 (
<Route path={baseUrl} component={App}>
<IndexRoute component={Landing} />
<ProxyRoute
path="login"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={LoginContainer} />
<ProxyRoute
path="logout"
proxyHandler={RedirectProxyHandler({to: '/', when: 'loggedOut'})}
component={LogoutContainer}/>
<ProxyRoute
path="signup"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={SignupContainer} />
<ProxyRoute
path="password_reset"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={PasswordResetContainer} />
<ProxyRoute
path="settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={SettingsContainer}/>
<Route
path='login'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(LoginContainer)} />
<Route
path='logout'
component={RedirectProxyHandler({to: '/', when: 'loggedOut'})(LogoutContainer)}/>
<Route
path='signup'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(SignupContainer)} />
<Route
path='password_reset'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(PasswordResetContainer)} />
<Route
path='settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(SettingsContainer)}/>
<Route
path='register_piece'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(PrizeRegisterPiece)}
headerTitle='+ NEW WORK'/>
<Route
path='collection'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(PrizePieceList)}
headerTitle='COLLECTION'/>
<ProxyRoute
path="register_piece"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={PrizeRegisterPiece}
headerTitle="+ NEW WORK"/>
<ProxyRoute
path="collection"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={PrizePieceList}
headerTitle="COLLECTION"/>
<Route path="pieces/:pieceId" component={PrizePieceContainer} />
<Route path="editions/:editionId" component={EditionContainer} />
<Route path="verify" component={CoaVerifyContainer} />
<Route path="*" component={ErrorNotFoundPage} />
<Route path='pieces/:pieceId' component={PrizePieceContainer} />
<Route path='editions/:editionId' component={EditionContainer} />
<Route path='verify' component={CoaVerifyContainer} />
<Route path='*' component={ErrorNotFoundPage} />
</Route>
);
}
export default getRoutes;
export default getRoutes;

View File

@ -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': (
<Route path={baseUrl} component={WalletApp}>
<IndexRoute component={CylandLanding} />
<ProxyRoute
path="login"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={LoginContainer} />
<ProxyRoute
path="logout"
proxyHandler={RedirectProxyHandler({to: '/', when: 'loggedOut'})}
component={LogoutContainer}/>
<ProxyRoute
path="signup"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={SignupContainer} />
<ProxyRoute
path="password_reset"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={PasswordResetContainer} />
<ProxyRoute
path="settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={SettingsContainer}/>
<ProxyRoute
path="contract_settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={ContractSettings}/>
<ProxyRoute
path="register_piece"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={CylandRegisterPiece}
headerTitle="+ NEW WORK"/>
<ProxyRoute
path="collection"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={CylandPieceList}
headerTitle="COLLECTION"/>
<Route path="editions/:editionId" component={EditionContainer} />
<Route path="verify" component={CoaVerifyContainer} />
<Route path="pieces/:pieceId" component={CylandPieceContainer} />
<Route path="*" component={ErrorNotFoundPage} />
<Route
path='login'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(LoginContainer)} />
<Route
path='logout'
component={RedirectProxyHandler({to: '/', when: 'loggedOut'})(LogoutContainer)}/>
<Route
path='signup'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(SignupContainer)} />
<Route
path='password_reset'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(PasswordResetContainer)} />
<Route
path='settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(SettingsContainer)}/>
<Route
path='contract_settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(ContractSettings)}/>
<Route
path='register_piece'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(CylandRegisterPiece)}
headerTitle='+ NEW WORK'/>
<Route
path='collection'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(CylandPieceList)}
headerTitle='COLLECTION'/>
<Route path='editions/:editionId' component={EditionContainer} />
<Route path='verify' component={CoaVerifyContainer} />
<Route path='pieces/:pieceId' component={CylandPieceContainer} />
<Route path='*' component={ErrorNotFoundPage} />
</Route>
),
'cc': (
<Route path={baseUrl} component={WalletApp}>
<ProxyRoute
path="login"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={LoginContainer} />
<ProxyRoute
path="logout"
proxyHandler={RedirectProxyHandler({to: '/', when: 'loggedOut'})}
component={LogoutContainer}/>
<ProxyRoute
path="signup"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={SignupContainer} />
<ProxyRoute
path="password_reset"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={PasswordResetContainer} />
<ProxyRoute
path="settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={SettingsContainer}/>
<ProxyRoute
path="contract_settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={ContractSettings}/>
<ProxyRoute
path="register_piece"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={CCRegisterPiece}
headerTitle="+ NEW WORK"/>
<ProxyRoute
path="collection"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={PieceList}
headerTitle="COLLECTION"/>
<Route path="pieces/:pieceId" component={PieceContainer} />
<Route path="editions/:editionId" component={EditionContainer} />
<Route path="verify" component={CoaVerifyContainer} />
<Route path="*" component={ErrorNotFoundPage} />
<Route
path='login'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(LoginContainer)} />
<Route
path='logout'
component={RedirectProxyHandler({to: '/', when: 'loggedOut'})(LogoutContainer)}/>
<Route
path='signup'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(SignupContainer)} />
<Route
path='password_reset'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(PasswordResetContainer)} />
<Route
path='settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(SettingsContainer)}/>
<Route
path='contract_settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(ContractSettings)}/>
<Route
path='register_piece'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(CCRegisterPiece)}
headerTitle='+ NEW WORK'/>
<Route
path='collection'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(PieceList)}
headerTitle='COLLECTION'/>
<Route path='pieces/:pieceId' component={PieceContainer} />
<Route path='editions/:editionId' component={EditionContainer} />
<Route path='verify' component={CoaVerifyContainer} />
<Route path='*' component={ErrorNotFoundPage} />
</Route>
),
'ikonotv': (
<Route path={baseUrl} component={WalletApp}>
<IndexRoute component={IkonotvLanding} />
<ProxyRoute
path="login"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={LoginContainer} />
<ProxyRoute
path="logout"
proxyHandler={RedirectProxyHandler({to: '/', when: 'loggedOut'})}
component={LogoutContainer}/>
<ProxyRoute
path="signup"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={SignupContainer} />
<ProxyRoute
path="password_reset"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={PasswordResetContainer} />
<ProxyRoute
path="settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={SettingsContainer}/>
<ProxyRoute
path="contract_settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={ContractSettings}/>
<ProxyRoute
path="request_loan"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={ContractAgreementForm}
headerTitle="SEND NEW CONTRACT"
aclName="acl_create_contractagreement"/>
<ProxyRoute
path="register_piece"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={IkonotvRegisterPiece}
headerTitle="+ NEW WORK"
aclName="acl_create_piece"/>
<ProxyRoute
path="collection"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={IkonotvPieceList}
headerTitle="COLLECTION"/>
<ProxyRoute
path="contract_notifications"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={IkonotvContractNotifications}/>
<Route path="pieces/:pieceId" component={IkonotvPieceContainer} />
<Route path="editions/:editionId" component={EditionContainer} />
<Route path="verify" component={CoaVerifyContainer} />
<Route path="*" component={ErrorNotFoundPage} />
<Route
path='login'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(LoginContainer)} />
<Route
path='logout'
component={RedirectProxyHandler({to: '/', when: 'loggedOut'})(LogoutContainer)}/>
<Route
path='signup'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(SignupContainer)} />
<Route
path='password_reset'
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(PasswordResetContainer)} />
<Route
path='settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(SettingsContainer)}/>
<Route
path='contract_settings'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(ContractSettings)}/>
<Route
path='request_loan'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(ContractAgreementForm)}
headerTitle='SEND NEW CONTRACT'
aclName='acl_create_contractagreement'/>
<Route
path='register_piece'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(IkonotvRegisterPiece)}
headerTitle='+ NEW WORK'
aclName='acl_create_piece'/>
<Route
path='collection'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(IkonotvPieceList)}
headerTitle='COLLECTION'/>
<Route
path='contract_notifications'
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(IkonotvContractNotifications)}/>
<Route path='pieces/:pieceId' component={IkonotvPieceContainer} />
<Route path='editions/:editionId' component={EditionContainer} />
<Route path='verify' component={CoaVerifyContainer} />
<Route path='*' component={ErrorNotFoundPage} />
</Route>
)
};
@ -191,4 +164,4 @@ function getRoutes(commonRoutes, subdomain) {
}
export default getRoutes;
export default getRoutes;

View File

@ -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 = (
<Route path={baseUrl} component={App}>
<ProxyRoute
<Route
path="login"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={LoginContainer} />
<ProxyRoute
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(LoginContainer)} />
<Route
path="register_piece"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={RegisterPiece}
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(RegisterPiece)}
headerTitle="+ NEW WORK"/>
<ProxyRoute
<Route
path="collection"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={PieceList}
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(PieceList)}
headerTitle="COLLECTION"/>
<ProxyRoute
<Route
path="signup"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={SignupContainer} />
<ProxyRoute
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(SignupContainer)} />
<Route
path="logout"
proxyHandler={RedirectProxyHandler({to: '/', when: 'loggedOut'})}
component={LogoutContainer}/>
component={RedirectProxyHandler({to: '/', when: 'loggedOut'})(LogoutContainer)}/>
<Route path="pieces/:pieceId" component={PieceContainer} />
<Route path="editions/:editionId" component={EditionContainer} />
<ProxyRoute
<Route
path="password_reset"
proxyHandler={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})}
component={PasswordResetContainer} />
<ProxyRoute
component={RedirectProxyHandler({to: '/collection', when: 'loggedIn'})(PasswordResetContainer)} />
<Route
path="settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={SettingsContainer}/>
<ProxyRoute
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(SettingsContainer)}/>
<Route
path="contract_settings"
proxyHandler={RedirectProxyHandler({to: '/login', when: 'loggedOut'})}
component={ContractSettings}/>
component={RedirectProxyHandler({to: '/login', when: 'loggedOut'})(ContractSettings)}/>
<Route path="coa_verify" component={CoaVerifyContainer} />
<Route path="*" component={ErrorNotFoundPage} />
</Route>