Skip to content

Commit

Permalink
Un-deprecate Navigation and State mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Apr 11, 2015
1 parent 06c15c5 commit e5ad53b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
32 changes: 10 additions & 22 deletions modules/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
var warning = require('react/lib/warning');
var PropTypes = require('./PropTypes');

function deprecatedMethod(routerMethodName, fn) {
return function () {
warning(
false,
`Router.Navigation is deprecated. Please use this.context.router.${routerMethodName}() instead`
);

return fn.apply(this, arguments);
};
}

/**
* A mixin for components that modify the URL.
*
Expand Down Expand Up @@ -40,40 +28,40 @@ var Navigation = {
* Returns an absolute URL path created from the given route
* name, URL parameters, and query values.
*/
makePath: deprecatedMethod('makePath', function (to, params, query) {
makePath(to, params, query) {
return this.context.router.makePath(to, params, query);
}),
},

/**
* Returns a string that may safely be used as the href of a
* link to the route with the given name.
*/
makeHref: deprecatedMethod('makeHref', function (to, params, query) {
makeHref(to, params, query) {
return this.context.router.makeHref(to, params, query);
}),
},

/**
* Transitions to the URL specified in the arguments by pushing
* a new URL onto the history stack.
*/
transitionTo: deprecatedMethod('transitionTo', function (to, params, query) {
transitionTo(to, params, query) {
this.context.router.transitionTo(to, params, query);
}),
},

/**
* Transitions to the URL specified in the arguments by replacing
* the current URL in the history stack.
*/
replaceWith: deprecatedMethod('replaceWith', function (to, params, query) {
replaceWith(to, params, query) {
this.context.router.replaceWith(to, params, query);
}),
},

/**
* Transitions to the previous URL.
*/
goBack: deprecatedMethod('goBack', function () {
goBack() {
return this.context.router.goBack();
})
}

};

Expand Down
40 changes: 14 additions & 26 deletions modules/State.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
var warning = require('react/lib/warning');
var PropTypes = require('./PropTypes');

function deprecatedMethod(routerMethodName, fn) {
return function () {
warning(
false,
`Router.State is deprecated. Please use this.context.router.${routerMethodName}() instead`
);

return fn.apply(this, arguments);
};
}

/**
* A mixin for components that need to know the path, routes, URL
* params and query that are currently active.
Expand All @@ -22,10 +10,10 @@ function deprecatedMethod(routerMethodName, fn) {
* mixins: [ Router.State ],
* render() {
* var className = this.props.className;
*
*
* if (this.isActive('about'))
* className += ' is-active';
*
*
* return React.DOM.a({ className: className }, this.props.children);
* }
* });
Expand All @@ -39,45 +27,45 @@ var State = {
/**
* Returns the current URL path.
*/
getPath: deprecatedMethod('getCurrentPath', function () {
getPath() {
return this.context.router.getCurrentPath();
}),
},

/**
* Returns the current URL path without the query string.
*/
getPathname: deprecatedMethod('getCurrentPathname', function () {
getPathname() {
return this.context.router.getCurrentPathname();
}),
},

/**
* Returns an object of the URL params that are currently active.
*/
getParams: deprecatedMethod('getCurrentParams', function () {
getParams() {
return this.context.router.getCurrentParams();
}),
},

/**
* Returns an object of the query params that are currently active.
*/
getQuery: deprecatedMethod('getCurrentQuery', function () {
getQuery() {
return this.context.router.getCurrentQuery();
}),
},

/**
* Returns an array of the routes that are currently active.
*/
getRoutes: deprecatedMethod('getCurrentRoutes', function () {
getRoutes() {
return this.context.router.getCurrentRoutes();
}),
},

/**
* A helper method to determine if a given route, params, and query
* are active.
*/
isActive: deprecatedMethod('isActive', function (to, params, query) {
isActive(to, params, query) {
return this.context.router.isActive(to, params, query);
})
}

};

Expand Down

0 comments on commit e5ad53b

Please sign in to comment.