Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
jQuery Design Patterns

You're reading from   jQuery Design Patterns Write Elegant, Structured and Efficient jQuery

Arrow left icon
Product type Paperback
Published in Feb 2016
Publisher
ISBN-13 9781785888687
Length 246 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Thodoris Greasidis Thodoris Greasidis
Author Profile Icon Thodoris Greasidis
Thodoris Greasidis
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. A Refresher on jQuery and the Composite Pattern FREE CHAPTER 2. The Observer Pattern 3. The Publish/Subscribe Pattern 4. Divide and Conquer with the Module Pattern 5. The Facade Pattern 6. The Builder and Factory Patterns 7. Asynchronous Control Flow Patterns 8. Mock Object Pattern 9. Client-side Templating 10. Plugin and Widget Development Patterns 11. Optimization Patterns Index

Demonstrating a sample use case

In order to see how the Pub/Sub Pattern is used, and make it easy to compare it with the Observer Pattern, we are going to rewrite the dashboard example from Chapter 2, The Observer Pattern, using this pattern. This will also clearly demonstrate how this pattern can help us decouple the individual parts of an implementation and make it more extendable and scalable.

Using Pub/Sub on the dashboard example

For the needs of this demonstration, we will use the HTML and CSS files exactly as we saw them in Chapter 2, The Observer Pattern.

Using Pub/Sub on the dashboard example

To apply this pattern, we will only need to change the code in the JavaScript file with our new implementation. In the following code snippet, we can see how the code was changed in order to adapt to the Publisher/Subscriber Pattern:

$(document).ready(function() { 
    window.broker = $('.dashboardContainer'); 

    $('#categoriesSelector').change(function() { 
        var $selector = $(this); 
        var message...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image