rxjs

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

Using RxJS 6.x WebSocketSubject client

╄→尐↘猪︶ㄣ 提交于 2019-12-05 20:20:12
I cannot figure out how to use WebSocketSubjects in rxjs v6.x Here's the working HTML/JS for v5.5.6 . The commented out code is my attempt at getting it working in v6.x : <html> <head> <!-- <script src="https://unpkg.com/@reactivex/rxjs@6.0.0/dist/global/rxjs.umd.js"></script> --> <script src="https://unpkg.com/@reactivex/rxjs@5.5.6/dist/global/Rx.js"></script> <script> // const { WebSocketSubject } = rxjs.webSocket; // const socket$ = WebSocketSubject.create('ws://localhost:8080'); const socket$ = Rx.Observable.webSocket('ws://localhost:8080'); socket$.subscribe( (data) => console.log(data),

Functional reactive operator for custom filter based on another Observable

淺唱寂寞╮ 提交于 2019-12-05 19:50:27
For fun and to learn I'm trying to implement an undo system in my app using functional reactive programming. I have a stream of state changes, which need to be saved onto the undo stack. When the user clicks undo, I take a value from the stack and update application state accordingly. The problem is that this update itself also generates an event in the state change stream. So what I would like is to derive another stream from state changes, which ommits state change right after undo. A simple diagram: states ----S----S----S---- undos -------U----------- save ----S---------S---- The first line

RxJs avoid external state but still access previous values

怎甘沉沦 提交于 2019-12-05 18:47:17
I'm using RxJs to listen to a amqp queu (not really relevant). I have a function createConnection that returns an Observable that emits the new connection object. Once I have a connection, I want to send messages through it every 1000ms and after 10 messages I want to close the connection. I'm trying to avoid external state, but if I don't store the connection in an external variable, how can I close it? See I begin with the connection, then flatMap and push messages, so after a few chains I no longer have the connection object. This is no my flow but imagine something like this:

How can I complete Observable in RxJS

浪子不回头ぞ 提交于 2019-12-05 18:18:45
问题 Let's say we have an Observable : var observable = Rx.Observable .fromEvent(document.getElementById('emitter'), 'click'); How can I make it Complete (what will trigger onComplete event for all subscribed Observers ) ? 回答1: In this present form, you cannot. Your observable is derived from a source which does not complete so it cannot itself complete. What you can do is extend this source with a completing condition. This would work like : var end$ = new Rx.Subject(); var observable = Rx

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,

Angular2 Http with RXJS Observable TypeError: this.http.get(…).map(…).catch is not a function

Deadly 提交于 2019-12-05 17:39:10
问题 I have following Service which was working fine until today i got this error TypeError: this.http.get(...).map(...).catch is not a function. When i,m debugging this code it crash when it comes to catch method. import { Test } from "./home.component"; import { Injectable } from "@angular/core"; import { Inject } from "@angular/core"; import { Http , Response } from "@angular/http"; import { Observable } from "rxjs/Observable"; @Injectable() export class HomeService { public constructor(@Inject

Get angular Observable stream as array

£可爱£侵袭症+ 提交于 2019-12-05 17:30:25
问题 I have list, that should simulate the stream : list = [ {name : 'Str1', age: 10}, {name : 'Str2', age: 10}, {name : 'Str3', age: 10} ]; and I've created an Observable from this list: Observable.from(this.list).skip(this.currentPage * this.pageSize).take(this.pageSize).subscribe(data => this.pagerList = data, console.error); And in the subscribe method I get the values one by one. How I'm supposed to wait for the whole data to be returned and then to get the whole list. There is take()

Angular2 rxjs http.request.catch has strange behaviour for some http errors

丶灬走出姿态 提交于 2019-12-05 17:27:49
My http service does not catch correctly some http errors. The catch method has 2 different response objects ( see below ). private fireRequest(request: Request): Observable<any> { return this.http.request(request) .switchMap((response: Response) => { const responseData = response.json() || []; return Observable.of(responseData); }) .catch((response: Response) => { const res2 = response.json(); // filters http errors from status 0 errors if (response.status && response.status > 0) { const res = response.json(); return Observable.of<any>(res); } const unexpectedNetworkError = new Error('commons

RxJs difference between complete and unsubscribe in Observable?

无人久伴 提交于 2019-12-05 16:30:27
after complete event will unsubscribe Observable or not or any other difference. You complete an Observable , and unsubscribe a Subscription . These are two different methods on two different objects. You subscribe to an observable which returns a Subscription object. If you want to stop listening to emits from the Observable you call subscription.unsubscribe() . If you want an Observable to be done with his task, you call observable.complete() . (this only exists on Subject and those who extend Subject ). The complete method in itself will also unsubscribe any possible subscriptions. When an