O'Reilly logo

Async JavaScript by Trevor Burnham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What We’ve Learned

In this chapter, we’ve learned about distributing events via PubSub, one of the most fundamental JavaScript design patterns. When you’re not subscribing to the events that are being published, PubSub is completely unobtrusive. The key to using PubSub properly is deciding which entities to distribute events through.

We’ve seen that any object can be used for PubSub, simply by inheriting from something like Node’s EventEmitter. Whenever an object is associated with a set of async tasks or I/O events, it’s a good idea to make it evented.

One class of evented object is the models in MVC libraries like Backbone.js. These models both contain application state and announce changes to it. Change events can trigger application ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required