Skip to content

Commit

Permalink
Update Navigation mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Aug 13, 2015
1 parent 5276d75 commit 7c1edc6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 231 deletions.
6 changes: 3 additions & 3 deletions modules/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var { object } = React.PropTypes;
* mixins: [ Navigation ],
* handleClick(event) {
* event.preventDefault();
* this.transitionTo('aRoute', { the: 'params' }, { the: 'query' });
* this.transitionTo('/the/path', { the: 'query' });
* },
* render() {
* return (
Expand All @@ -31,8 +31,8 @@ var Navigation = {
};

var RouterNavigationMethods = [
'makePath',
'makeHref',
'createPath',
'createHref',
'transitionTo',
'replaceWith',
'go',
Expand Down
24 changes: 24 additions & 0 deletions modules/NavigationMixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
import invariant from 'invariant';
import React from 'react';
import { stringifyQuery } from './QueryUtils';

var { func } = React.PropTypes;

var NavigationMixin = {

propTypes: {
stringifyQuery: func
},

getDefaultProps() {
return {
stringifyQuery
};
},

createPath(pathname, query) {
var { stringifyQuery } = this.props;

var queryString;
if (query == null || (queryString = stringifyQuery(query)) === '')
return pathname;

return pathname + (pathname.indexOf('?') === -1 ? '?' : '&') + queryString;
},

/**
* Returns a string that may safely be used to link to the given
* pathname and query.
Expand Down
9 changes: 9 additions & 0 deletions modules/QueryUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import qs from 'qs';

export function stringifyQuery(query) {
return qs.stringify(query, { arrayFormat: 'brackets' });
}

export function parseQueryString(queryString) {
return qs.parse(queryString);
}
25 changes: 2 additions & 23 deletions modules/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import warning from 'warning';
import invariant from 'invariant';
import { createClass, createElement, isValidElement, PropTypes } from 'react';
import { component, components, history, location, routes } from './PropTypes';
import { parseQueryString } from './QueryUtils';
import { createRoutes } from './RouteUtils';
import matchRoutes from './matchRoutes';
import runTransitionHooks from './runTransitionHooks';
Expand All @@ -14,16 +15,6 @@ import ActiveMixin from './ActiveMixin';

var { arrayOf, func, object } = PropTypes;

import qs from 'qs';

function stringifyQuery(query) {
return qs.stringify(query, { arrayFormat: 'brackets' });
}

function parseQueryString(queryString) {
return qs.parse(queryString);
}

var Router = createClass({

mixins: [ NavigationMixin, ScrollManagementMixin, ActiveMixin ],
Expand Down Expand Up @@ -69,7 +60,6 @@ var Router = createClass({
propTypes: {
createElement: func,
parseQueryString: func,
stringifyQuery: func,
onError: func,
onUpdate: func,
routes,
Expand All @@ -86,8 +76,7 @@ var Router = createClass({
getDefaultProps() {
return {
createElement,
parseQueryString,
stringifyQuery
parseQueryString
};
},

Expand Down Expand Up @@ -177,16 +166,6 @@ var Router = createClass({
this._unlisten();
},

createPath(pathname, query) {
var { stringifyQuery } = this.props;

var queryString;
if (query == null || (queryString = stringifyQuery(query)) === '')
return pathname;

return pathname + (pathname.indexOf('?') === -1 ? '?' : '&') + queryString;
},

createElement(component, props) {
return component ? this.props.createElement(component, props) : null;
},
Expand Down
4 changes: 2 additions & 2 deletions modules/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ var { object } = React.PropTypes;
* render() {
* var className = this.props.className;
*
* if (this.isActive('about'))
* if (this.isActive('/about'))
* className += ' is-active';
*
* return React.createElement('a', { className: className }, this.props.children);
* return React.createElement('a', { className }, this.props.children);
* }
* });
*/
Expand Down
203 changes: 0 additions & 203 deletions modules/URLUtils.js

This file was deleted.

0 comments on commit 7c1edc6

Please sign in to comment.