Created
July 27, 2016 19:35
-
-
Save dotansimha/9ff75939ad76eb87fcb097e6eba29d0d to your computer and use it in GitHub Desktop.
Meteor MiniMongo Cursor to RxJS Observable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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