Fork me on GitHub
This API is deprecated since version 0.7.0 and will be removed in a future release (Moved to meteor-rxjs package)

MeteorObservable

A class with static methods, which wraps Meteor's API and returns RxJS Observable as return value for all Meteor's API. The method's signature is the same as Metoer's, except you don't need to provide callbacks, and you need to "subscribe" instead. The functionality that wrapped in this implementation is Meteor.call and Meteor.subscribe.

Kind: global class

MeteorObservable.call(name, ...args) ⇒ Observable.<T>

Method has the same notation as Meteor.call, only without the callbacks: Meteor.call(name, [...args])

Kind: static method of MeteorObservable
Returns: Observable.<T> - - RxJS Observable, which completes when the server return a response.

Param Type Description
name String Name of the method in the Meteor server
...args any Parameters that will be forwarded to the method. after the func call to initiate change detection.

Example (Example using Angular2 Component)

 class MyComponent  {
    constructor() {

    }

    doAction(payload) {
       MeteorObservable.call("myData", payload).subscribe((response) => {
          // Handle success and response from server!
       }, (err) => {
         // Handle error
       });
    }
 }

MeteorObservable.subscribe(name, ...args) ⇒ Observable

Method has the same notation as Meteor.subscribe, only without the callbacks: subscribe(name, [...args]) except the last autoBind param (see autorun above). You can use this method from any Angular2 element - such as Component, Pipe or service.

Kind: static method of MeteorObservable
Returns: Observable - - RxJS Observable, which completes when the subscription is ready.
See: Publications in Meteor documentation

Param Type Description
name String Name of the publication in the Meteor server
...args any Parameters that will be forwarded to the publication. after the func call to initiate change detection.

Example (Example using Angular2 service)

 class MyService {
    private meteorSubscription: Observable<any>;

    constructor() {

    }

    subscribeToData() {
       this.meteorSubscription = MeteorObservable.subscribe<any>("myData").subscribe(() => {
          // Subscription is ready!
       });
    }

    unsubscribeToData() {
       this.meteorSubscription.dispose();
    }
 }

Example (Example using Angular2 Component)

 class MyComponent implements OnInit, OnDestory {
    private meteorSubscription: Observable<any>;

    constructor() {

    }

    ngOnInit() {
       this.meteorSubscription = MeteorObservable.subscribe("myData").subscribe(() => {
          // Subscription is ready!
       });
    }

    ngOnDestory() {
       this.meteorSubscription.dispose();
    }
 }