rxjs5

How do I get around this “Subject incorrectly extends Observable” error in TypeScript 2.4 and RxJS 5.x?

*爱你&永不变心* 提交于 2019-11-27 19:36:01
When I compile, I get the following compiler error in the RxJS declaration files: node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable<T>'. Types of property 'lift' are incompatible. Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<R>'. Type 'Observable<T>' is not assignable to type 'Observable<R>'. Type 'T' is not assignable to type 'R'. What's going on here, and how do I get around this without downgrading to TypeScript 2.3 or earlier? Solution RxJS 5.4.2

What is pipe for in rxJS

北战南征 提交于 2019-11-27 19:34:43
I think I have the base concept, but there are some obscurities So in general this is how I use an observable: observable.subscribe(x => { }) If I want to filter data I can use this: import { first, last, map, reduce, find, skipWhile } from 'rxjs/operators'; observable.pipe( map(x => {return x}), first() ).subscribe(x => { }) I can also do this: import 'rxjs/add/operator/map'; import 'rxjs/add/operator/first'; observable.map(x => {return x}).first().subscribe(x => { }) So my questions are: What is the difference? If there is no difference, why the function pipe exists? Why those functions need

How to get current value of State object with @ngrx/store?

淺唱寂寞╮ 提交于 2019-11-27 19:17:13
问题 My service class, before calling a web service, needs to get a property called dataForUpdate from my state. Currently, I'm doing it like this: constructor ( public _store: Store<AppState>, public _APIService:APIService) { const store$ = this._store.select ('StateReducer'); .../... let update = this.actions$.filter ( action => action.type==UPDATE ) .do( (action) => this._store.dispatch({type: REDUCER_UPDATING, payload : action.payload }) ) *** GET STATE ***==> .mergeMap ( action => store$.map

Observable Finally on Subscribe

℡╲_俬逩灬. 提交于 2019-11-27 18:26:37
According to this artcle , onComplete and onError function of the subscribe are mutually exclusive. Meaning either onError or onComplete events will fire up in my subscribe . I have a logic block which needs to be executed whether I receive an error, or I finish my steam of information successfully. I looked up for something like finally in python , but all I found is finally which needs to be attached to the observable I create. But I want to to do that logic only when I subscribe, and after the stream has ended, whether successfully or with an error. Any ideas? The current "pipable" variant

How do I test a function that returns an observable using timed intervals in rxjs 5?

有些话、适合烂在心里 提交于 2019-11-27 15:34:23
For example, I have a function like this: export function timeRange(start: number, end: number): Rx.Observable<number> { return Rx.Observable.interval(1000) .map(n => n + start) .take(end - start + 1) } And I had a unit test that ran timeRange(10, 100) and asserted values against it. The problem is the time intervals would make my test too long to run. How would you reduce the time interval without touching the function itself? I tried reading the docs on schedulers but I didn't get it. There're a couple of caveats but you can test your function as follows: const Rx = require('rxjs'); const

error TS2339: Property 'takeUntil' does not exist on type 'Observable<Foo>' and other rxjs v.6 errors

可紊 提交于 2019-11-27 14:59:52
问题 I just recently updated A LOT of packages in my angular project. Old package.json: { "name": "data-jitsu", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^5.2.10", "@angular/cdk": "^5.2.5", "@angular/common": "5.2.7", "@angular/compiler": "5.2.7", "@angular/core": "5.2.7", "@angular/forms": "5.2.7", "@angular/http": "5.2

Angular2: Unsubscribe from http observable in Service

北战南征 提交于 2019-11-27 12:46:51
问题 What is the best practice to unsubscribe within a Angular2 service from a http subscription? Currently I do this but I'm not sure if this will be the best way. import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; import { Subject } from "rxjs/Subject"; import { ISubscription } from "rxjs/Subscription"; @Injectable() export class SearchService { private _searchSource = new Subject<any>(); public search$ = this._searchSource.asObservable(); constructor(private _http

Rxjs: Observable.combineLatest vs Observable.forkJoin

爷,独闯天下 提交于 2019-11-27 11:45:51
Just wonder what is differences between Observable.combineLatest and Observable.forkJoin ? As far as I can see, the only difference is forkJoin expects the Observables to be completed, while combineLatest return the latest values. Not only does forkJoin require all input observables to be completed, but it also returns an observable that produces a single value that is an array of the last values produced by the input observables. In other words, it waits until the last input observable completes, and then produces a single value and completes. In contrast, combineLatest returns an Observable

How to achieve a debounce service on input keyup event in angular2 with rxjs

和自甴很熟 提交于 2019-11-27 11:35:06
I am trying to call to a service on input key-up event. The HTML <input placeholder="enter name" (keyup)='onKeyUp($event)'> Below is the onKeyUp() function onKeyUp(event) { let observable = Observable.fromEvent(event.target, 'keyup') .map(value => event.target.value) .debounceTime(1000) .distinctUntilChanged() .flatMap((search) => { // call the service }); observable.subscribe((data) => { // data }); } It was found from the network tab of the browser that, it is calling the key-up function on every key-up event(as it is supposed to do), but what I am trying to achieve is a debounce time of

How to get an observable to return data immediately and every 5 seconds thereafter

爱⌒轻易说出口 提交于 2019-11-27 08:48:59
I want to create an observable that returns data from a webapi. I'd like it to return the data immediately, and poll the API every 10 seconds. The code below shows I'm using the 'interval' method. But this delays the first set of data by 10 seconds. How do I get that first flush of data to come down with no initial delay? export class EventService { public events$: Observable<Event[]>; private _eventsObserver: Observer<Event[]>; private pollInterval: number = 5000; private _dataStore: { events: Event[]; }; constructor(private http: Http) { this._dataStore = { events: [] }; this.events$ = new