A pattern for RxJS and Meteor


#1

I didn’t see discussion on RxJS on the forum, so I thought I’d share a pattern and get people’s opinion.

The gist of it is to use cursor.observeChanges to generate an RxJS stream, as in:

let userSubject = new Subject();
Tracker.autorun(  
    ()=>{  
     let userCursor = Meteor.users.find();  
     userCursor.observeChanges({  
       added: (_id, doc:User)=>{  
        userSubject.next(new UserEvent(doc));
       },  
       changed:(_id,doc)=>{   
        ...
       }  
      });  

The blog post is at https://fabricatech.wordpress.com/2016/05/23/a-pattern-for-rxjs-and-meteor/

It strikes as a clean pattern when a number of components in an app are interested in the same data and served my use case well (a number of Angular components needed updated user avatars and names). There’s a single cursor and subscription. Components are notified of new data via RxJS.