Skip to content

Commit

Permalink
Restore statem (#1013)
Browse files Browse the repository at this point in the history
* restore statem selector logic

* remove import

* fix ESLint errors
  • Loading branch information
aksonov authored Aug 4, 2016
1 parent 93084b8 commit 45762f1
Showing 1 changed file with 27 additions and 13 deletions.
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

0 comments on commit 45762f1

Please sign in to comment.