chore(client): simplify resolveTransitions()

#566
This commit is contained in:
Pooya Parsa 2017-06-12 05:09:42 +04:30
parent 5c36ed7b73
commit d3f66e132e

View File

@ -14,17 +14,16 @@ let router
<%= (store ? 'let store' : '') %>
function mapTransitions(Components, to, from) {
const resolve = t => (typeof t.options.transition === 'function')
? t.options.transition(to, from)
: Object.assign({}, t.options.transition)
const resolveTransitions = component => (typeof component.options.transition === 'function')
? component.options.transition(to, from)
: component.options.transition
const resolveRoute = r => resolve(r.matched[0].components.default)
const resolveRoute = route => resolveTransitions(route.matched[0].components.default)
return Components.map((Component) => {
let transitions = Object.assign({}, to ? resolveRoute(to) : resolve(Component))
// Combine transitions
// Prefer leave* transitions of from route
let from_transitions = from ? resolveRoute(from) : {}
const transitions = Object.assign({}, to ? resolveRoute(to) : resolveTransitions(Component))
const from_transitions = from ? resolveRoute(from) : {}
// Combine transitions & prefer leave* transitions of from route
Object.keys(from_transitions).forEach(key=> {
if (from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1) {
transitions[key] = from_transitions[key]