Reputation: 145
I would like to know how I could force loading template to have a minimum load time (ex: 3 seconds) before loading my default template / controller (App Controller). I have no subscriptions so, the only thing I need is to set the timeout for delaying the loadingTemplate.
I've already tried a similar solution posted [here][1] but the problem now is that Router.route('/', { name: 'home'}); is never called and I'm stuck on the loadingTemplate page.
I deployed my application to http://ns-timeout.meteor.com/ so anyone could have a look on my console.logs()...
Any help would be very appreciated.
Thank you very much
Router.configure({
layoutTemplate: 'AppController',
loadingTemplate: 'loading',
waitOn: function() {
var hasWaitTimePassed = new ReactiveVar(false);
var waitFor = 3000; // Wait for 3 sec
var stopped = false;
Meteor.setTimeout(function() {
console.log('setTimeOut() hasWaitTimePassed :'+ hasWaitTimePassed.get());
console.log('setTimeOut() stopped :'+ stopped);
if (!stopped) {
hasWaitTimePassed.set(true);
console.log('setTimeOut() if(!stopped) : hasWaitTimePassed.set(true):'+ hasWaitTimePassed.get());
console.log('setTimeOut() if(!stopped): '+ stopped);
}
}, waitFor);
return {
ready: function() {
// hasWaitTimePassed is a reactive source, so this should do just fine
console.log('return { ready function() hasWaitTimePassed :'+ hasWaitTimePassed.get());
console.log('return { ready function() stopped :'+ stopped);
return hasWaitTimePassed.get();
},
stop: function() {
console.log('return { stop function() hasWaitTimePassed :'+ hasWaitTimePassed.get());
console.log('return { stop function() stopped :'+ stopped);
// Stopping should prevent the hasWaitTimePassed becoming true.
stopped = true;
}
};
}
});
Upvotes: 2
Views: 120