-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Regular postal works great with require; if you publish on a channel from a dependency, the module depending on it receives that transmission through a subscription. I.E. if 'app/app' is defined like so:
define(['postal', 'postal.when'], function (postal) {
var app = postal;
return app;
});
Then, the following works:
requirejs(['app/app', 'app/homeBackgroundSlider'],
function ( app, homeBackgroundSlider) {
// homeBackgroundSlider sends homeBackgroundSlider.complete on the default channel
app.channel().subscribe('homeBackgroundSlider.complete', function() {
console.log('this works');
});
});
But this won't work:
requirejs(['app/app', 'app/homeBackgroundSlider'],
function ( app, homeBackgroundSlider) {
// homeBackgroundSlider sends homeBackgroundSlider.complete on the default channel
app.when([{topic: 'homeBackgroundSlider.complete'}], function() {
console.log('this doesn\'t work');
});
});
Now I've only started digging into postal.when, but my guess is that because 'app/homeBackgroundSlider' is included as a dependency, it actually executes before the module above, meaning that it publishes before the when statement listens. However, that it works using "vanilla" postal's subscribe means that perhaps this issue has to do with the postal.when code specifically. In fact, I had this issue elsewhere and created my own postal.when functionality in code, I just don't want to have to do that (makes postal.when useless in requireJS applications).