Skip to content

Instantly share code, notes, and snippets.

@dotansimha
Created July 27, 2016 19:35
Show Gist options
  • Save dotansimha/9ff75939ad76eb87fcb097e6eba29d0d to your computer and use it in GitHub Desktop.
Save dotansimha/9ff75939ad76eb87fcb097e6eba29d0d to your computer and use it in GitHub Desktop.
Meteor MiniMongo Cursor to RxJS Observable
import { Mongo } from 'meteor/mongo';
import {Observable, Subscriber} from "rxjs";
function toObservable<T>(cursor : Mongo.Cursor<T>) : Observable<T> {
return Observable.create((observer : Subscriber) => {
const handleChange = () => {
observer.next(cursor.fetch());
};
let handler = cursor.observe({
added: handleChange,
changed: handleChange,
removed: handleChange
});
return () => {
handler.stop();
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment