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

Chapter 2Distributing Events

In the previous chapter, we looked at how async events work in JavaScript. But in practice, how should we handle those events?

That may sound like a silly question. Just attach a handler to each event your app cares about, right? But when a single event has several consequences, the “one event, one handler” approach forces handlers to grow to gargantuan proportions.

Let’s say you’re building a web-based word processor like Google Docs. Every time a user presses a key, a number of things need to happen: the new character has to be displayed on the screen, the caret has to be moved, the action has to be pushed to the local undo history and synced to the server, spell-check may have to run, and the word count and ...

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