Fork me on GitHub

MeteorObservable

This is a class with static methods that wrap Meteor's API and return RxJS Observables. The methods' signatures are the same as Meteor's, with the ] exception that the callbacks are handled by Meteor-rxjs. Instead of providing callbacks, you need to subscribe to the observables that are returned. The methods that are wrapped in MeteorObservable are Meteor.call, Meteor.autorun and Meteor.subscribe.

Kind: global class

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

Invokes a Meteor Method defined on the server, passing any number of arguments. This method has the same signature as Meteor.call, only without the callbacks: MeteorObservable.call(name, [...args])

Kind: static method of MeteorObservable
Returns: Observable.<T> - - RxJS Observable, which completes when the server returns 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

When you subscribe to a collection, it tells the server to send records to the client. This method has the same signature as Meteor.subscribe, except without the callbacks again: subscribe(name, [...args])

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.unsubscribe();
    }
 }

Example (Example using Angular2 Component)

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

    constructor() {

    }

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

    ngOnDestroy() {
       this.meteorSubscription.unsubscribe();
    }
 }

MeteorObservable.autorun() ⇒ Observable.<T>

Allows you to run a function every time there is a change is a reactive data sources. This method has the same signature as Meteor.autorun, only without the callback: MeteorObservable.autorun()

Kind: static method of MeteorObservable
Returns: Observable.<T> - - RxJS Observable, which trigger the subscription callback each time that Meteor Tracker detects a change.
Example (Example using Angular2 Component)

 class MyComponent  {
    constructor() {

    }

    doAction(payload) {
       MeteorObservable.autorun().subscribe(() => {
          // Handle Tracker autorun change
       });
    }
 }