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 ...

Get Serverless Single Page Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.