rxjs5

Typescript Select Ids from object [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 20:41:41
问题 This question already has answers here : From an array of objects, extract value of a property as array (14 answers) Closed 2 years ago . I am new to Typescript. I want to select ids from observable This is my observable let myObj = [{ "id": 1, "text": "Mary" }, { "id": 2, "text": "Nancy" }, { "id": 3, "text": "Paul" }, { "id": 4, "text": "Cheryl" }, { "id": 5, "text": "Frances" }] Expected Result : let selectedIds = [1,2,3,4,5]; Can I do this without creating an array and pushing the ids in

error TS2339: Property 'partition' does not exist on type 'Observable<boolean>'

半世苍凉 提交于 2019-12-05 19:53:45
Previously I was using rxjs-5 and I was using observable.partition as follows: const [isTiming$, isNotTiming$] = this.store.select(state => state.tetris.isTiming) .partition(value => value); After upgrade angular to 8 rxjs got upgraded to rxjs-6 which started throwing following error: providers/timer.provider.ts(27,5): error TS2339: Property 'partition' does not exist on type 'Observable<boolean>'. when I checked in older rxjs implementation it was implemented as follows: import { Observable } from '../Observable'; import { partition as higherOrder } from '../operators/partition'; /** * Splits

Observable.of turn async

試著忘記壹切 提交于 2019-12-05 18:18:39
I'm about to mock a http call wrapped into observable. My initial idea was to simply use Observable.of similar to Promise.resolve , but it does not seem to work as I expected: Rx.Observable.of('of1').subscribe(e => console.log(e)); console.log('of2'); Rx.Observable.from(Promise.resolve('from1')).subscribe(e => console.log(e)); console.log('from2'); <script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.6/dist/global/Rx.umd.js"></script> It seems that Observable.of runs synchronously while Rx.Observable.from(Promise.resolve('from1')) runs asynchronously (that is what I want). As long as I

Convert infinite async callback sequence to Observable sequence?

限于喜欢 提交于 2019-12-05 18:05:18
Let's say I have the following asynchronous callback-based "infinite" sequence, which I cancel after some time: 'use strict'; const timers = require('timers'); let cancelled = false; function asyncOperation(callback) { const delayMsec = Math.floor(Math.random() * 10000) + 1; console.log(`Taking ${delayMsec}msec to process...`); timers.setTimeout(callback, delayMsec, null, delayMsec); } function cancellableSequence(callback) { asyncOperation((error, processTime) => { console.log('Did stuff'); if (!cancelled) { process.nextTick(() => { cancellableSequence(callback); }); } else { callback(null,

How to Return From Observable in TypeScript Method with Return Type

試著忘記壹切 提交于 2019-12-05 17:41:05
I have a Google geocode service in TypeScript. I need this method to return a "GoogleMap" class, after it fetches the lat/long for a given address. I created a TypeScript method that returns a "GoogleMap" type. But, I'm getting a function that is neither void nor any must return a value... Here's my method: getLatLongFromAddress(streetAddress: string): GoogleMap { this.geoCodeURL = GOOGLE_GEOCODE_BASE_URL + streetAddress + "&key=" + GOOGLE_MAPS_API_KEY; this.googleMap = new GoogleMap(); this.httpService .get(this.geoCodeURL) .subscribe((data) => { this.googleMap.lat = data.results.geometry

Angular 2 polling with RxJS

ε祈祈猫儿з 提交于 2019-12-05 17:15:46
问题 I'm trying to poll a RESTful endpoint to refresh my live chat messages. I know the best approach for a live chat would be Websockets, I'm just trying to understand how RxJS works with Angular 2. I want to check for new messages every second. I have the following code: return Rx.Observable .interval(1000) .flatMapLatest(() => this.http.get(`${AppSettings.API_ENDPOINT}/messages`)) .map(response => response.json()) .map((messages: Object[]) => { return messages.map(message => this.parseData

Angular 2 Http RetryWhen

空扰寡人 提交于 2019-12-05 15:26:43
I'm trying to use retryWhen in HTTP calls. It works perfectly when try to use like this: return this.http.get(`${environment.apiUrl}/track/${this.user.instance._id}/${this.currentPlayer.playlist.id}/next?s=${this.playerCounter}`, options) .timeout(500, new TimeoutError(`Timeout trying to get next track. [instanceId=${this.user.instance._id}]`)) .retryWhen(attempts => { return Observable.range(1, 3).zip(attempts, i => i).flatMap(i => 3 === i ? Observable.throw(attempts) : Observable.timer(i * 1000)); }) It makes a maximum of 3 tries if get a Timeout error. But, always have a buuut, I want to

Start first call of IntervalObservable instant

流过昼夜 提交于 2019-12-05 10:41:07
I'm using an IntervalObservable to make continuous calls to the server side of my application. I can subscribe and unsubscribe to to the Oberservable and everything works fine with one exception: The first call to the server is delayed, but I want it to be instant. The behaviour of the IntervalObservable is in principle correct, but does not match my requirements. @Injectable() export class LoggerService { constructor(private http: Http) { } private apiURL = 'assets/file.json'; getList() { return IntervalObservable.create(1000).flatMap(() => this.http.get(this.apiURL)) .map(this.extractData)

rxjs5 merge and error handling

会有一股神秘感。 提交于 2019-12-05 10:32:42
I would like to combine/merge multiple Observables and when each of them is completed execute a finally function. The merge operator seems to execute each subscription in parallel, which is what I need, but if any of them throws an error the execution is halted. RxJS version 4 has an operator mergeDelayError that should keep the all subscriptions executing till all of them are completed, but this operator isn't implemented in version 5 . Should I revert to a different operator? var source1 = Rx.Observable.of(1,2,3).delay(3000); var source2 = Rx.Observable.throw(new Error('woops')); var source3

Batching using RxJS?

旧街凉风 提交于 2019-12-05 08:44:06
I'm guessing this should be somewhat easy to achieve but I've having trouble (conceptually, I guess) figuring out how to tackle it. What I have is an API that returns an array of JSON objects. I need to step through these objects, and, for each object, make another AJAX call. The issue is the system that handles each AJAX call can only handle two active calls at a time (as it's quite a CPU-intensive task that hooks out into a desktop application). I was wondering how I could achieve this using RxJS (either using version 5 or 4)? EDIT: In addition, is it possible to have a chain of steps