Urigo / meteor-rxjs

Exposing Mongo Cursor as RxJS Observable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No support for ValidatedMethods (method 'objects')

JanvanCasteren opened this issue · comments

Thanks for this library I use it together with meteor-client-bundler and Angular and it works very well.

Method MeteorObservable.call only supports calling methods by passing a string. But when ValidatedMethods are used, methods are imported as objects with a call() method. I wrote my own implementation for this, maybe you could integrate something like that in your library:

import {Observable} from 'rxjs/Observable';
import {Subscriber} from 'rxjs/Subscriber';
import {Meteor} from 'meteor/meteor';
import { forkZone } from 'meteor-rxjs/dist/utils';

export const MethodObservable = function<T>(method: any, args?: any) {

    const zone = forkZone();

    return Observable.create((observer: Subscriber<Meteor.Error | any>) => {
        method.call(args,  (error: Meteor.Error, result: T) => {
                zone.run(() => {
                    error ? observer.error(error) :
                        observer.next(result);
                    observer.complete();
                });
            }
        );
    });
};