Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Other minor tweaks to pub/sub example 1

  • Loading branch information...
commit d51113bb856157e8b57c526e4c209214a9355a50 1 parent de03dd7
@addyosmani authored
Showing with 7 additions and 8 deletions.
  1. +7 −8 book/index.html
View
15 book/index.html
@@ -1812,10 +1812,9 @@ <h2 id="observerpatternjavascript">The Observer Pattern</h2>
var mailCounter = 0;
// Initialize subscribers that will listen out for a topic
-// with the name "inbox/newMessage". This could correspond
-// to a new message being received
+// with the name "inbox/newMessage".
-// Renders a preview of new messages
+// Render a preview of new messages
var subscriber1 = subscribe( "inbox/newMessage", function( topic, data ) {
// Log the topic for debugging purposes
@@ -1829,14 +1828,14 @@ <h2 id="observerpatternjavascript">The Observer Pattern</h2>
});
// Here's another subscriber using the same data to perform
-// a different task. Note how nothing different has to be
-// done to the publisher in order for this to be possible.
+// a different task.
+
+// Update the counter displaying the number of new
+// messages received via the publisher
var subscriber2 = subscribe( "inbox/newMessage", function( topic, data ) {
- // Increment our counter of the number of new messages
- // received via the publisher
- mailCounter++;
+ $('.newMessageCounter').html( mailCounter++ );
});
Please sign in to comment.
Something went wrong with that request. Please try again.