Skip to content

Commit

Permalink
Merge pull request #36 from KrisSiegel/2.4.1
Browse files Browse the repository at this point in the history
Expose subscriber count
  • Loading branch information
KrisSiegel committed Oct 11, 2015
2 parents dcdfc3c + ee336a7 commit fce68b2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
9 changes: 8 additions & 1 deletion msngr.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var msngr = msngr || (function() {
return internal.objects.message(topic, category, subcategory);
};

external.version = "2.4.0";
external.version = "2.4.1";

// Merge two inputs into one
var twoMerge = function(input1, input2) {
Expand Down Expand Up @@ -1017,6 +1017,13 @@ msngr.extend((function(external, internal) {
}
});

// Setup a property to get subscribers
Object.defineProperty(msgObj, "subscribers", {
get: function() {
return messageIndex.query(msg).length;
}
});

// If debug mode is enabled then let's expose the internal method hit counts.
// These counts are only good if a method is called and succeeds.
if (external.debug === true) {
Expand Down
2 changes: 1 addition & 1 deletion msngr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "msngr",
"main": "msngr.js",
"description": "msngr.js is a small library used to facilitate communication through messages rather than direct binding. This loose coupling allows connecting components to each other or to UI components in an abstract way on the server or the client.",
"version": "2.4.0",
"version": "2.4.1",
"keywords": ["message", "messaging", "subscription", "delegation", "eventing", "dom", "binding"],
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var msngr = msngr || (function() {
return internal.objects.message(topic, category, subcategory);
};

external.version = "2.4.0";
external.version = "2.4.1";

// Merge two inputs into one
var twoMerge = function(input1, input2) {
Expand Down
11 changes: 11 additions & 0 deletions src/objects/message.aspec.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,17 @@ describe("./objects/message.js", function() {
msngr.debug = false;
var msg2 = msngr("another");
expect(msg2.counts).to.not.exist;

msngr.debug = true;
});

it("msngr().subscribers - returns a correct subscriber count", function() {
var msg = msngr("test", "whateves");
expect(msg.subscribers).to.equal(0);
msg.on(function() { });
expect(msg.subscribers).to.equal(1);
msg.dropAll();
expect(msg.subscribers).to.equal(0);
});

});
7 changes: 7 additions & 0 deletions src/objects/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ msngr.extend((function(external, internal) {
}
});

// Setup a property to get subscribers
Object.defineProperty(msgObj, "subscribers", {
get: function() {
return messageIndex.query(msg).length;
}
});

// If debug mode is enabled then let's expose the internal method hit counts.
// These counts are only good if a method is called and succeeds.
if (external.debug === true) {
Expand Down

0 comments on commit fce68b2

Please sign in to comment.