Skip to content

Instantly share code, notes, and snippets.

@nicooprat
Created February 4, 2017 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicooprat/ea184d51ba3c9ab131bf1d3400ef0ef0 to your computer and use it in GitHub Desktop.
Save nicooprat/ea184d51ba3c9ab131bf1d3400ef0ef0 to your computer and use it in GitHub Desktop.
Concept for Barba v2
// Internally, do something like this
Promise
.all([
this.loadNewContent,
this.transitionOut({
fromRoute,
event,
oldContainer,
promise
})
])
.then(this.transitionIn({
fromRoute,
event,
oldContainer,
newContainer,
promise
}))
import Barba from 'barba.js'
// Github says "Contents files can't be in subdirectories or include '/' in the name" but these should be in a subdir
import home from 'routes.home.js'
import post from 'routes.post.js'
import posts from 'routes.posts.js'
Barba.init({
routes: [home, post, posts], // Order would be important, when looking for `path` property
opts: {},
defaults: {
onEnter() {},
onLeave() {},
transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {},
transitionOut({toRoute, event, oldContainer, promise}) {} // Out transition can't have `newContainer` yet
}
})
// Barba.addRoute(...)
// Barba.goTo(...)
export default {
name: 'home',
path: '/',
onEnter() {
// init components for this page, like a slider, calendar, ...
},
onLeave() {
// destroy components to avoid memory leaks
},
transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {
// do some animation
promise.resolve()
},
transitionOut({toRoute, event, oldContainer, promise}) {
if( toRoute.name === 'blog' ) {
// do animation
promise.resolve()
} else {
// do another animation
promise.resolve()
}
}
}
export default {
name: 'post',
path: '/news/*',
onEnter() {},
onLeave() {},
transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {},
transitionOut({toRoute, event, oldContainer, promise}) {}
}
export default {
name: 'posts',
path: '/news',
onEnter() {},
onLeave() {},
transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {},
transitionOut({toRoute, event, oldContainer, promise}) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment