diff --git a/.travis.yml b/.travis.yml index fde32f5f25..8b0177a90f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,4 @@ node_js: before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start +sudo: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ead757f51..465c19cdc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +v0.13.4 - Tue, 06 Oct 2015 13:13:20 GMT +--------------------------------------- + +- [b237238](../../commit/b237238) [fixed] Removed getter for IE8 compat +- [53ce7f1](../../commit/53ce7f1) [fixed] #1148 regex for detecting trailing slashes + + v0.13.3 - Wed, 29 Apr 2015 01:47:08 GMT --------------------------------------- diff --git a/README.md b/README.md index 985c291dd5..a2b7abdaff 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,24 @@ -[![npm package](https://img.shields.io/npm/v/react-router.svg?style=flat-square)](https://www.npmjs.org/package/react-router) -[![build status](https://img.shields.io/travis/rackt/react-router/master.svg?style=flat-square)](https://travis-ci.org/rackt/react-router) -[![dependency status](https://img.shields.io/david/rackt/react-router.svg?style=flat-square)](https://david-dm.org/rackt/react-router) -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rackt/react-router?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![Build Status](https://travis-ci.org/nkt/react-router-old.svg?branch=master)](https://travis-ci.org/nkt/react-router-old) +[![npm package](https://img.shields.io/npm/v/react-router-old.svg)](https://www.npmjs.org/package/react-router-old) -React Router -============ +React Router Old +================ -A complete routing library for React. +---------- + +Imporant note +------------- +This is the fork of original React Router. It has been created for adding support +for React 0.14.x but without a lot of changes, like React Router 1.0.x does. +I guess there are many typos in docs or comments, but it passed all existed tests +with React 0.14.x, so you can use this for fluent migrating to React 0.14. -Docs ----- +---------- + +A complete routing library for React. -- [Guide: Overview](/docs/guides/overview.md) -- [API](/docs/api/) +* [Guides](/docs/guides) +* [Docs](/doc) Important Notes --------------- @@ -124,7 +130,7 @@ Related Modules - [rnr-constrained-route](https://github.com/bjyoungblood/rnr-constrained-route) - validate paths and parameters on route handlers. -- [react-router-bootstrap](https://github.com/mtscout6/react-router-bootstrap) - Integration with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap) components. +- [react-router-bootstrap](https://github.com/react-bootstrap/react-router-bootstrap) - Integration with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap) components. - [react-router-proxy-loader](https://github.com/odysseyscience/react-router-proxy-loader) - A Webpack loader to dynamically load react-router components on-demand Contributing diff --git a/bower.json b/bower.json index 76f7e4dbfd..d8a3ad7ac2 100644 --- a/bower.json +++ b/bower.json @@ -1,9 +1,9 @@ { - "name": "react-router", - "version": "0.13.3", + "name": "react-router-old", + "version": "0.13.4", "description": "A complete routing library for React.js", "main": "build/umd/ReactRouter.js", - "homepage": "https://github.com/rackt/react-router", + "homepage": "https://github.com/nkt/react-router-old", "authors": [ "Ryan Florence", "Michael Jackson" diff --git a/build/README.md b/build/README.md index 985c291dd5..534047546c 100644 --- a/build/README.md +++ b/build/README.md @@ -1,18 +1,13 @@ -[![npm package](https://img.shields.io/npm/v/react-router.svg?style=flat-square)](https://www.npmjs.org/package/react-router) -[![build status](https://img.shields.io/travis/rackt/react-router/master.svg?style=flat-square)](https://travis-ci.org/rackt/react-router) -[![dependency status](https://img.shields.io/david/rackt/react-router.svg?style=flat-square)](https://david-dm.org/rackt/react-router) -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rackt/react-router?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![build status](https://img.shields.io/travis/nkt/react-router-old/master.svg)](https://travis-ci.org/nkt/react-router-old) +[![npm package](https://img.shields.io/npm/v/react-router.svg)](https://www.npmjs.org/package/react-router) React Router ============ A complete routing library for React. -Docs ----- - -- [Guide: Overview](/docs/guides/overview.md) -- [API](/docs/api/) +* [Guides](/docs/guides) +* [Docs](/doc) Important Notes --------------- @@ -124,7 +119,7 @@ Related Modules - [rnr-constrained-route](https://github.com/bjyoungblood/rnr-constrained-route) - validate paths and parameters on route handlers. -- [react-router-bootstrap](https://github.com/mtscout6/react-router-bootstrap) - Integration with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap) components. +- [react-router-bootstrap](https://github.com/react-bootstrap/react-router-bootstrap) - Integration with [react-bootstrap](https://github.com/react-bootstrap/react-bootstrap) components. - [react-router-proxy-loader](https://github.com/odysseyscience/react-router-proxy-loader) - A Webpack loader to dynamically load react-router components on-demand Contributing diff --git a/build/lib/History.js b/build/lib/History.js index f6194ad34d..03ec1380ce 100644 --- a/build/lib/History.js +++ b/build/lib/History.js @@ -1,7 +1,7 @@ 'use strict'; -var invariant = require('react/lib/invariant'); -var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM; +var invariant = require('invariant'); +var canUseDOM = require('exenv').canUseDOM; var History = { diff --git a/build/lib/Match.js b/build/lib/Match.js index ec5f8bc571..e113e1b1da 100644 --- a/build/lib/Match.js +++ b/build/lib/Match.js @@ -1,10 +1,10 @@ +/* jshint -W084 */ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -/* jshint -W084 */ +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + var PathUtils = require('./PathUtils'); function deepSearch(route, pathname, query) { @@ -27,29 +27,20 @@ function deepSearch(route, pathname, query) { // No child routes matched; try the default route. var defaultRoute = route.defaultRoute; - if (defaultRoute && (params = PathUtils.extractParams(defaultRoute.path, pathname))) { - return new Match(pathname, params, query, [route, defaultRoute]); - } // Does the "not found" route match? + if (defaultRoute && (params = PathUtils.extractParams(defaultRoute.path, pathname))) return new Match(pathname, params, query, [route, defaultRoute]); + + // Does the "not found" route match? var notFoundRoute = route.notFoundRoute; - if (notFoundRoute && (params = PathUtils.extractParams(notFoundRoute.path, pathname))) { - return new Match(pathname, params, query, [route, notFoundRoute]); - } // Last attempt: check this route. + if (notFoundRoute && (params = PathUtils.extractParams(notFoundRoute.path, pathname))) return new Match(pathname, params, query, [route, notFoundRoute]); + + // Last attempt: check this route. var params = PathUtils.extractParams(route.path, pathname); - if (params) { - return new Match(pathname, params, query, [route]); - }return null; + if (params) return new Match(pathname, params, query, [route]); + + return null; } var Match = (function () { - function Match(pathname, params, query, routes) { - _classCallCheck(this, Match); - - this.pathname = pathname; - this.params = params; - this.query = query; - this.routes = routes; - } - _createClass(Match, null, [{ key: 'findMatch', @@ -69,6 +60,15 @@ var Match = (function () { } }]); + function Match(pathname, params, query, routes) { + _classCallCheck(this, Match); + + this.pathname = pathname; + this.params = params; + this.query = query; + this.routes = routes; + } + return Match; })(); diff --git a/build/lib/PathUtils.js b/build/lib/PathUtils.js index c39d21052f..f190579ed6 100644 --- a/build/lib/PathUtils.js +++ b/build/lib/PathUtils.js @@ -1,12 +1,12 @@ 'use strict'; -var invariant = require('react/lib/invariant'); +var invariant = require('invariant'); var assign = require('object-assign'); var qs = require('qs'); var paramCompileMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|[*.()\[\]\\+|{}^$]/g; var paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?]?)|[*]/g; -var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?\/|\/\?/g; +var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?\/|\/\?(?![^\/=]+=.*$)/g; var queryMatcher = /\?(.*)$/; var _compiledPatterns = {}; @@ -71,9 +71,9 @@ var PathUtils = { var match = path.match(matcher); - if (!match) { - return null; - }var params = {}; + if (!match) return null; + + var params = {}; paramNames.forEach(function (paramName, index) { params[paramName] = match[index + 1]; @@ -143,9 +143,9 @@ var PathUtils = { var queryString = qs.stringify(query, { arrayFormat: 'brackets' }); - if (queryString) { - return PathUtils.withoutQuery(path) + '?' + queryString; - }return PathUtils.withoutQuery(path); + if (queryString) return PathUtils.withoutQuery(path) + '?' + queryString; + + return PathUtils.withoutQuery(path); } }; diff --git a/build/lib/PropTypes.js b/build/lib/PropTypes.js index fdee9be9aa..08d12700bb 100644 --- a/build/lib/PropTypes.js +++ b/build/lib/PropTypes.js @@ -10,9 +10,7 @@ var PropTypes = assign({}, ReactPropTypes, { * Indicates that a prop should be falsy. */ falsy: function falsy(props, propName, componentName) { - if (props[propName]) { - return new Error('<' + componentName + '> should not have a "' + propName + '" prop'); - } + if (props[propName]) return new Error('<' + componentName + '> should not have a "' + propName + '" prop'); }, /** diff --git a/build/lib/Route.js b/build/lib/Route.js index b2d4ac1e84..b8eeb32feb 100644 --- a/build/lib/Route.js +++ b/build/lib/Route.js @@ -1,56 +1,18 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + var assign = require('react/lib/Object.assign'); -var invariant = require('react/lib/invariant'); -var warning = require('react/lib/warning'); +var invariant = require('invariant'); +var warning = require('warning'); var PathUtils = require('./PathUtils'); var _currentRoute; var Route = (function () { - function Route(name, path, ignoreScrollBehavior, isDefault, isNotFound, onEnter, onLeave, handler) { - _classCallCheck(this, Route); - - this.name = name; - this.path = path; - this.paramNames = PathUtils.extractParamNames(this.path); - this.ignoreScrollBehavior = !!ignoreScrollBehavior; - this.isDefault = !!isDefault; - this.isNotFound = !!isNotFound; - this.onEnter = onEnter; - this.onLeave = onLeave; - this.handler = handler; - } - - _createClass(Route, [{ - key: 'appendChild', - - /** - * Appends the given route to this route's child routes. - */ - value: function appendChild(route) { - invariant(route instanceof Route, 'route.appendChild must use a valid Route'); - - if (!this.childRoutes) this.childRoutes = []; - - this.childRoutes.push(route); - } - }, { - key: 'toString', - value: function toString() { - var string = ''; - - return string; - } - }], [{ + _createClass(Route, null, [{ key: 'createRoute', /** @@ -149,28 +111,26 @@ var Route = (function () { return route; } - }, { - key: 'createDefaultRoute', /** * Creates and returns a route that is rendered when its parent matches * the current URL. */ + }, { + key: 'createDefaultRoute', value: function createDefaultRoute(options) { return Route.createRoute(assign({}, options, { isDefault: true })); } - }, { - key: 'createNotFoundRoute', /** * Creates and returns a route that is rendered when its parent matches * the current URL but none of its siblings do. */ + }, { + key: 'createNotFoundRoute', value: function createNotFoundRoute(options) { return Route.createRoute(assign({}, options, { isNotFound: true })); } - }, { - key: 'createRedirect', /** * Creates and returns a route that automatically redirects the transition @@ -184,6 +144,8 @@ var Route = (function () { * - query The query to use in the redirect URL. Defaults * to using the current query */ + }, { + key: 'createRedirect', value: function createRedirect(options) { return Route.createRoute(assign({}, options, { path: options.path || options.from || '*', @@ -194,6 +156,46 @@ var Route = (function () { } }]); + function Route(name, path, ignoreScrollBehavior, isDefault, isNotFound, onEnter, onLeave, handler) { + _classCallCheck(this, Route); + + this.name = name; + this.path = path; + this.paramNames = PathUtils.extractParamNames(this.path); + this.ignoreScrollBehavior = !!ignoreScrollBehavior; + this.isDefault = !!isDefault; + this.isNotFound = !!isNotFound; + this.onEnter = onEnter; + this.onLeave = onLeave; + this.handler = handler; + } + + /** + * Appends the given route to this route's child routes. + */ + + _createClass(Route, [{ + key: 'appendChild', + value: function appendChild(route) { + invariant(route instanceof Route, 'route.appendChild must use a valid Route'); + + if (!this.childRoutes) this.childRoutes = []; + + this.childRoutes.push(route); + } + }, { + key: 'toString', + value: function toString() { + var string = ''; + + return string; + } + }]); + return Route; })(); diff --git a/build/lib/ScrollHistory.js b/build/lib/ScrollHistory.js index 52a585f3d0..4270a8626d 100644 --- a/build/lib/ScrollHistory.js +++ b/build/lib/ScrollHistory.js @@ -1,16 +1,16 @@ 'use strict'; -var invariant = require('react/lib/invariant'); -var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM; +var invariant = require('invariant'); +var canUseDOM = require('exenv').canUseDOM; var getWindowScrollPosition = require('./getWindowScrollPosition'); function shouldUpdateScroll(state, prevState) { - if (!prevState) { - return true; - } // Don't update scroll position when only the query has changed. - if (state.pathname === prevState.pathname) { - return false; - }var routes = state.routes; + if (!prevState) return true; + + // Don't update scroll position when only the query has changed. + if (state.pathname === prevState.pathname) return false; + + var routes = state.routes; var prevRoutes = prevState.routes; var sharedAncestorRoutes = routes.filter(function (route) { @@ -63,9 +63,9 @@ var ScrollHistory = { }, _updateScroll: function _updateScroll(prevState) { - if (!shouldUpdateScroll(this.state, prevState)) { - return; - }var scrollBehavior = this.constructor.getScrollBehavior(); + if (!shouldUpdateScroll(this.state, prevState)) return; + + var scrollBehavior = this.constructor.getScrollBehavior(); if (scrollBehavior) scrollBehavior.updateScrollPosition(this.constructor.getScrollPosition(this.state.path), this.state.action); } diff --git a/build/lib/components/ActiveHandler.js b/build/lib/components/ActiveHandler.js index 13844bece0..d3d3d38dc2 100644 --- a/build/lib/components/ActiveHandler.js +++ b/build/lib/components/ActiveHandler.js @@ -1,10 +1,12 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var React = require('react'); var ContextWrapper = require('./ContextWrapper'); @@ -19,15 +21,17 @@ var REF_NAME = '__routeHandler__'; */ var RouteHandler = (function (_React$Component) { + _inherits(RouteHandler, _React$Component); + function RouteHandler() { _classCallCheck(this, RouteHandler); - if (_React$Component != null) { - _React$Component.apply(this, arguments); - } + _get(Object.getPrototypeOf(RouteHandler.prototype), 'constructor', this).apply(this, arguments); } - _inherits(RouteHandler, _React$Component); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 _createClass(RouteHandler, [{ key: 'getChildContext', @@ -66,9 +70,9 @@ var RouteHandler = (function (_React$Component) { value: function createChildRouteHandler(props) { var route = this.context.router.getRouteAtDepth(this.getRouteDepth()); - if (route == null) { - return null; - }var childProps = assign({}, props || this.props, { + if (route == null) return null; + + var childProps = assign({}, props || this.props, { ref: REF_NAME, params: this.context.router.getCurrentParams(), query: this.context.router.getCurrentQuery() @@ -92,10 +96,6 @@ var RouteHandler = (function (_React$Component) { return RouteHandler; })(React.Component); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - RouteHandler.contextTypes = { routeDepth: PropTypes.number.isRequired, router: PropTypes.router.isRequired diff --git a/build/lib/components/ContextWrapper.js b/build/lib/components/ContextWrapper.js index e92a81a85e..9aa4c15804 100644 --- a/build/lib/components/ContextWrapper.js +++ b/build/lib/components/ContextWrapper.js @@ -1,30 +1,30 @@ -'use strict'; - -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - /** * This component is necessary to get around a context warning * present in React 0.13.0. It sovles this by providing a separation * between the "owner" and "parent" contexts. */ +'use strict'; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + var React = require('react'); var ContextWrapper = (function (_React$Component) { + _inherits(ContextWrapper, _React$Component); + function ContextWrapper() { _classCallCheck(this, ContextWrapper); - if (_React$Component != null) { - _React$Component.apply(this, arguments); - } + _get(Object.getPrototypeOf(ContextWrapper.prototype), 'constructor', this).apply(this, arguments); } - _inherits(ContextWrapper, _React$Component); - _createClass(ContextWrapper, [{ key: 'render', value: function render() { diff --git a/build/lib/components/DefaultRoute.js b/build/lib/components/DefaultRoute.js index 016a2f817f..8b710641c7 100644 --- a/build/lib/components/DefaultRoute.js +++ b/build/lib/components/DefaultRoute.js @@ -1,8 +1,10 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var PropTypes = require('../PropTypes'); var RouteHandler = require('./RouteHandler'); @@ -16,23 +18,21 @@ var Route = require('./Route'); */ var DefaultRoute = (function (_Route) { + _inherits(DefaultRoute, _Route); + function DefaultRoute() { _classCallCheck(this, DefaultRoute); - if (_Route != null) { - _Route.apply(this, arguments); - } + _get(Object.getPrototypeOf(DefaultRoute.prototype), 'constructor', this).apply(this, arguments); } - _inherits(DefaultRoute, _Route); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 return DefaultRoute; })(Route); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - DefaultRoute.propTypes = { name: PropTypes.string, path: PropTypes.falsy, diff --git a/build/lib/components/Link.js b/build/lib/components/Link.js index fdda8f6e4f..0682fb0992 100644 --- a/build/lib/components/Link.js +++ b/build/lib/components/Link.js @@ -1,10 +1,12 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var React = require('react'); var assign = require('react/lib/Object.assign'); @@ -38,15 +40,17 @@ function isModifiedEvent(event) { */ var Link = (function (_React$Component) { + _inherits(Link, _React$Component); + function Link() { _classCallCheck(this, Link); - if (_React$Component != null) { - _React$Component.apply(this, arguments); - } + _get(Object.getPrototypeOf(Link.prototype), 'constructor', this).apply(this, arguments); } - _inherits(Link, _React$Component); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 _createClass(Link, [{ key: 'handleClick', @@ -56,30 +60,30 @@ var Link = (function (_React$Component) { if (this.props.onClick) clickResult = this.props.onClick(event); - if (isModifiedEvent(event) || !isLeftClickEvent(event)) { - return; - }if (clickResult === false || event.defaultPrevented === true) allowTransition = false; + if (isModifiedEvent(event) || !isLeftClickEvent(event)) return; + + if (clickResult === false || event.defaultPrevented === true) allowTransition = false; event.preventDefault(); if (allowTransition) this.context.router.transitionTo(this.props.to, this.props.params, this.props.query); } - }, { - key: 'getHref', /** * Returns the value of the "href" attribute to use on the DOM element. */ + }, { + key: 'getHref', value: function getHref() { return this.context.router.makeHref(this.props.to, this.props.params, this.props.query); } - }, { - key: 'getClassName', /** * Returns the value of the "class" attribute to use on the DOM element, which contains * the value of the activeClassName property when this is active. */ + }, { + key: 'getClassName', value: function getClassName() { var className = this.props.className; @@ -110,10 +114,6 @@ var Link = (function (_React$Component) { return Link; })(React.Component); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - Link.contextTypes = { router: PropTypes.router.isRequired }; diff --git a/build/lib/components/NotFoundRoute.js b/build/lib/components/NotFoundRoute.js index a0d00f3a42..ce395a51aa 100644 --- a/build/lib/components/NotFoundRoute.js +++ b/build/lib/components/NotFoundRoute.js @@ -1,8 +1,10 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var PropTypes = require('../PropTypes'); var RouteHandler = require('./RouteHandler'); @@ -17,23 +19,21 @@ var Route = require('./Route'); */ var NotFoundRoute = (function (_Route) { + _inherits(NotFoundRoute, _Route); + function NotFoundRoute() { _classCallCheck(this, NotFoundRoute); - if (_Route != null) { - _Route.apply(this, arguments); - } + _get(Object.getPrototypeOf(NotFoundRoute.prototype), 'constructor', this).apply(this, arguments); } - _inherits(NotFoundRoute, _Route); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 return NotFoundRoute; })(Route); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - NotFoundRoute.propTypes = { name: PropTypes.string, path: PropTypes.falsy, diff --git a/build/lib/components/Redirect.js b/build/lib/components/Redirect.js index 0e7cebb9b5..db39b8e348 100644 --- a/build/lib/components/Redirect.js +++ b/build/lib/components/Redirect.js @@ -1,8 +1,10 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var PropTypes = require('../PropTypes'); var Route = require('./Route'); @@ -13,23 +15,21 @@ var Route = require('./Route'); */ var Redirect = (function (_Route) { + _inherits(Redirect, _Route); + function Redirect() { _classCallCheck(this, Redirect); - if (_Route != null) { - _Route.apply(this, arguments); - } + _get(Object.getPrototypeOf(Redirect.prototype), 'constructor', this).apply(this, arguments); } - _inherits(Redirect, _Route); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 return Redirect; })(Route); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - Redirect.propTypes = { path: PropTypes.string, from: PropTypes.string, // Alias for path. diff --git a/build/lib/components/Route.js b/build/lib/components/Route.js index 19664f1644..a6b28f57db 100644 --- a/build/lib/components/Route.js +++ b/build/lib/components/Route.js @@ -1,13 +1,15 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var React = require('react'); -var invariant = require('react/lib/invariant'); +var invariant = require('invariant'); var PropTypes = require('../PropTypes'); var RouteHandler = require('./RouteHandler'); @@ -33,7 +35,7 @@ var RouteHandler = require('./RouteHandler'); * ]; * * Router.run(routes, function (Handler) { - * React.render(, document.body); + * ReactDOM.render(, document.body); * }); * * Handlers for Route components that contain children can render their active @@ -42,7 +44,7 @@ var RouteHandler = require('./RouteHandler'); * var App = React.createClass({ * render: function () { * return ( - *
+ *
* *
* ); @@ -53,15 +55,17 @@ var RouteHandler = require('./RouteHandler'); */ var Route = (function (_React$Component) { + _inherits(Route, _React$Component); + function Route() { _classCallCheck(this, Route); - if (_React$Component != null) { - _React$Component.apply(this, arguments); - } + _get(Object.getPrototypeOf(Route.prototype), 'constructor', this).apply(this, arguments); } - _inherits(Route, _React$Component); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 _createClass(Route, [{ key: 'render', @@ -73,10 +77,6 @@ var Route = (function (_React$Component) { return Route; })(React.Component); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - Route.propTypes = { name: PropTypes.string, path: PropTypes.string, diff --git a/build/lib/components/RouteHandler.js b/build/lib/components/RouteHandler.js index 13844bece0..d3d3d38dc2 100644 --- a/build/lib/components/RouteHandler.js +++ b/build/lib/components/RouteHandler.js @@ -1,10 +1,12 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var React = require('react'); var ContextWrapper = require('./ContextWrapper'); @@ -19,15 +21,17 @@ var REF_NAME = '__routeHandler__'; */ var RouteHandler = (function (_React$Component) { + _inherits(RouteHandler, _React$Component); + function RouteHandler() { _classCallCheck(this, RouteHandler); - if (_React$Component != null) { - _React$Component.apply(this, arguments); - } + _get(Object.getPrototypeOf(RouteHandler.prototype), 'constructor', this).apply(this, arguments); } - _inherits(RouteHandler, _React$Component); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 _createClass(RouteHandler, [{ key: 'getChildContext', @@ -66,9 +70,9 @@ var RouteHandler = (function (_React$Component) { value: function createChildRouteHandler(props) { var route = this.context.router.getRouteAtDepth(this.getRouteDepth()); - if (route == null) { - return null; - }var childProps = assign({}, props || this.props, { + if (route == null) return null; + + var childProps = assign({}, props || this.props, { ref: REF_NAME, params: this.context.router.getCurrentParams(), query: this.context.router.getCurrentQuery() @@ -92,10 +96,6 @@ var RouteHandler = (function (_React$Component) { return RouteHandler; })(React.Component); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - RouteHandler.contextTypes = { routeDepth: PropTypes.number.isRequired, router: PropTypes.router.isRequired diff --git a/build/lib/createRouter.js b/build/lib/createRouter.js index 83216a752c..3043b51630 100644 --- a/build/lib/createRouter.js +++ b/build/lib/createRouter.js @@ -2,9 +2,9 @@ 'use strict'; var React = require('react'); -var warning = require('react/lib/warning'); -var invariant = require('react/lib/invariant'); -var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM; +var warning = require('warning'); +var invariant = require('invariant'); +var canUseDOM = require('exenv').canUseDOM; var LocationActions = require('./actions/LocationActions'); var ImitateBrowserBehavior = require('./behaviors/ImitateBrowserBehavior'); var HashLocation = require('./locations/HashLocation'); @@ -35,9 +35,9 @@ var DEFAULT_LOCATION = canUseDOM ? HashLocation : '/'; var DEFAULT_SCROLL_BEHAVIOR = canUseDOM ? ImitateBrowserBehavior : null; function hasProperties(object, properties) { - for (var propertyName in properties) if (properties.hasOwnProperty(propertyName) && object[propertyName] !== properties[propertyName]) { - return false; - }return true; + for (var propertyName in properties) if (properties.hasOwnProperty(propertyName) && object[propertyName] !== properties[propertyName]) return false; + + return true; } function hasMatch(routes, route, prevParams, nextParams, prevQuery, nextQuery) { @@ -81,15 +81,15 @@ function routeIsActive(activeRoutes, routeName) { } function paramsAreActive(activeParams, params) { - for (var property in params) if (String(activeParams[property]) !== String(params[property])) { - return false; - }return true; + for (var property in params) if (String(activeParams[property]) !== String(params[property])) return false; + + return true; } function queryIsActive(activeQuery, query) { - for (var property in query) if (String(activeQuery[property]) !== String(query[property])) { - return false; - }return true; + for (var property in query) if (String(activeQuery[property]) !== String(query[property])) return false; + + return true; } /** @@ -301,9 +301,7 @@ function createRouter(options) { var prevPath = state.path; var isRefreshing = action == null; - if (prevPath === path && !isRefreshing) { - return; - } // Nothing to do! + if (prevPath === path && !isRefreshing) return; // Nothing to do! // Record the scroll position as early as possible to // get it before browsers try update it automatically. @@ -460,9 +458,9 @@ function createRouter(options) { * Returns true if the given route, params, and query are active. */ isActive: function isActive(to, params, query) { - if (PathUtils.isAbsolute(to)) { - return to === state.path; - }return routeIsActive(state.routes, to) && paramsAreActive(state.params, params) && (query == null || queryIsActive(state.query, query)); + if (PathUtils.isAbsolute(to)) return to === state.path; + + return routeIsActive(state.routes, to) && paramsAreActive(state.params, params) && (query == null || queryIsActive(state.query, query)); } }, diff --git a/build/lib/createRoutesFromReactChildren.js b/build/lib/createRoutesFromReactChildren.js index 8abf8d3b83..aed8c2d597 100644 --- a/build/lib/createRoutesFromReactChildren.js +++ b/build/lib/createRoutesFromReactChildren.js @@ -3,7 +3,7 @@ var React = require('react'); var assign = require('react/lib/Object.assign'); -var warning = require('react/lib/warning'); +var warning = require('warning'); var DefaultRoute = require('./components/DefaultRoute'); var NotFoundRoute = require('./components/NotFoundRoute'); var Redirect = require('./components/Redirect'); @@ -34,20 +34,20 @@ function createRouteOptions(props) { } function createRouteFromReactElement(element) { - if (!React.isValidElement(element)) { - return; - }var type = element.type; + if (!React.isValidElement(element)) return; + + var type = element.type; var props = assign({}, type.defaultProps, element.props); if (type.propTypes) checkPropTypes(type.displayName, type.propTypes, props); - if (type === DefaultRoute) { - return Route.createDefaultRoute(createRouteOptions(props)); - }if (type === NotFoundRoute) { - return Route.createNotFoundRoute(createRouteOptions(props)); - }if (type === Redirect) { - return Route.createRedirect(createRouteOptions(props)); - }return Route.createRoute(createRouteOptions(props), function () { + if (type === DefaultRoute) return Route.createDefaultRoute(createRouteOptions(props)); + + if (type === NotFoundRoute) return Route.createNotFoundRoute(createRouteOptions(props)); + + if (type === Redirect) return Route.createRedirect(createRouteOptions(props)); + + return Route.createRoute(createRouteOptions(props), function () { if (props.children) createRoutesFromReactChildren(props.children); }); } diff --git a/build/lib/getWindowScrollPosition.js b/build/lib/getWindowScrollPosition.js index 10b07050eb..222c7f4cb7 100644 --- a/build/lib/getWindowScrollPosition.js +++ b/build/lib/getWindowScrollPosition.js @@ -1,7 +1,7 @@ 'use strict'; -var invariant = require('react/lib/invariant'); -var canUseDOM = require('react/lib/ExecutionEnvironment').canUseDOM; +var invariant = require('invariant'); +var canUseDOM = require('exenv').canUseDOM; /** * Returns the current scroll position of the window as { x, y }. diff --git a/build/lib/locations/HashLocation.js b/build/lib/locations/HashLocation.js index 26067da8ce..9cbf68b0b6 100644 --- a/build/lib/locations/HashLocation.js +++ b/build/lib/locations/HashLocation.js @@ -23,9 +23,9 @@ function notifyChange(type) { function ensureSlash() { var path = HashLocation.getCurrentPath(); - if (path.charAt(0) === '/') { - return true; - }HashLocation.replace('/' + path); + if (path.charAt(0) === '/') return true; + + HashLocation.replace('/' + path); return false; } diff --git a/build/lib/locations/HistoryLocation.js b/build/lib/locations/HistoryLocation.js index 5054461236..73f3648bf5 100644 --- a/build/lib/locations/HistoryLocation.js +++ b/build/lib/locations/HistoryLocation.js @@ -18,9 +18,7 @@ function notifyChange(type) { } function onPopState(event) { - if (event.state === undefined) { - return; - } // Ignore extraneous popstate events in WebKit. + if (event.state === undefined) return; // Ignore extraneous popstate events in WebKit. notifyChange(LocationActions.POP); } diff --git a/build/lib/locations/StaticLocation.js b/build/lib/locations/StaticLocation.js index e2e14dcb0b..c018d5158a 100644 --- a/build/lib/locations/StaticLocation.js +++ b/build/lib/locations/StaticLocation.js @@ -1,10 +1,10 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var invariant = require('react/lib/invariant'); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +var invariant = require('invariant'); function throwCannotModify() { invariant(false, 'You cannot modify a static location'); @@ -23,6 +23,10 @@ var StaticLocation = (function () { this.path = path; } + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 + _createClass(StaticLocation, [{ key: 'getCurrentPath', value: function getCurrentPath() { @@ -38,10 +42,6 @@ var StaticLocation = (function () { return StaticLocation; })(); -// TODO: Include these in the above class definition -// once we can use ES7 property initializers. -// https://github.com/babel/babel/issues/619 - StaticLocation.prototype.push = throwCannotModify; StaticLocation.prototype.replace = throwCannotModify; StaticLocation.prototype.pop = throwCannotModify; diff --git a/build/lib/locations/TestLocation.js b/build/lib/locations/TestLocation.js index bb02b189da..8a76a43c34 100644 --- a/build/lib/locations/TestLocation.js +++ b/build/lib/locations/TestLocation.js @@ -1,10 +1,10 @@ 'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var invariant = require('react/lib/invariant'); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +var invariant = require('invariant'); var LocationActions = require('../actions/LocationActions'); var History = require('../History'); @@ -18,15 +18,11 @@ var TestLocation = (function () { this.history = history || []; this.listeners = []; + this.needsDOM = false; this._updateHistoryLength(); } _createClass(TestLocation, [{ - key: 'needsDOM', - get: function () { - return false; - } - }, { key: '_updateHistoryLength', value: function _updateHistoryLength() { History.length = this.history.length; diff --git a/build/lib/runRouter.js b/build/lib/runRouter.js index 2fac435aa4..1807f6c843 100644 --- a/build/lib/runRouter.js +++ b/build/lib/runRouter.js @@ -11,13 +11,13 @@ var createRouter = require('./createRouter'); * Using `window.location.hash` to manage the URL, you could do: * * Router.run(routes, function (Handler) { - * React.render(, document.body); + * ReactDOM.render(, document.body); * }); * * Using HTML5 history and a custom "cursor" prop: * * Router.run(routes, Router.HistoryLocation, function (Handler) { - * React.render(, document.body); + * ReactDOM.render(, document.body); * }); * * Returns the newly created router. diff --git a/build/package.json b/build/package.json index 9bcba73681..4229b1da81 100644 --- a/build/package.json +++ b/build/package.json @@ -1,25 +1,29 @@ { - "name": "react-router", - "version": "0.13.3", + "name": "react-router-old", + "version": "0.13.4", "description": "A complete routing library for React.js", "main": "lib", "repository": { "type": "git", - "url": "https://github.com/rackt/react-router.git" + "url": "https://github.com/nkt/react-router-old.git" }, - "homepage": "https://github.com/rackt/react-router/blob/latest/README.md", - "bugs": "https://github.com/rackt/react-router/issues", + "homepage": "https://github.com/nkt/react-router-old/blob/latest/README.md", + "bugs": "https://github.com/nkt/react-router-old/issues", "authors": [ "Ryan Florence", "Michael Jackson" ], "license": "MIT", "peerDependencies": { - "react": "0.13.x" + "react": "0.14.x", + "react-dom": "0.14.x" }, "dependencies": { + "exenv": "^1.2.0", + "invariant": "^2.1.1", "object-assign": "^2.0.0", - "qs": "2.4.1" + "qs": "2.4.1", + "warning": "^2.1.0" }, "tags": [ "react", diff --git a/build/umd/ReactRouter.js b/build/umd/ReactRouter.js index 81b830787c..580ab370e8 100644 --- a/build/umd/ReactRouter.js +++ b/build/umd/ReactRouter.js @@ -7,45 +7,45 @@ exports["ReactRouter"] = factory(require("react")); else root["ReactRouter"] = factory(root["React"]); -})(this, function(__WEBPACK_EXTERNAL_MODULE_21__) { +})(this, function(__WEBPACK_EXTERNAL_MODULE_4__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; -/******/ + /******/ // The require function /******/ function __webpack_require__(moduleId) { -/******/ + /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; -/******/ + /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; -/******/ + /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ + /******/ // Flag the module as loaded /******/ module.loaded = true; -/******/ + /******/ // Return the exports of the module /******/ return module.exports; /******/ } -/******/ -/******/ + + /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; -/******/ + /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; -/******/ + /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; -/******/ + /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) @@ -57,34 +57,34 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; exports.DefaultRoute = __webpack_require__(1); - exports.Link = __webpack_require__(2); - exports.NotFoundRoute = __webpack_require__(3); - exports.Redirect = __webpack_require__(4); - exports.Route = __webpack_require__(5); - exports.ActiveHandler = __webpack_require__(6); + exports.Link = __webpack_require__(18); + exports.NotFoundRoute = __webpack_require__(19); + exports.Redirect = __webpack_require__(20); + exports.Route = __webpack_require__(17); + exports.ActiveHandler = __webpack_require__(15); exports.RouteHandler = exports.ActiveHandler; - exports.HashLocation = __webpack_require__(7); - exports.HistoryLocation = __webpack_require__(8); - exports.RefreshLocation = __webpack_require__(9); - exports.StaticLocation = __webpack_require__(10); - exports.TestLocation = __webpack_require__(11); + exports.HashLocation = __webpack_require__(21); + exports.HistoryLocation = __webpack_require__(25); + exports.RefreshLocation = __webpack_require__(26); + exports.StaticLocation = __webpack_require__(27); + exports.TestLocation = __webpack_require__(28); - exports.ImitateBrowserBehavior = __webpack_require__(12); - exports.ScrollToTopBehavior = __webpack_require__(13); + exports.ImitateBrowserBehavior = __webpack_require__(29); + exports.ScrollToTopBehavior = __webpack_require__(30); - exports.History = __webpack_require__(14); - exports.Navigation = __webpack_require__(15); - exports.State = __webpack_require__(16); + exports.History = __webpack_require__(23); + exports.Navigation = __webpack_require__(31); + exports.State = __webpack_require__(32); - exports.createRoute = __webpack_require__(17).createRoute; - exports.createDefaultRoute = __webpack_require__(17).createDefaultRoute; - exports.createNotFoundRoute = __webpack_require__(17).createNotFoundRoute; - exports.createRedirect = __webpack_require__(17).createRedirect; - exports.createRoutesFromReactChildren = __webpack_require__(18); + exports.createRoute = __webpack_require__(5).createRoute; + exports.createDefaultRoute = __webpack_require__(5).createDefaultRoute; + exports.createNotFoundRoute = __webpack_require__(5).createNotFoundRoute; + exports.createRedirect = __webpack_require__(5).createRedirect; + exports.createRoutesFromReactChildren = __webpack_require__(33); - exports.create = __webpack_require__(19); - exports.run = __webpack_require__(20); + exports.create = __webpack_require__(34); + exports.run = __webpack_require__(43); /***/ }, /* 1 */ @@ -92,13 +92,15 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; + var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - var PropTypes = __webpack_require__(22); - var RouteHandler = __webpack_require__(6); - var Route = __webpack_require__(5); + function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + var PropTypes = __webpack_require__(2); + var RouteHandler = __webpack_require__(15); + var Route = __webpack_require__(17); /** * A component is a special kind of that @@ -108,23 +110,21 @@ return /******/ (function(modules) { // webpackBootstrap */ var DefaultRoute = (function (_Route) { + _inherits(DefaultRoute, _Route); + function DefaultRoute() { _classCallCheck(this, DefaultRoute); - if (_Route != null) { - _Route.apply(this, arguments); - } + _get(Object.getPrototypeOf(DefaultRoute.prototype), 'constructor', this).apply(this, arguments); } - _inherits(DefaultRoute, _Route); + // TODO: Include these in the above class definition + // once we can use ES7 property initializers. + // https://github.com/babel/babel/issues/619 return DefaultRoute; })(Route); - // TODO: Include these in the above class definition - // once we can use ES7 property initializers. - // https://github.com/babel/babel/issues/619 - DefaultRoute.propTypes = { name: PropTypes.string, path: PropTypes.falsy, @@ -144,2435 +144,2040 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; + var assign = __webpack_require__(3); + var ReactPropTypes = __webpack_require__(4).PropTypes; + var Route = __webpack_require__(5); - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + var PropTypes = assign({}, ReactPropTypes, { - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + /** + * Indicates that a prop should be falsy. + */ + falsy: function falsy(props, propName, componentName) { + if (props[propName]) return new Error('<' + componentName + '> should not have a "' + propName + '" prop'); + }, - var React = __webpack_require__(21); - var assign = __webpack_require__(33); - var PropTypes = __webpack_require__(22); + /** + * Indicates that a prop should be a Route object. + */ + route: ReactPropTypes.instanceOf(Route), - function isLeftClickEvent(event) { - return event.button === 0; - } + /** + * Indicates that a prop should be a Router object. + */ + //router: ReactPropTypes.instanceOf(Router) // TODO + router: ReactPropTypes.func - function isModifiedEvent(event) { - return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); - } + }); + + module.exports = PropTypes; + +/***/ }, +/* 3 */ +/***/ function(module, exports) { /** - * components are used to create an element that links to a route. - * When that route is active, the link gets an "active" class name (or the - * value of its `activeClassName` prop). - * - * For example, assuming you have the following route: - * - * - * - * You could use the following component to link to that route: - * - * + * Copyright 2014-2015, Facebook, Inc. + * All rights reserved. * - * In addition to params, links may pass along query string parameters - * using the `query` prop. + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. * - * + * @providesModule Object.assign */ - var Link = (function (_React$Component) { - function Link() { - _classCallCheck(this, Link); - - if (_React$Component != null) { - _React$Component.apply(this, arguments); - } - } - - _inherits(Link, _React$Component); - - _createClass(Link, [{ - key: 'handleClick', - value: function handleClick(event) { - var allowTransition = true; - var clickResult; - - if (this.props.onClick) clickResult = this.props.onClick(event); + // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign - if (isModifiedEvent(event) || !isLeftClickEvent(event)) { - return; - }if (clickResult === false || event.defaultPrevented === true) allowTransition = false; + 'use strict'; - event.preventDefault(); + function assign(target, sources) { + if (target == null) { + throw new TypeError('Object.assign target cannot be null or undefined'); + } - if (allowTransition) this.context.router.transitionTo(this.props.to, this.props.params, this.props.query); - } - }, { - key: 'getHref', + var to = Object(target); + var hasOwnProperty = Object.prototype.hasOwnProperty; - /** - * Returns the value of the "href" attribute to use on the DOM element. - */ - value: function getHref() { - return this.context.router.makeHref(this.props.to, this.props.params, this.props.query); + for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) { + var nextSource = arguments[nextIndex]; + if (nextSource == null) { + continue; } - }, { - key: 'getClassName', - - /** - * Returns the value of the "class" attribute to use on the DOM element, which contains - * the value of the activeClassName property when this is active. - */ - value: function getClassName() { - var className = this.props.className; - if (this.getActiveState()) className += ' ' + this.props.activeClassName; - - return className; - } - }, { - key: 'getActiveState', - value: function getActiveState() { - return this.context.router.isActive(this.props.to, this.props.params, this.props.query); - } - }, { - key: 'render', - value: function render() { - var props = assign({}, this.props, { - href: this.getHref(), - className: this.getClassName(), - onClick: this.handleClick.bind(this) - }); + var from = Object(nextSource); - if (props.activeStyle && this.getActiveState()) props.style = props.activeStyle; + // We don't currently support accessors nor proxies. Therefore this + // copy cannot throw. If we ever supported this then we must handle + // exceptions and side-effects. We don't support symbols so they won't + // be transferred. - return React.DOM.a(props, this.props.children); + for (var key in from) { + if (hasOwnProperty.call(from, key)) { + to[key] = from[key]; + } } - }]); - - return Link; - })(React.Component); - - // TODO: Include these in the above class definition - // once we can use ES7 property initializers. - // https://github.com/babel/babel/issues/619 + } - Link.contextTypes = { - router: PropTypes.router.isRequired - }; + return to; + } - Link.propTypes = { - activeClassName: PropTypes.string.isRequired, - to: PropTypes.oneOfType([PropTypes.string, PropTypes.route]).isRequired, - params: PropTypes.object, - query: PropTypes.object, - activeStyle: PropTypes.object, - onClick: PropTypes.func - }; + module.exports = assign; - Link.defaultProps = { - activeClassName: 'active', - className: '' - }; +/***/ }, +/* 4 */ +/***/ function(module, exports) { - module.exports = Link; + module.exports = __WEBPACK_EXTERNAL_MODULE_4__; /***/ }, -/* 3 */ +/* 5 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; - - var PropTypes = __webpack_require__(22); - var RouteHandler = __webpack_require__(6); - var Route = __webpack_require__(5); - - /** - * A is a special kind of that - * renders when the beginning of its parent's path matches - * but none of its siblings do, including any . - * Only one such route may be used at any given level in the - * route hierarchy. - */ + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - var NotFoundRoute = (function (_Route) { - function NotFoundRoute() { - _classCallCheck(this, NotFoundRoute); + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - if (_Route != null) { - _Route.apply(this, arguments); - } - } + var assign = __webpack_require__(3); + var invariant = __webpack_require__(6); + var warning = __webpack_require__(7); + var PathUtils = __webpack_require__(8); - _inherits(NotFoundRoute, _Route); + var _currentRoute; - return NotFoundRoute; - })(Route); + var Route = (function () { + _createClass(Route, null, [{ + key: 'createRoute', - // TODO: Include these in the above class definition - // once we can use ES7 property initializers. - // https://github.com/babel/babel/issues/619 + /** + * Creates and returns a new route. Options may be a URL pathname string + * with placeholders for named params or an object with any of the following + * properties: + * + * - name The name of the route. This is used to lookup a + * route relative to its parent route and should be + * unique among all child routes of the same parent + * - path A URL pathname string with optional placeholders + * that specify the names of params to extract from + * the URL when the path matches. Defaults to `/${name}` + * when there is a name given, or the path of the parent + * route, or / + * - ignoreScrollBehavior True to make this route (and all descendants) ignore + * the scroll behavior of the router + * - isDefault True to make this route the default route among all + * its siblings + * - isNotFound True to make this route the "not found" route among + * all its siblings + * - onEnter A transition hook that will be called when the + * router is going to enter this route + * - onLeave A transition hook that will be called when the + * router is going to leave this route + * - handler A React component that will be rendered when + * this route is active + * - parentRoute The parent route to use for this route. This option + * is automatically supplied when creating routes inside + * the callback to another invocation of createRoute. You + * only ever need to use this when declaring routes + * independently of one another to manually piece together + * the route hierarchy + * + * The callback may be used to structure your route hierarchy. Any call to + * createRoute, createDefaultRoute, createNotFoundRoute, or createRedirect + * inside the callback automatically uses this route as its parent. + */ + value: function createRoute(options, callback) { + options = options || {}; - NotFoundRoute.propTypes = { - name: PropTypes.string, - path: PropTypes.falsy, - children: PropTypes.falsy, - handler: PropTypes.func.isRequired - }; + if (typeof options === 'string') options = { path: options }; - NotFoundRoute.defaultProps = { - handler: RouteHandler - }; + var parentRoute = _currentRoute; - module.exports = NotFoundRoute; + if (parentRoute) { + warning(options.parentRoute == null || options.parentRoute === parentRoute, 'You should not use parentRoute with createRoute inside another route\'s child callback; it is ignored'); + } else { + parentRoute = options.parentRoute; + } -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { + var name = options.name; + var path = options.path || name; - 'use strict'; + if (path && !(options.isDefault || options.isNotFound)) { + if (PathUtils.isAbsolute(path)) { + if (parentRoute) { + invariant(path === parentRoute.path || parentRoute.paramNames.length === 0, 'You cannot nest path "%s" inside "%s"; the parent requires URL parameters', path, parentRoute.path); + } + } else if (parentRoute) { + // Relative paths extend their parent. + path = PathUtils.join(parentRoute.path, path); + } else { + path = '/' + path; + } + } else { + path = parentRoute ? parentRoute.path : '/'; + } - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; + if (options.isNotFound && !/\*$/.test(path)) path += '*'; // Auto-append * to the path of not found routes. - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + var route = new Route(name, path, options.ignoreScrollBehavior, options.isDefault, options.isNotFound, options.onEnter, options.onLeave, options.handler); - var PropTypes = __webpack_require__(22); - var Route = __webpack_require__(5); + if (parentRoute) { + if (route.isDefault) { + invariant(parentRoute.defaultRoute == null, '%s may not have more than one default route', parentRoute); - /** - * A component is a special kind of that always - * redirects to another route when it matches. - */ + parentRoute.defaultRoute = route; + } else if (route.isNotFound) { + invariant(parentRoute.notFoundRoute == null, '%s may not have more than one not found route', parentRoute); - var Redirect = (function (_Route) { - function Redirect() { - _classCallCheck(this, Redirect); + parentRoute.notFoundRoute = route; + } + + parentRoute.appendChild(route); + } + + // Any routes created in the callback + // use this route as their parent. + if (typeof callback === 'function') { + var currentRoute = _currentRoute; + _currentRoute = route; + callback.call(route, route); + _currentRoute = currentRoute; + } - if (_Route != null) { - _Route.apply(this, arguments); + return route; } - } - _inherits(Redirect, _Route); + /** + * Creates and returns a route that is rendered when its parent matches + * the current URL. + */ + }, { + key: 'createDefaultRoute', + value: function createDefaultRoute(options) { + return Route.createRoute(assign({}, options, { isDefault: true })); + } - return Redirect; - })(Route); + /** + * Creates and returns a route that is rendered when its parent matches + * the current URL but none of its siblings do. + */ + }, { + key: 'createNotFoundRoute', + value: function createNotFoundRoute(options) { + return Route.createRoute(assign({}, options, { isNotFound: true })); + } - // TODO: Include these in the above class definition - // once we can use ES7 property initializers. - // https://github.com/babel/babel/issues/619 + /** + * Creates and returns a route that automatically redirects the transition + * to another route. In addition to the normal options to createRoute, this + * function accepts the following options: + * + * - from An alias for the `path` option. Defaults to * + * - to The path/route/route name to redirect to + * - params The params to use in the redirect URL. Defaults + * to using the current params + * - query The query to use in the redirect URL. Defaults + * to using the current query + */ + }, { + key: 'createRedirect', + value: function createRedirect(options) { + return Route.createRoute(assign({}, options, { + path: options.path || options.from || '*', + onEnter: function onEnter(transition, params, query) { + transition.redirect(options.to, options.params || params, options.query || query); + } + })); + } + }]); - Redirect.propTypes = { - path: PropTypes.string, - from: PropTypes.string, // Alias for path. - to: PropTypes.string, - handler: PropTypes.falsy - }; + function Route(name, path, ignoreScrollBehavior, isDefault, isNotFound, onEnter, onLeave, handler) { + _classCallCheck(this, Route); - // Redirects should not have a default handler - Redirect.defaultProps = {}; + this.name = name; + this.path = path; + this.paramNames = PathUtils.extractParamNames(this.path); + this.ignoreScrollBehavior = !!ignoreScrollBehavior; + this.isDefault = !!isDefault; + this.isNotFound = !!isNotFound; + this.onEnter = onEnter; + this.onLeave = onLeave; + this.handler = handler; + } - module.exports = Redirect; + /** + * Appends the given route to this route's child routes. + */ -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { + _createClass(Route, [{ + key: 'appendChild', + value: function appendChild(route) { + invariant(route instanceof Route, 'route.appendChild must use a valid Route'); - 'use strict'; + if (!this.childRoutes) this.childRoutes = []; + + this.childRoutes.push(route); + } + }, { + key: 'toString', + value: function toString() { + var string = ''; + + return string; + } + }]); + + return Route; + })(); - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + module.exports = Route; - var React = __webpack_require__(21); - var invariant = __webpack_require__(34); - var PropTypes = __webpack_require__(22); - var RouteHandler = __webpack_require__(6); +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { /** - * components specify components that are rendered to the page when the - * URL matches a given pattern. - * - * Routes are arranged in a nested tree structure. When a new URL is requested, - * the tree is searched depth-first to find a route whose path matches the URL. - * When one is found, all routes in the tree that lead to it are considered - * "active" and their components are rendered into the DOM, nested in the same - * order as they are in the tree. - * - * The preferred way to configure a router is using JSX. The XML-like syntax is - * a great way to visualize how routes are laid out in an application. + * Copyright 2013-2015, Facebook, Inc. + * All rights reserved. * - * var routes = [ - * - * - * - * - * - * ]; - * - * Router.run(routes, function (Handler) { - * React.render(, document.body); - * }); + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. * - * Handlers for Route components that contain children can render their active - * child route using a element. + * @providesModule invariant + */ + + 'use strict'; + + /** + * Use invariant() to assert state which your program assumes to be true. * - * var App = React.createClass({ - * render: function () { - * return ( - *
- * - *
- * ); - * } - * }); + * Provide sprintf-style format (only %s is supported) and arguments + * to provide information about what broke and what you were + * expecting. * - * If no handler is provided for the route, it will render a matched child route. + * The invariant message will be stripped in production, but the invariant + * will remain to ensure logic does not differ in production. */ - var Route = (function (_React$Component) { - function Route() { - _classCallCheck(this, Route); - - if (_React$Component != null) { - _React$Component.apply(this, arguments); + var invariant = function invariant(condition, format, a, b, c, d, e, f) { + if (false) { + if (format === undefined) { + throw new Error('invariant requires an error message argument'); } } - _inherits(Route, _React$Component); - - _createClass(Route, [{ - key: 'render', - value: function render() { - invariant(false, '%s elements are for router configuration only and should not be rendered', this.constructor.name); + if (!condition) { + var error; + if (format === undefined) { + error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error('Invariant Violation: ' + format.replace(/%s/g, function () { + return args[argIndex++]; + })); } - }]); - - return Route; - })(React.Component); - - // TODO: Include these in the above class definition - // once we can use ES7 property initializers. - // https://github.com/babel/babel/issues/619 - - Route.propTypes = { - name: PropTypes.string, - path: PropTypes.string, - handler: PropTypes.func, - ignoreScrollBehavior: PropTypes.bool - }; - Route.defaultProps = { - handler: RouteHandler + error.framesToPop = 1; // we don't care about invariant's own frame + throw error; + } }; - module.exports = Route; + module.exports = invariant; /***/ }, -/* 6 */ +/* 7 */ /***/ function(module, exports, __webpack_require__) { - 'use strict'; + /** + * Copyright 2014-2015, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; + 'use strict'; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + /** + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + var warning = function warning() {}; - var React = __webpack_require__(21); - var ContextWrapper = __webpack_require__(23); - var assign = __webpack_require__(33); - var PropTypes = __webpack_require__(22); + if (false) { + warning = function (condition, format, args) { + var len = arguments.length; + args = new Array(len > 2 ? len - 2 : 0); + for (var key = 2; key < len; key++) { + args[key - 2] = arguments[key]; + } + if (format === undefined) { + throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); + } - var REF_NAME = '__routeHandler__'; - - /** - * A component renders the active child route handler - * when routes are nested. - */ - - var RouteHandler = (function (_React$Component) { - function RouteHandler() { - _classCallCheck(this, RouteHandler); + if (format.length < 10 || /^[s\W]*$/.test(format)) { + throw new Error('The warning format should be able to uniquely identify this ' + 'warning. Please, use a more descriptive format than: ' + format); + } - if (_React$Component != null) { - _React$Component.apply(this, arguments); + if (!condition) { + var argIndex = 0; + var message = 'Warning: ' + format.replace(/%s/g, function () { + return args[argIndex++]; + }); + if (typeof console !== 'undefined') { + console.error(message); + } + try { + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} } - } + }; + } - _inherits(RouteHandler, _React$Component); + module.exports = warning; - _createClass(RouteHandler, [{ - key: 'getChildContext', - value: function getChildContext() { - return { - routeDepth: this.context.routeDepth + 1 - }; - } - }, { - key: 'componentDidMount', - value: function componentDidMount() { - this._updateRouteComponent(this.refs[REF_NAME]); - } - }, { - key: 'componentDidUpdate', - value: function componentDidUpdate() { - this._updateRouteComponent(this.refs[REF_NAME]); - } - }, { - key: 'componentWillUnmount', - value: function componentWillUnmount() { - this._updateRouteComponent(null); - } - }, { - key: '_updateRouteComponent', - value: function _updateRouteComponent(component) { - this.context.router.setRouteComponentAtDepth(this.getRouteDepth(), component); - } - }, { - key: 'getRouteDepth', - value: function getRouteDepth() { - return this.context.routeDepth; - } - }, { - key: 'createChildRouteHandler', - value: function createChildRouteHandler(props) { - var route = this.context.router.getRouteAtDepth(this.getRouteDepth()); +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { - if (route == null) { - return null; - }var childProps = assign({}, props || this.props, { - ref: REF_NAME, - params: this.context.router.getCurrentParams(), - query: this.context.router.getCurrentQuery() - }); + 'use strict'; - return React.createElement(route.handler, childProps); - } - }, { - key: 'render', - value: function render() { - var handler = this.createChildRouteHandler(); - // +
diff --git a/website/scripts/build.js b/website/scripts/build.js index 85d8daa6b6..ae6f28865f 100755 --- a/website/scripts/build.js +++ b/website/scripts/build.js @@ -80,7 +80,7 @@ class Page extends React.Component { server side rendering.

- Contribute on Github. + Contribute on Github.

{this.props.categories.map((category) => (