Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlehman committed Sep 25, 2015
1 parent 48ba046 commit 23749e4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"no-else-return": 0,
"new-cap": 0,
"quotes": [2, "single", "avoid-escape"],
"comma-dangle": 0,
"jsx-quotes": 1,

"react/display-name": 1,
"react/jsx-boolean-value": 1,
"react/jsx-quotes": 1,
"react/jsx-no-undef": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1,
Expand Down
2 changes: 1 addition & 1 deletion dist/switcheroo.min.js

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@
"author": "Jonathan Lehman <[email protected]>",
"license": "MIT",
"devDependencies": {
"babel-core": "^5.2.17",
"babel-eslint": "^3.1.26",
"babel-loader": "^5.0.0",
"chai": "^2.3.0",
"eslint": "^0.20.0",
"eslint-config-airbnb": "0.0.6",
"eslint-plugin-react": "^3.0.0",
"istanbul": "^0.3.13",
"istanbul-instrumenter-loader": "^0.1.2",
"karma": "^0.12.31",
"babel-core": "^5.8.25",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"chai": "^3.3.0",
"eslint": "^1.5.1",
"eslint-config-airbnb": "0.0.9",
"eslint-plugin-react": "^3.4.2",
"istanbul": "^0.3.21",
"istanbul-instrumenter-loader": "^0.1.3",
"karma": "^0.13.10",
"karma-chai": "^0.1.0",
"karma-cli": "0.0.4",
"karma-coverage": "^0.3.1",
"karma-mocha": "^0.1.10",
"karma-phantomjs-launcher": "^0.1.4",
"karma-cli": "0.1.0",
"karma-coverage": "^0.5.2",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sinon": "^1.0.4",
"karma-sourcemap-loader": "^0.3.4",
"karma-webpack": "^1.5.1",
"mocha": "^2.2.4",
"phantomjs": "^1.9.16",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"mocha": "^2.3.3",
"phantomjs": "^1.9.18",
"react": ">=0.12.0 <0.14.0",
"sinon": "git://github.com/cjohansen/Sinon.JS#b672042043517b9f84e14ed0fb8265126168778a",
"webpack": "^1.8.11"
"webpack": "^1.12.2"
},
"peerDependencies": {
"react": ">=0.12.0 <0.14.0"
},
"dependencies": {
"route-recognizer": "^0.1.5"
"route-recognizer": "^0.1.9"
}
}
63 changes: 31 additions & 32 deletions src/components/Switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,17 @@ export default class Switcher extends Component {
}

componentDidMount() {
if(this.props.load) {
if (this.props.load) {
window.addEventListener('load', this.handleRouteChange);
}
if(this.props.pushState) {
if (this.props.pushState) {
window.addEventListener('popstate', this.handleRouteChange);
}
if(this.props.hashChange) {
if (this.props.hashChange) {
window.addEventListener('hashchange', this.handleRouteChange);
}
}

componentWillUnmount() {
if(this.props.load) {
window.removeEventListener('load', this.handleRouteChange);
}
if(this.props.pushState) {
window.removeEventListener('popstate', this.handleRouteChange);
}
if(this.props.hashChange) {
window.removeEventListener('hashchange', this.handleRouteChange);
}
}

componentWillReceiveProps(nextProps) {
this.initializeRecognizer(nextProps);

Expand All @@ -76,23 +64,23 @@ export default class Switcher extends Component {
});
}

initializeRecognizer = (props) => {
this.recognizer = new Recognizer();
var children = [].concat(props.children);
children.forEach((child) => {
this.recognizer.add([{
path: `${props.basePath}${child.props.path}`,
handler: child.props.handler || child
}]);
});
componentWillUnmount() {
if (this.props.load) {
window.removeEventListener('load', this.handleRouteChange);
}
if (this.props.pushState) {
window.removeEventListener('popstate', this.handleRouteChange);
}
if (this.props.hashChange) {
window.removeEventListener('hashchange', this.handleRouteChange);
}
}

getLocation = () => {
var location = decodeURI(window.location[this.props.location].slice(1).split('?')[0]);
if(location.charAt(0) !== '/') {
if (location.charAt(0) !== '/') {
return `/${location}`;
}
else {
} else {
return location;
}
}
Expand All @@ -102,11 +90,23 @@ export default class Switcher extends Component {
return (handlers && handlers[0] && handlers[0].handler) || null;
}

handleRouteChange = (e) => {
initializeRecognizer = (props) => {
this.recognizer = new Recognizer();
var children = [].concat(props.children);
children.forEach((child) => {
this.recognizer.add([{
path: `${props.basePath}${child.props.path}`,
handler: child.props.handler || child
}]);
});
}


handleRouteChange = (ev) => {
var currentPath = this.getLocation();
var switchElement = this.getSwitch(currentPath);

if(typeof this.props.onChange === 'function') {
if (typeof this.props.onChange === 'function') {
this.props.onChange(!!switchElement, currentPath);
}

Expand All @@ -116,14 +116,13 @@ export default class Switcher extends Component {
}

render() {
if(this.props.wrapper) {
if (this.props.wrapper) {
return React.createElement(
this.props.wrapper,
this.props,
this.state.visibleSwitch || this.defaultSwitch
);
}
else {
} else {
return this.state.visibleSwitch || this.defaultSwitch;
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/components/Switcher_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ describe('Switcher', function() {
});

it('handles paths with wild cards', function() {
var swtch = this.switcher.getSwitch('/wildCardPath/something'),
swtch2 = this.switcher.getSwitch('/wildCardPath/something/more');
var swtch = this.switcher.getSwitch('/wildCardPath/something');
var swtch2 = this.switcher.getSwitch('/wildCardPath/something/more');
assert.equal(swtch.props.children, 'Wild');
assert.equal(swtch2.props.children, 'Wild');
});

it('handles paths with dynamic segments', function() {
var swtch = this.switcher.getSwitch('/path/abc123/more'),
swtch2 = this.switcher.getSwitch('/path/somethingelse/more');
var swtch = this.switcher.getSwitch('/path/abc123/more');
var swtch2 = this.switcher.getSwitch('/path/somethingelse/more');
assert.equal(swtch.props.children, 'Dynamic');
assert.equal(swtch2.props.children, 'Dynamic');
});
Expand Down Expand Up @@ -298,8 +298,8 @@ describe('Switcher', function() {
it('renders matched component in wrapper', function() {
window.location.hash = '/';
this.switcher.handleRouteChange();
var wrapper = React.findDOMNode(this.switcher),
component = wrapper.children[0];
var wrapper = React.findDOMNode(this.switcher);
var component = wrapper.children[0];
assert.equal(wrapper.tagName, 'SPAN');
assert.equal(component.innerHTML, 'Home');
});
Expand Down
2 changes: 0 additions & 2 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// https://github.com/facebook/react/issues/945

(function() {

var Ap = Array.prototype;
var slice = Ap.slice;
var Fp = Function.prototype;
Expand Down Expand Up @@ -41,5 +40,4 @@
return bound;
};
}

})();

0 comments on commit 23749e4

Please sign in to comment.