O'Reilly logo

Serverless Single Page Apps by Ben Rady

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

Using Custom Events

Right now, it’s easy for our views to invoke behavior in the rest of the application. Our data model functions, for example, are easily shared among the views. One thing that’s missing is a way for the app to trigger behavior in the views. There’s no good way for the app to reach into the scope of the view functions to make things happen.

One approach we could take is to add a button to our shiny new toolbar and have each view register a click handler when it is created. However, without a mechanism to remove that click handler, that handler and any variables in its scope will never be garbage collected. As users move through the views, our memory usage would gradually increase until the application crashes.

To avoid this ...

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