Skip to content

Commit

Permalink
protect ie8!
Browse files Browse the repository at this point in the history
  • Loading branch information
mattydoincode committed Nov 13, 2015
1 parent 0e16e6c commit a0877f9
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 165 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"loose": "all",
"plugins": [
"dev-expression"
],
"blacklist": [
"es7.classProperties"
]
}
40 changes: 20 additions & 20 deletions modules/IndexRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@ const { string, object } = React.PropTypes
*/
class IndexRedirect extends Component {

static createRouteFromReactElement(element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = Redirect.createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRedirect> does not make sense at the root of your route config'
)
}
}

static propTypes = {
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
}

/* istanbul ignore next: sanity check */
render() {
invariant(
Expand All @@ -41,4 +21,24 @@ class IndexRedirect extends Component {

}

IndexRedirect.propTypes = {
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
}

IndexRedirect.createRouteFromReactElement = function (element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = Redirect.createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRedirect> does not make sense at the root of your route config'
)
}
}

export default IndexRedirect
40 changes: 20 additions & 20 deletions modules/IndexRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ const { func } = React.PropTypes
*/
class IndexRoute extends Component {

static createRouteFromReactElement(element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRoute> does not make sense at the root of your route config'
)
}
}

static propTypes = {
path: falsy,
component,
components,
getComponent: func,
getComponents: func
}

/* istanbul ignore next: sanity check */
render() {
invariant(
false,
'<IndexRoute> elements are for router configuration only and should not be rendered'
)
}

}

IndexRoute.propTypes = {
path: falsy,
component,
components,
getComponent: func,
getComponents: func
}

IndexRoute.createRouteFromReactElement = function (element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRoute> does not make sense at the root of your route config'
)
}
}

export default IndexRoute
41 changes: 21 additions & 20 deletions modules/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,6 @@ function isEmptyObject(object) {
*/
class Link extends Component {

static contextTypes = {
history: object
}

static propTypes = {
to: string.isRequired,
query: object,
hash: string,
state: object,
activeStyle: object,
activeClassName: string,
onlyActiveOnIndex: bool.isRequired,
onClick: func
}

static defaultProps = {
onlyActiveOnIndex: false,
className: '',
style: {}
}

handleClick(event) {
let allowTransition = true
Expand Down Expand Up @@ -122,4 +102,25 @@ class Link extends Component {

}

Link.contextTypes = {
history: object
}

Link.propTypes = {
to: string.isRequired,
query: object,
hash: string,
state: object,
activeStyle: object,
activeClassName: string,
onlyActiveOnIndex: bool.isRequired,
onClick: func
}

Link.defaultProps = {
onlyActiveOnIndex: false,
className: '',
style: {}
}

export default Link
108 changes: 54 additions & 54 deletions modules/Redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,70 @@ const { string, object } = React.PropTypes
*/
class Redirect extends Component {

static createRouteFromReactElement(element) {
const route = createRouteFromReactElement(element)

if (route.from)
route.path = route.from

route.onEnter = function (nextState, replaceState) {
const { location, params } = nextState

let pathname
if (route.to.charAt(0) === '/') {
pathname = formatPattern(route.to, params)
} else if (!route.to) {
pathname = location.pathname
} else {
let routeIndex = nextState.routes.indexOf(route)
let parentPattern = Redirect.getRoutePattern(nextState.routes, routeIndex - 1)
let pattern = parentPattern.replace(/\/*$/, '/') + route.to
pathname = formatPattern(pattern, params)
}

replaceState(
route.state || location.state,
pathname,
route.query || location.query
)
}

return route
/* istanbul ignore next: sanity check */
render() {
invariant(
false,
'<Redirect> elements are for router configuration only and should not be rendered'
)
}

static getRoutePattern(routes, routeIndex) {
let parentPattern = ''

for (let i = routeIndex; i >= 0; i--) {
let route = routes[i]
let pattern = route.path || ''
parentPattern = pattern.replace(/\/*$/, '/') + parentPattern
}

if (pattern.indexOf('/') === 0)
break
Redirect.createRouteFromReactElement = function (element) {
const route = createRouteFromReactElement(element)

if (route.from)
route.path = route.from

route.onEnter = function (nextState, replaceState) {
const { location, params } = nextState

let pathname
if (route.to.charAt(0) === '/') {
pathname = formatPattern(route.to, params)
} else if (!route.to) {
pathname = location.pathname
} else {
let routeIndex = nextState.routes.indexOf(route)
let parentPattern = Redirect.getRoutePattern(nextState.routes, routeIndex - 1)
let pattern = parentPattern.replace(/\/*$/, '/') + route.to
pathname = formatPattern(pattern, params)
}

return '/' + parentPattern
replaceState(
route.state || location.state,
pathname,
route.query || location.query
)
}

static propTypes = {
path: string,
from: string, // Alias for path
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
}
return route
}

/* istanbul ignore next: sanity check */
render() {
invariant(
false,
'<Redirect> elements are for router configuration only and should not be rendered'
)
Redirect.getRoutePattern = function (routes, routeIndex) {
let parentPattern = ''

for (let i = routeIndex; i >= 0; i--) {
let route = routes[i]
let pattern = route.path || ''
parentPattern = pattern.replace(/\/*$/, '/') + parentPattern

if (pattern.indexOf('/') === 0)
break
}

return '/' + parentPattern
}

Redirect.propTypes = {
path: string,
from: string, // Alias for path
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
}

export default Redirect
20 changes: 10 additions & 10 deletions modules/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ const { string, func } = React.PropTypes
*/
class Route extends Component {

static createRouteFromReactElement = createRouteFromReactElement

static propTypes = {
path: string,
component,
components,
getComponent: func,
getComponents: func
}

/* istanbul ignore next: sanity check */
render() {
invariant(
Expand All @@ -37,4 +27,14 @@ class Route extends Component {

}

Route.createRouteFromReactElement = createRouteFromReactElement

Route.propTypes = {
path: string,
component,
components,
getComponent: func,
getComponents: func
}

export default Route
32 changes: 16 additions & 16 deletions modules/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ const { func, object } = React.PropTypes
*/
class Router extends Component {

static propTypes = {
history: object,
children: routes,
routes, // alias for children
RoutingContext: func.isRequired,
createElement: func,
onError: func,
onUpdate: func,
parseQueryString: func,
stringifyQuery: func
}

static defaultProps = {
RoutingContext
}

constructor(props, context) {
super(props, context)

Expand Down Expand Up @@ -107,4 +91,20 @@ class Router extends Component {

}

Router.propTypes = {
history: object,
children: routes,
routes, // alias for children
RoutingContext: func.isRequired,
createElement: func,
onError: func,
onUpdate: func,
parseQueryString: func,
stringifyQuery: func
}

Router.defaultProps = {
RoutingContext
}

export default Router
Loading

0 comments on commit a0877f9

Please sign in to comment.