Skip to content

Commit

Permalink
Merge pull request #19 from dcneiner/sub-bug
Browse files Browse the repository at this point in the history
Core: Multiple subscriptions are no longer ignored
  • Loading branch information
scottgonzalez committed Jul 19, 2011
2 parents 07523aa + 0d2ed16 commit 26b9bd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions core/amplify.core.js
Expand Up @@ -48,9 +48,11 @@ var amplify = global.amplify = {

var topicIndex = 0,
topics = topic.split( /\s/ ),
topicLength = topics.length;
topicLength = topics.length,
added;
for ( ; topicIndex < topicLength; topicIndex++ ) {
topic = topics[ topicIndex ];
added = false;
if ( !subscriptions[ topic ] ) {
subscriptions[ topic ] = [];
}
Expand All @@ -65,11 +67,14 @@ var amplify = global.amplify = {
for ( ; i >= 0; i-- ) {
if ( subscriptions[ topic ][ i ].priority <= priority ) {
subscriptions[ topic ].splice( i + 1, 0, subscriptionInfo );
return callback;
added = true;
break;
}
}

subscriptions[ topic ].unshift( subscriptionInfo );

if ( !added ) {
subscriptions[ topic ].unshift( subscriptionInfo );
}
}

return callback;
Expand Down
8 changes: 7 additions & 1 deletion core/test/unit.js
Expand Up @@ -144,9 +144,15 @@ test( "multiple subscriptions", function() {
});
amplify.publish( "sub-a-1" );

amplify.subscribe( "sub-b-1 sub-b-2 sub-b-3", function() {
amplify.subscribe( "sub-b-1 sub-b-2", function() {
ok( true );
});

// Test for Ticket #18
amplify.subscribe( "sub-b-1 sub-b-3", function() {
ok( true );
});

amplify.publish( "sub-b-2" );
amplify.publish( "sub-b-2" );
amplify.publish( "sub-b-3" );
Expand Down

0 comments on commit 26b9bd7

Please sign in to comment.