Currently, I am diving into the world of RxJS and experimenting with various operators and combinations that pique my interest.
I am studying from resources like this and this.
In my Angular2 rc4 CLI project, using Typescript, I am encountering an issue where some operators are missing from the Observable.
For instance, I am trying to create an observable that emits key-value pairs from an object sequentially. The implementation can be seen here.
// Utilizing 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
However, my editor does not provide IntelliSense for Observable.pairs().
According to this article, I have added two imports:
import {Observable} from "rxjs/Rx";
import 'rxjs/Rx'; // importing all operators for this example only
I have attempted to install additional typings for rxjs beyond what the angular cli offers, but without success:
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.
I also tried:
import * as Rx from 'rxjs/Rx'
myObjProperties$ = Rx.Observable.pairs(myObj) // same error persists.
Additionally, when attempting to print the Observable object to the console, I get a string-function rather than any useful information.
console.log('TheAllmightyObservable : ', Observable) // output:
// TheAllmightyObservable : function Observable(subscribe) {
// this._isScalar = false;
// if (subscribe) {
// this._subscribe = subscribe;
// }
// }
The problem extends to many other operators such as ofObjectChanges, ofArrayChanges, ofWithScheduler, pairs, among others. While some may seem insignificant, it bothers me when I come across a highly useful RxJs operator that is inaccessible in an angular2 CLI project.
Questions:
- What is the relationship between Angular2 and RxJS? Is there a specific list of angular2-rxjs operators or are they independent packages like Jquery?
- Where can I find a comprehensive list of all available RxJS operators compatible with angular2?
- Is this primarily a TypeScript-typings issue? If so, how can I install them to access all operators mentioned in the documentation? And if typings are unavailable, how can I temporarily resolve the "no property/method found on x" problem?
Thank you for your time and assistance in helping me navigate through this challenge :)