DurandalJS - Why are transitions not starting right away when a user navigates

跟風遠走 提交于 2019-12-22 08:53:41

问题


Could someone explain why the transitions (at least the default one - entrance) are not starting right away when a user clicks on a link (navigate) with Durandal?

In other words, do we need two mechanisms (loader animation + transition) to indicate that there is an action underway (ex. ajax call inside the activate method).

I'm sure there's a good reason, or maybe I just have to modify the entrance transition?


回答1:


It seems like Durandal's transitions run once the activate function resolves. I asked a similar question where I enumerated some of the possible solutions that I found which worked for my situation specifically:

  • Manually animate away every view in its deactivate() and animate it back in via its viewAttached()
  • Bind the .page-host div's visibility to router.isNavigating (using a custom binding to handle the transition such as the fadeVisible example from the knockout site)
  • Manually subscribe to router.isNavigating and run custom logic when it changes

Hopefully this helps.




回答2:


If you did not compress your entire application then the first process will be requirejs downloading the next amd module and then downloading the appropriate view.

The next step is durandal calling activate on your module. Activate if it returns a Deferred then it will wait for the deferred to complete.

Once activate is complete then the transition is called. The transition is responsible for swapping out the old view for the new one.

So, if its taking a while to kick off the transition its probably because its lagging in downloading your module and view.. or your activate method is taking a bit of time to finish.



来源:https://stackoverflow.com/questions/16738107/durandaljs-why-are-transitions-not-starting-right-away-when-a-user-navigates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!