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

All we have to do now is to implement our service. To do this, change the listenToMessages() service in the file services.js to use this implementation:

listenToMessages(payload,observable){       let me = payload.me;       observable = observable || dataSource.get();       return observable.filter(function(message){         return !message.to || message.to === me || message.from === me;       });     } 

Our service is simple: on the first line we store the user, on the next line we store the observable we will listen to; if no observable is provided we get the observable from the DataSource containing all messages,; we then return the observable resulting from applying a filter to check that the message does not have a to property (broadcast), ...

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