barba: Barba.HistoryManager.currentStatus is undefined
Hey there!
Love the library, but I seem to keep running into an issue where the Barba.HistoryManager.currentStatus() object is always returned undefined. Whereas prevStatus() seems to work perfectly.
I’m following one of your demo’s code in order to use a variety of transitions.
Barba.Pjax.getTransition = function() {
var transitionObj = FadeTransition;
if (Barba.HistoryManager.currentStatus().namespace === "homepage") {
transitionObj = HomeTransition;
}
return transitionObj;
};
Is there a preferred way for determining what transition to use when you want separate pages to use unique animations?
Is there any chance we could add a demo with namespaces/views? I’m finding them difficult to use correctly given most pages will have two on a page initially.
Thanks!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (8 by maintainers)
Hi @destefanis ! Are you sure that
Barba.HistoryManager.currentStatus()returnsundefined, or it’s just the.namespacevalue?In the second case, it’s normal.
When
.getTransitionis called, the next page is not loaded yet, that means that we don’t know thedata-namespaceyet on the next container.Usually I use different solutions:
1. by URL
You can make a check on
Barba.HistoryManager.currentStatus().urlto choose what Transition to use.cons: could be tricky to keep track of the URL for a multilanguage / CMS driven site
2. by namespace
You can make a generic Transition, that waits
newContainerLoadingto be resolved, at that point.namespacewill be populated and you can continue the transition accordingly.cons: You need to wait the loading of the next page before starting the transition
3. by latest clicked element
You may want to save the latest clicked element
then, in
.getTransition, decide the transition based on this.How I structure my transitions:
I use commonJS modules for all my project, and I have all my transition in separate files.
To each transition I implement a
valid()method, that could returntrueorfalse, based if that transition has the right or not to be executed.A typical
validfunction may look like this:and in my .getTransition I do something like:
This structure helps me to be very flexible, and to use that three different technique to choose if that particular transition needs to run or not.
Hope this reply fits your needs. Cheers!
Really enjoying Barba!
I’ve come up with a technique for managing transitions that I wanted to share. Curious if anyone else has used this technique. Would really appreciate any feedback!
Informative and thorough response! I might suggest adding something like this to the documentation. However, this is perfect, I appreciate the help.