Skip to content

Behaviour for publishing to non-existent channel has changed #36

@tbusser

Description

@tbusser

PR #31 introduced a change in behaviour which might break existing implementations of the Mediator. The change to getChannel() on the Mediator object has had an unexpected consequence.

When you have a channel named root:sub1 and you post a message to root:sub1:subA the message will bubble through the hierarchy as expected. The problem is that subscribers will no longer be able to tell the message was originally posted to root:sub1:subA.

Before the PR this worked because the publish method create the non-existing root:sub1:subA and call the subscribers with this newly created Channel object. Due to the change the subscribers will now get called with a Channel which has a namespace root:sub as this is the most specific channel we were able to find.

I am not sure if this is going to cause any problems for anyone already using the Mediator from before PR #31 was merged. One possible solution could be to push the namespace the publish method was called with into the arguments array like this:

function publish(channelName) {
  ...
  var args = Array.prototype.slice.call(arguments, 1);
  args.push(channel);
  args.push(channelName);
  channel.publish(args);
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions