Skip to content

Commit

Permalink
Merge pull request #43 from artvolk/1.5.2
Browse files Browse the repository at this point in the history
Pub/sub typo fix, templates cached
  • Loading branch information
addyosmani committed Jul 8, 2012
2 parents 289b19e + ddda72c commit 9e361a2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions book/index.html
Expand Up @@ -2036,7 +2036,7 @@ <h4>Example: Using Our Implementation</h4>
// Subscribers listen for topics they have subscribed to and
// invoke a callback function (e.g messageLogger) once a new
// notification is broadcast on that topic
var subscriber = pubsub.subscribe( "inbox/newMessage", messageLogger );
var subscription = pubsub.subscribe( "inbox/newMessage", messageLogger );

// Publishers are in charge of publishing topics or notifications of
// interest to the application. e.g:
Expand All @@ -2054,7 +2054,7 @@ <h4>Example: Using Our Implementation</h4>

// We cab also unsubscribe if we no longer wish for our subscribers
// to be notified
// pubsub.unsubscribe( testSubscription );
// pubsub.unsubscribe( subscription );

// Once unsubscribed, this for example won't result in our
// messageLogger being executed as the subscriber is
Expand Down Expand Up @@ -2217,13 +2217,14 @@ <h4>Example: Decoupling applications using Ben Alman's Pub/Sub implementation</h
// to a list of users who have submitted reviews
$.subscribe( "/new/user", function( e, data ){

var compiledTemplate;
// Pre-compile templates and "cache" them using closure
var
userTemplate = _.template($( "#userTemplate" ).html()),
ratingTemplate = _.template($( "#ratingsTemplate" ).html());

if( data ){

compiledTemplate = _.template($( "#userTemplate" ).html());

$('#users').append( compiledTemplate( data ));
$('#users').append( userTemplate( data ));

}

Expand All @@ -2238,9 +2239,7 @@ <h4>Example: Decoupling applications using Ben Alman's Pub/Sub implementation</h

if( data ){

compiledTemplate = _.template($( "#ratingsTemplate" ).html());

$( "#ratings" ).append( compiledTemplate( data ) );
$( "#ratings" ).append( ratingTemplate( data );

}

Expand Down Expand Up @@ -2318,6 +2317,9 @@ <h4>Example: Decoupling an Ajax-based jQuery application</h4>

;(function( $ ) {

// Pre-compile template and "cache" it using closure
var resultTemplate = _.template($( "#resultTemplate" ).html());

// Subscribe to the new search tags topic
$.subscribe( "/search/tags" , function( tags ) {
$( "#searchResults" )
Expand All @@ -2327,9 +2329,7 @@ <h4>Example: Decoupling an Ajax-based jQuery application</h4>
// Subscribe to the new results topic
$.subscribe( "/search/resultSet" , function( results ){

var compiled_template = _.template($( "#resultTemplate" ).html());

$( "#searchResults" ).append(compiled_template( results ));
$( "#searchResults" ).append(resultTemplate( results ));

});

Expand Down

0 comments on commit 9e361a2

Please sign in to comment.