Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const firestore = firebase.firestore()
- const doc$ = (path: string) => {
- return Observable.create(observer => {
- firestore
- .doc(path)
- .onSnapshot({
- next(doc) {
- observer.next(doc);
- }
- });
- });
- }
- // Custom Operators
- // Maps snapshot to raw data
- const data = (opts?: firebase.firestore.SnapshotOptions) => (
- source: Observable<firebase.firestore.DocumentSnapshot>
- ) =>
- new Observable<firebase.firestore.DocumentData>(observer => {
- return source.subscribe({
- next(snap) {
- observer.next(snap.data());
- }
- });
- });
- // Plucks specific properties from the document data, like a client-side projection query
- const pick = (props: string[]) => (
- source: Observable<firebase.firestore.DocumentSnapshot>
- ) =>
- new Observable<firebase.firestore.DocumentData>(observer => {
- return source.subscribe({
- next(snap) {
- const data = snap.data();
- observer.next(_.pick(data, props)); // Using lodash here
- }
- });
- });
Add Comment
Please, Sign In to add comment