Skip to content

Commit

Permalink
Merge pull request #601 from mikefowler/master
Browse files Browse the repository at this point in the history
Fix eslint errors in Switch.js
  • Loading branch information
lelandrichardson committed Apr 27, 2016
2 parents 4bae5dc + ce9e940 commit e187567
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
presets: ["react-native"]
"presets": ["react-native"]
}
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ module.exports = {
'react',
],
parser: 'babel-eslint',
rules: {
'no-console': 0,
}
};
43 changes: 25 additions & 18 deletions src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,41 @@ export default class extends Component {
this.state = {};
}

updateState(props) {
const navState = props.navigationState;
const selector = props.selector || console.error('selector should be defined');
const selectedKey = selector(props) || console.error('selector should return key');
const selected = navState.children.filter(el => el.sceneKey == selectedKey) || console.error('key=' + selectedKey + " doesn't exist");
const navigationState = selected[0] || console.error('Cannot find scene with key=' + selectedKey);
if (navigationState.key != navState.children[navState.index].key) {
Actions[selectedKey]();
}
this.setState({ navigationState });
}
componentDidMount() {
this.updateState(this.props);

}

componentWillReceiveProps(props) {
this.updateState(props);
}

updateState(props) {
const navState = props.navigationState;

const selector = props.selector;
if (!selector) console.error('Selector should be defined.');

const selectedKey = selector(props);
if (!selectedKey) console.error('Selector should return key.');

const selected = navState.children.filter(el => el.sceneKey === selectedKey);
if (!selected) console.error(`A scene for key “${selectedKey}” does not exist.`);

const navigationState = selected[0];
if (!navigationState) console.error(`Cannot find a scene with key “${selectedKey}”`);

if (navigationState.key !== navState.children[navState.index].key) {
Actions[selectedKey]();
}

this.setState({ navigationState });
}

render() {
if (this.state.navigationState) {
return <DefaultRenderer navigationState={this.state.navigationState} />;
} else {
return null;
}

return null;
}
}




0 comments on commit e187567

Please sign in to comment.