Closed D1no closed 9 years ago
Hey Dino, thank you for checking it out. Tests are coming as soon as I find some time to write (and test ;) them, but you're welcome to do it as well :)
As for the problem - it seems that in the latest version(s) Iron.Router doesn't call route event handlers (onRun
, waitOn
,...) within extended (custom) route controllers unless they are explicitly assigned to particular route.
For now, I'd suggest two workarounds: either...
Router.route( '/', {
name: 'home',
// Assign route controller to each route
// 'PreloadController' is provided by the
// miro:preloader package
controller: 'PreloadController'
});
...or...
// NOTE: PreloadController is client-only!
if ( Meteor.isClient ) {
// HomeController = RouteController.extend({
HomeController = PreloadController.extend({
waitOn: function () {
return [Meteor.subscribe("articles")];
},
data: function () {
return {
articles: Articles.find()
};
},
preload: {
'sync': {
'default': {
'js' : '/externaljs.js'
}
}
}
});
}
Same here, not working on any place, on controller or out... ;)
Hey Jadson, have you tried the workarounds I've described?
yes man, before comment here. :D
Well, that's odd man. I'm using it on one of my projects and I tested it with Dino's preloadertest repository where my workaround code came from.
Ya better check your code again, man ;)
Mh, can you give me a pull-request - it doesn't work for me either
There you go! :)
Hey, thanks for the quick response. Well, i think I found the error. The reason why it works in my repo is due to the double declaration of preloader in both the route and the controller. And you had a typo in the controller, loading externaljs.js.
But I believe there is also an odd behavior that the controller has no effect.
router.js
// Global Router Set-Up
Router.configure({
layoutTemplate: 'Layout',
loadingTemplate: "Loading",
/*
miro:preloader preload router extension
*/
preload: {
sync: {
'default': {
'js' : '/external.js'
}
}
}
});
controller.js
if ( Meteor.isClient ) {
// HomeController = RouteController.extend({
HomeController = PreloadController.extend({
waitOn: function () {
return [Meteor.subscribe("articles")];
},
data: function () {
return {
articles: Articles.find()
};
},
preload: {
'sync': {
'default': {
'js' : '/external.js' //correct file
}
}
}
});
}
deleted preloader settings from router.js router.js
// Global Router Set-Up Router.configure({ layoutTemplate: 'Layout', loadingTemplate: "Loading", /* miro:preloader preload router extension */ });
controller.js
if ( Meteor.isClient ) {
// HomeController = RouteController.extend({
HomeController = PreloadController.extend({
waitOn: function () {
return [Meteor.subscribe("articles")];
},
data: function () {
return {
articles: Articles.find()
};
},
preload: {
'sync': {
'default': {
'js' : '/externaljs.js'
}
}
}
});
}
router.js
// Global Router Set-Up
Router.configure({
layoutTemplate: 'Layout',
loadingTemplate: "Loading",
/*
miro:preloader preload router extension
*/
preload: {
sync: {
'default': {
'js' : '/external.js'
}
}
}
});
deleted preloader settings in controller.js from HomeController. Also changes there have no effect
if ( Meteor.isClient ) { // HomeController = RouteController.extend({ HomeController = PreloadController.extend({ waitOn: function () { return [Meteor.subscribe("articles")]; }, data: function () { return { articles: Articles.find() }; } }); }
router.js
// Global Router Set-Up
Router.configure({
layoutTemplate: 'Layout',
loadingTemplate: "Loading",
/*
miro:preloader preload router extension
*/
preload: {
sync: {
'default': {
'js' : '/external.js'
}
}
}
});
As long preload is included, content doesn't matter
if ( Meteor.isClient ) { // HomeController = RouteController.extend({ HomeController = PreloadController.extend({ waitOn: function () { return [Meteor.subscribe("articles")]; }, data: function () { return { articles: Articles.find() }; }, preload: { 'pizza': { 'american-style': { 'dinner' : 'salami' } } } }); }
Hey guys, I've just released a new version of Preloader as well as updated testing app.
API (and internals) is simplified and should be easier to use.
Let me know how it goes.
I worked for me with the following syntax:
Router.route('/', {
template: 'custom_view',
controller: PreloadController,
preload: {
styles: '/materialize/css/materialize.min.css'
}
})
I very much like the concept, but I can not get it to work. (Compatibility?)
Since you don't have any tests, I simply added it to a baseline set-up https://github.com/D1no/preloadertest to check out for recreation. Preloader was added to the global configuration object
Router.configure
; router.jsA blind copy of the examples including a variation in objects async, sync, common, default and key expressions
' '
, or file root/
seems to have no effect. Why does external.js not fire?