3

I'm in the process of learning RxJS and i constantly try many operators and combinations that i find interesting.

I'm learning form here: http://reactivex.io/documentation/operators.html and here.

I have an Angular2 rc4 CLI project - so i'm using Typescript. RxJS is : 5.0.0-beta.6

The problem:

I found that some operators are not present on the Observable.

For example: I want to create an observable that returns one by one key value pairs of an object: You can see how the implementation looks like, as i've taken it from here.

// Using Standard JavaScript
var obj = {
  foo: 42,
  bar: 56,
  baz: 78
};

var source = Rx.Observable.pairs(obj);

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Next: ['foo', 42]
// => Next: ['bar', 56]
// => Next: ['baz', 78]
// => Completed

But here is what my editor looks like:

enter image description here

no Intelisense for Observable.pairs()..

enter image description here

Based on this post i've aded the 2 imports:

import {Observable} from "rxjs/Rx";
import 'rxjs/Rx'; // import all operators and stuff. it's not good practice i know, but only for this example

And tryed to install more typings for rxjs than angular cli provides, but is not working:

typings install --save --ambient npm:rx/ts/rx.all.d.ts // Unable to resolve "npm:rx/ts/rx.all.d.ts" from "rx"
or
typings install rxjs // Unable to find "rxjs" ("npm") in the registry.

And aslo tryed to use:

import * as Rx form 'rxjs/Rx'
myObjProperties$ = Rx.Observable.pairs(myObj) // still doesn't work, same error.

And aslo, I can't explain why printing the Observable object to the console doesn't work.. I get a string-function which is useless. No prototype stuff.

console.log('TheAllmightyObservable : ', Observable) // i get:

// TheAllmightyObservable :  function Observable(subscribe) {
        // this._isScalar = false;
        // if (subscribe) {
            // this._subscribe = subscribe;
        // }
    // }

I have the same problem with many other operators: ofObjectChanges, ofArrayChanges, ofWithSkeduler, pairs - some of them not that important - but it bugs me when i found one RxJs operator that is very useful, and i can't use it in angular2 CLI project.

Questions:

  1. what angular2 has to do with RxJS ? (i'm missing the general picture i guess..) - is there a separate list of angular2-rxjs operators or RxJS is fully separated package, and can be used like Jquery for example? I mean no wired interference between the 2 - that i can't predict. (digest cycle related maybe?!)

  2. where can i find a good list of all the RxJS operators available on angular2 - assuming that exists.

  3. is this only a Typescript - typings problem? If so, how to install them in order to have all the operators which are available on the docs? If no typings are available, how to temporarily get rid of this "no property/method found on x" problem?

Thank you so much for taking the time to read and help me by finding a solution to this:)

AIon
  • 12,521
  • 10
  • 47
  • 73
  • I had the same issue [here](http://stackoverflow.com/questions/38607203/angular-2-property-topromise-does-not-exist-on-type-observableresponse) and its somewhat similar to it. It's still unanswered yet. I have open an issue on angular github but still no correct solution found. Hope you find solution for this – Abdul Moiz Khan Jul 29 '16 at 12:20

1 Answers1

5

Root issue: You are using one version of RxJS but looking at the documentation for another.

RxJS 5 (beta) used with Angular 2: https://github.com/ReactiveX/rxjs RxJS 4 (stable): https://github.com/Reactive-Extensions/RxJS

Those operators do not exist on the new version which is why you can't see them.

To your questions:

1) RxJS doesn't have anything to do with Angular2, you can use RxJS without Angular2. RxJS is just a library for creating event streams, it operate orthogonally to what ever you use to generate events.

2) If you are using RxJS 4 then you can use the docs which are pretty good. RxJS 5 is still a work in progress but there are docs that are generated by the build process here.

3) It is not a typings issue in this case.

paulpdaniels
  • 18,395
  • 2
  • 51
  • 55