Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore statem #1013

Merged
merged 3 commits into from
Aug 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@ export default function Switch(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 statem = props.statem;
if (!selector && !statem) console.error('Selector should be defined.');
let index = -1;
navState.children.forEach((el, i) => {
if (el.sceneKey === selectedKey) {
index = i;
}
});
let selectedKey = undefined;
if (!selector) {
// support Statem - Harel statecharts machine!
navState.children.forEach((el, i) => {
if (!(el.default || el.state)) {
console.error(`Either default or state should be defined for element=${el.key}`);
}
if (el.default) {
index = i;
} else {
if (el.state.active) {
index = i;
}
}
});
} else {
selectedKey = selector(props);
if (!selectedKey) console.error('Selector should return key.');
navState.children.forEach((el, i) => {
if (el.sceneKey === selectedKey) {
index = i;
}
});
}
if (index === -1) console.error(`A scene for key “${selectedKey}” does not exist.`);
selectedKey = navState.children[index].sceneKey;

let navigationState;
if (index !== navState.index) {
Expand Down