rxjs5

Use fetch instead of ajax with redux-observable

China☆狼群 提交于 2019-12-17 19:34:23
问题 In redux-observable is it possible to use isomporphic-fetch instead of Rx.DOM.ajax? 回答1: (Note: RX.DOM.ajax is from RxJS v4 , and doesn't work with redux-observable which requires RxJS v5. The equivalent in v5 is Rx.Observable.ajax or import { ajax } from 'rxjs/observable/ajax'; ) It is indeed possible to use fetch() as well as any other AJAX API; though some adapt easier than others! The fetch() API returns a Promise , which RxJS v5 has built-in support for . Most operators that expect an

How to import `Observable` from `Rx` (not angular)

这一生的挚爱 提交于 2019-12-17 18:59:08
问题 I'm using SystemJS to load my es2015 project into the browser. This is what I did import {Observable} from 'rxjs/Rx'; const button = document.querySelector('button'); const start$ = Observable.fromEvent(button, 'click'); In this case Observable is undefined . So I tried import Observable from 'rxjs/Observable'; In which case Observable is an object but Observable.fromEvent is undefined (it seems to be an empty object) Finally I did import Rx from 'rxjs/Rx' // Rx.Observable which did work. Any

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

≯℡__Kan透↙ 提交于 2019-12-17 13:54:25
问题 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. 回答1:

Difference between .unsubscribe to .take(1)

こ雲淡風輕ζ 提交于 2019-12-17 08:52:27
问题 I wonder, if there is any difference in performance between using .take(1) and .unsubscribe when unsubscribe is used right after the subscription: var observable = Rx.Observable.interval(100); First: var subscription = observable.subscribe(function(value) { console.log(value); }).unsubscribe(); Second: var subscription = observable.take(1).subscribe(function(value) { console.log(value); }); Any ideas of it makes any different regard the performance? 回答1: Each serves a different purpose so it

Chaining Observables in RxJS

雨燕双飞 提交于 2019-12-17 04:28:19
问题 I'm learning RxJS and Angular 2. Let's say I have a promise chain with multiple async function calls which depend on the previous one's result which looks like: var promiseChain = new Promise((resolve, reject) => { setTimeout(() => { resolve(1); }, 1000); }).then((result) => { console.log(result); return new Promise((resolve, reject) => { setTimeout(() => { resolve(result + 2); }, 1000); }); }).then((result) => { console.log(result); return new Promise((resolve, reject) => { setTimeout(() =>

Preserving state of checkboxes generated by Rxjs

北城以北 提交于 2019-12-14 03:46:18
问题 Based on selecting different items in a dropdown, I am generating html of items with check boxes. How can I preserve the state of checkbox i.e. check/uncheck whenever value in dropdown is changing. See the plunkr here https://plnkr.co/edit/PUG3g7dfTbQjPyIgGLzh?p=preview Steps: - uncheck 'abc2' - change dd value to 'international' - again change the dd value to 'local' - here 'abc2' must be unchecked... here is my code: var data = [ {type: 'local', name: 'abc1', location: 'xyz1', checked: true

RxJS how to ignore an error with catch and keep going

亡梦爱人 提交于 2019-12-14 03:39:44
问题 Hi I have the following code and I would like to know how to prevent the main (upstream) Observable from getting deleted when an error is thrown. How can I change the following code so that all numbers expect '4' get displayed? I am looking for a general pattern solution that would work in other cases with different operators. This is the simplest case I could come up with. const Rx = require('rxjs/Rx'); function checkValue(n) { if(n === 4) { throw new Error("Bad value"); } return true; }

angular2 avoid updating reference variable also

一世执手 提交于 2019-12-13 06:11:41
问题 why angular2 is updating all the references of a variable? Problem Statement: I have a service which returns observable on calling getData method @Injectable() export class BuildingService { constructor(private http: Http){ } buildings$: Observable<Building[]>; getData() : Observable<Building[]>{ if (this.buildings$) { this.buildings$ = this.http.get('http://localhost:8080/buildings') .map(this.extractData) .publishReplay(1) .refCount(); } return this.buildings$; } private extractData(res:

Component cannot subscribe to data source

社会主义新天地 提交于 2019-12-13 02:58:01
问题 I have this component listening for messages from a service. Note that every console.log() statement shown below is hit at least once, everything gets logged. That is, except "adding message to array" - that does not get logged, but it should get logged! Here is the component: import {Component, OnInit, Inject} from '@angular/core'; import {ChromeDataService} from '../../../../shared/services/events'; @Component({ providers: [ChromeDataService], selector: 'app-events-list', templateUrl: '.

Angular 2 & RxJs catch function callback binding to 'this' causes http request to be repeated over and over

拈花ヽ惹草 提交于 2019-12-12 19:53:04
问题 I have a method for handle our errors from http requests and it looks like this public handleError(err: any, caught: Observable<any>): Observable<any> { //irrelevant code removed this.logger.debug(err);//example of problem return caught; } It is invoked like this (example method, but shows the error) public makeHttpCall() { this.http.get("http://api.exmaple.com/getsomedata") .map(r=> r.json()) .catch(this.handleError); } The problem with the above code is that when calling this.logger.debug