More straitforward context transition relations declaration

This commit is contained in:
SleepWalker
2016-05-15 00:03:36 +03:00
parent 3472c7b29f
commit c559eb4b10

View File

@ -232,20 +232,22 @@ class PanelTransition extends Component {
} }
getDirection(next, prev) { getDirection(next, prev) {
const not = (panelId) => ![prev, next].includes(panelId); // transition between context will be Y (through heigh animation)
// transition inside context will be X (horizontal sliding animation)
const contexts = [
['login', 'password', 'forgotPassword', 'recoverPassword'],
['register', 'activation'],
['changePassword'],
['permissions']
];
const map = { const prevPanelContext = contexts.filter((context) => context.includes(prev));
login: not('password') && not('forgotPassword') ? 'Y' : 'X',
password: not('login') && not('forgotPassword') ? 'Y' : 'X',
register: not('activation') ? 'Y' : 'X',
activation: not('register') ? 'Y' : 'X',
permissions: 'Y',
changePassword: 'Y',
forgotPassword: not('password') && not('login') ? 'Y' : 'X',
recoverPassword: not('password') && not('login') && not('forgotPassword') ? 'Y' : 'X'
};
return map[next]; if (prevPanelContext.length > 1) {
throw new Error(`${prev} panel exists more than in one context`);
}
return prevPanelContext.pop().includes(next) ? 'X' : 'Y';
} }
onUpdateHeight = (height, key) => { onUpdateHeight = (height, key) => {