Urigo / meteor-rxjs

Exposing Mongo Cursor as RxJS Observable
MIT License
120 stars 38 forks source link

Suggestion: MeteorObservable passing through observables #227

Open Slavrix opened 6 years ago

Slavrix commented 6 years ago

Currently, I've run into an issue where I have an observable on my server side (which is created from Rx.Observable.bindNodeCallback). When I try to return this observable in a Meteor.Method (not subscribing to it on the server, returning the whole observable) and call it using MeteorObservable.call() on the client I get back an object, that looks like it is an observable( {isScalar:false} etc as you'd expect when logging an observable), however, I cannot subscribe to the observable that is passed through to the client.

///server
Meteor.methods({
            'documents.signDir': function(link) {

               return getDocFromS3(link)
               .pipe(
                 map(res=>  {
                     console.log(res); 
                     return res;
                 })
              )
            }
...

///client

MeteorObservable.call('documents.signDir', 'some/dir/on/s3')
.subscribe((res)=>{
    console.log(res);
    res.subscribe((res2)=>{
        console.log(res2);
    })
})

//output  {isScalar: false}
//error: saying subscribe doesn't exist on res

am I doing something wrong here? I had a look at what MeteorObservable does and saw that is passes the response from Meteor.call into Observer.next() which seems to be why im getting the response im seeing.

Maybe adding a way to have MeteorObservable pass through a return if it is already an observable?

Feel free to shut me down if I'm just doing something wrong here.