rxjs

What's the difference between two Observables if one is created by defer?

走远了吗. 提交于 2019-12-11 13:17:59
问题 For instance, var interval = Rx.Observable.interval(1000); interval.subscribe(x => console.log(x)); And var deferred = Rx.Observable.defer(()=> return interval); deferred.subscribe(x=> console.log(x)); seem to do the same thing. It seems to that observables are by default "deferred". What is defer useful for? 回答1: defer takes a parameter function which returns an observable. The operator itself returns an observable, as most operators do. When that defer observable is subscribed to, it

Importing operators with RXJS 5.0.0-beta.6 and Angular 2 RC1

六眼飞鱼酱① 提交于 2019-12-11 13:09:37
问题 I am building an Angular 2 web app using Typescript and am trying to switch from Angular2-beta-17 to Angular2-RC1. I am struggling to get the imports of the RXJS operators to work. I am using SystemJS as a module loader, and suspect this is were the problem lies. I copy the file bundles I need from my node modules to a lib-folder and then include the files in the index.html file like this (the commented sections are some of the many combinations of different attempts for solutions I have

Smarter buffers

情到浓时终转凉″ 提交于 2019-12-11 12:37:23
问题 I send request - get an array of data. In order to manipulate that data I need to flatten it, so I can use it as a stream of entities not stream of array of entities but, then on side-effect I want those entities appear in the UI at once, not one by one, so it updates UI only ones at a time. Let's say I have a code like this: // this generates a sequence of objects - getCasesStream sends an ajax request, // whenever dateRange changes casesStm = dateRangeStm.flatMapLatest(getCasesStream)

Handle error in forkJoin on subscribe

旧巷老猫 提交于 2019-12-11 12:15:13
问题 I have next function: saveTable() { ... let promises = []; for (index = 0; index < this._TOTAL.length; ++index) { let promise = this.db.object(ref).update(this._TOTAL[index]); promises.push(promise); } Observable.forkJoin(promises).subscribe(() => { this.messagesService.createMessage('success', `Saved`); this.router.navigate(['/dashboard/my-calculations']); }) } How can i handle error in this case? Actually, i just need to use then and catch after all my promises resolve, so using forkJoin

Can't infer type in the map function

本小妞迷上赌 提交于 2019-12-11 12:04:49
问题 As part of migrating my project from angular 5 to 6 I had to update the way RXJS6 does things. So this this.filteredList = this.autoComplete.valueChanges .startWith(null) .map(val => val ? this.filter(val) : this.list.slice()); changed to this this.filteredList = this.autoComplete.valueChanges.pipe( startWith(null), map(val => val ? this.filter(val) : this.list.slice())); It seems the compiler can't infer type anymore as I get Severity Code Description Project File Line Suppression State

RxJS's share operator behaves differently when complete?

两盒软妹~` 提交于 2019-12-11 11:06:11
问题 I'm struggling with something which I can't understand why it is happening . Looking at this example : const source = Rx.Observable.of(1).share(); source.subscribe(console.log); //1 source.subscribe(console.log); //1 This prints "1" twice. AFAIK share looks at refCount . But if we look at it - refcount should be ZERO here : const source = Rx.Observable.of(1).share(); source.subscribe(console.log); ^-- 1)refCount=1 2)value emitted - closing subscription ( complete) 3)refCount=0 source

Angular 5 nested http client observables return object

五迷三道 提交于 2019-12-11 11:04:09
问题 I am trying to create an observable response where I make one http call and then before returning the response, I make another http call to populate the return object of the first call as shown below. getOrderWithItems(orderId: string, includes: Set<OrderInclude>): Observable<OrderDto> { return this.getOrder(orderId, includes) .map(order => { this.searchItems().subscribe( items => { order.items = items.results; return order; } ) }); } The compiler gives an error: Type 'Observable' is not

In Rxjs is it an anti-pattern if you add a value to an array, and then immediately after emit that array as an observable?

风流意气都作罢 提交于 2019-12-11 10:58:17
问题 In my angular application, I want user to be able to upload few images and then I want to display their preview using subjects and observables. My component.ts file has these properties: uploadPicturesSubject$: Subject<any[]> = new Subject<any[]>(); previewUrls$: Observable<any[]> = this.uploadPicturesSubject$.asObservable(); previewUrls: any[] = []; Then in my event handler for the (change) event (when user uploads photos) I have the following code: ... const reader: FileReader = new

RxJS retry operator with ajax call

Deadly 提交于 2019-12-11 10:48:58
问题 I'm trying to figure out why my use of retry is not working in this example: http://jsbin.com/bobecoluxu/edit?js,output var response$ = Rx.Observable.fromPromise( $.ajax({ url: 'http://en.wikipedia.org/w/api.php', dataType: 'jsonp', data: { action: 'opensearch', format: 'json', search: term } })) .retry(3); I've wrapped the ajax call in an Observable in the searchWikipedia function, but if I try to force the failure of this call by turning off the wifi or throwing an exception by the related

Rx: What are subscriptions and how do subscriptions work?

霸气de小男生 提交于 2019-12-11 10:48:11
问题 I'm learning reactive extensions (rx) in .NET and I'm struggling a little bit with what a "subscription" really is and when it is used. Lets take some sample data, taken from this thread: using System; using System.Reactive.Linq; using System.Threading; namespace ConsoleApp1 { class Program { class Result { public bool Flag { get; set; } public string Text { get; set; } } static void Main(string[] args) { var source = Observable.Create<Result>(f => { Console.WriteLine("Start creating data!");