Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with RequireJS #9

Open
davidrhoderick opened this issue Apr 3, 2017 · 0 comments
Open

Incompatibility with RequireJS #9

davidrhoderick opened this issue Apr 3, 2017 · 0 comments

Comments

@davidrhoderick
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant