O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

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

Service implementation

Now its time to implement our service to block messages from a given user. To do this, change the blockUser() service in the file services.js to use this implementation:

blockUser(payload,observable){       let blocked = payload.blocked;       observable = observable || this.listenToMessages(payload);       return observable.filter(function(message){         return message.from !== blocked;       });     } 

The implementation is similar to that from the listenToMessages() service. We have to call the filter operator to avoid propagating messages from the blocked user. One important thing is, if an observable is not passed as an argument, we get one from the listenToMessages() service, as it ensures a user listens only to messages he can listen ...

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