rxjs6

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

break up buffer into size rxjs

大城市里の小女人 提交于 2019-12-11 06:37:28
问题 I have an observable get data from stream each time at size 512 each next I have to break it up to 200 char at other observable and keep [12] char in other buffer to concatenate with next block, I solve it by using new subject and for loop, I believe there maybe a better, more pretty solution. received Observable ---------------------------------------- 1st next [512] -------> [112] [200] [200] -------> [200] [200] 2nd next [512][ 112 ] --> [24][200][200] [88+ 112 ] --> [200] [200] 3rd next

How to refactor a subscribe inside a subscribe in rxjs

左心房为你撑大大i 提交于 2019-12-11 06:20:00
问题 For example: this.saveSubscription$ = this.ds.onSave$.subscribe(x => this.sb.updateMachineTool(this.viewEditModel.viewEditModel).subscribe(x = { console.log('alert results', x) }) ) this.ds.onSave$ is a subject that triggers when a save button on a different component is clicked. this.sb.updateMachineTool is an httpClient post that updates a specific tool should I be using some type of map so i'm not subscribing to both areas? How can I refactor this code? 回答1: To Refactor your code You can

rxjs - combining inner observables after filtering

跟風遠走 提交于 2019-12-11 05:23:40
问题 I call backend that respond with: [ "https://some-url.com/someData1.json", "https://some-url.com/someData2.json" ] Each JSON can have following schema: { "isValid": boolean, "data": string } I want to get array with all data, that have isValid is set to true backend.get(url) .pipe( mergeMap((urls: []) => urls.map((url: string) => backend.get(url) .pipe( filter(response => response.isValid), map(response => response.data) ) ) ), combineAll() ) When both .json have "isValid" set to true, I get

Should the Rxjs 6 filter operator work on the return from a map operator?

给你一囗甜甜゛ 提交于 2019-12-11 04:59:55
问题 I had the following function: Original Function public FindCertType(CertTypeID: string) : Observable<ICertType> { console.log("... FindCertType in Model-tools.service called ..."); return this.GetCertTypes() .pipe( map((CertTypeMap: IResponseObject<ICertType>) => { return CertTypeMap.Array }), filter((CertType: ICertType ) => CertType.Id === CertTypeID)[0] ) } This code resulted in the following error: Console Error ... ShowCertType called ... new-bcaba.component.ts:27 ... GetCertType in

How can I avoid multiple nested subscriptions using RxJS operators?

风格不统一 提交于 2019-12-10 17:47:13
问题 I am working on a file encryption and upload class using Angular. Many of these operations are async and therefore the methods I wrote are returning RxJS Observables. // 1. private prepareUpload(file): Observable<T>; // 2. private encryptData(data, filekey): Observable<T> // 3. private uploadEncryptedData(formData, token, range): Observable<T> // 4. private completeUpload(updatedFilekey, token): Observable<T> I want to encapsulate this logic in a public upload(file) method and I ended up

Jest not handling errors from expect() in subscribe() of RxJS observable

╄→гoц情女王★ 提交于 2019-12-10 17:08:00
问题 I've been trying to get Jest working with RxJS and am having trouble with Jest not propagating errors from inside the subscribe callback. Here is a sample test I've tried that is not working: import {of} from 'rxjs'; test('should fail', () => { of(false).subscribe(val => { expect(val).toBe(true); }); }); The above test should fail, but it passes. I've googled around and found the following solution: Failing expect() inside subscribe() does not mark test as invalid This suggests using the

RxJS - How to share the output of an expensive observable but rerun that observable if its requested again after N seconds?

孤街浪徒 提交于 2019-12-10 15:25:05
问题 Let's say we have this global const: const isSignedIn = fromPromise(fetch('/api/is-signed-in')) .pipe(throttleTime(1000), shareReply(1)); After page load, several components will subscribe to this at the same time: isSignedIn.subscribe(() => console.log('do 1st')); isSignedIn.subscribe(() => console.log('do 2nd')); isSignedIn.subscribe(() => console.log('do 3rd')); The above will only call the API once, however i need it to call the API again (ie after 1 second) if another component

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

情到浓时终转凉″ 提交于 2019-12-07 17:04:21
问题 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

Refresh token (JWT) in interceptor Angular 6

被刻印的时光 ゝ 提交于 2019-12-07 11:02:38
问题 Initially, I had a function that simply checked for the presence of a token and, if it was not present, sent the user to the login header. Now I need to implement the logic of refreshing a token when it expires with the help of a refreshing token. But I get an error 401. The refresh function does not have time to work and the work in the interceptor goes further to the error. How can I fix the code so that I can wait for the refresh to finish, get a new token and not redirect to the login