Depending on the purpose of your application, you might find yourself with the need to utilize a publish-subscribe (pub-sub) architecture to accomplish certain features. AngularJS provides the proper toolkit to accomplish this, but there are considerations that need to be made to prevent performance degradation and keep the application organized.
Formerly, using the $broadcast
service from a scope with a large number of descendant scopes incurred a significant performance hit due to the large number of potential listeners that needed to be handled. In the AngularJS 1.2.7 release, an optimization was introduced to $broadcast
that limits the reach of the event to only the scopes that are listening for it. With this, $broadcast
can be used more freely throughout your application, but there is still a void to be filled to service applications that demand a pub-sub architecture. Simply put, your application should be able to broadcast an event to subscribers throughout the...