Skip to content

Incompatibility with RequireJS #9

@davidrhoderick

Description

@davidrhoderick

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions