rxjs

How to unit test a function is called correctly after a timer has fired. Angular 7, RXJS 6

余生长醉 提交于 2020-06-29 06:25:12
问题 In my Angular 7 application, I have a service that is used to track active user tasks. In the service, a timer runs every second to check if any tasks still haven't been completed within 30 seconds. If any tasks are found to have expired, the task is emitted via an event emitter on the service to be handled elsewhere. This all works when the app is running in a browser, but when I try to write a unit test to test the behavior in a fakeAsync environment, tick(X) does not advance the time ( or

How can I toggle (start/ stop) an ngrx action?

心已入冬 提交于 2020-06-28 07:39:32
问题 Below is an action that dispatches a load action to the store. The corresponding effect will handle the request and sends back the response items. But What I want is I want to toggle the below action with a button. So if I press start it will start dispatching actions every 1 s and if I press pause, it will pause dispatching and again If I press start it will continue from where it left, and repeats so... How can I toggle such an action? let date = 1587513626000; // date is required because

Testing fail action - marble - ngrx Effects

Deadly 提交于 2020-06-28 05:17:37
问题 I've got an issue testing a failed action on my effects. To give a bit of context here loadProducts effect is executed when the Load action is called. Inside the effect an HTTP request is performed, in case this request is executed successfully the LoadSuccess action is called, otherwise LoadFail is called. Code here bellow @Effect() loadProducts$ = this.actions$.pipe( ofType(productActions.ProductActionTypes.Load), mergeMap((action: productActions.Load) => this.productService.getProducts()

RXJS How do I use the result of one observable in another (and then process those two results together)

自闭症网瘾萝莉.ら 提交于 2020-06-27 16:37:11
问题 A very common problem when using RxJs seems to be to want the result of one or more observables to then use them in subsequent ones. e.g. in pseudo-code (This is not rx or valid js syntax deliberately) var someResult = $observable-A; // wait to complete var finalResult = $observable-B(someResult.aValueINeed); This can be done in an ugly way where you could subscribe to both and call one inside the other.. however, this is very messy and doesn't afford you much flexibility. e.g. (real syntax)

How does RxJS create or simulate asynchronism?

谁说我不能喝 提交于 2020-06-27 15:42:07
问题 I have problems understand the execution model/order of RxJS Observables and Subjects. I read a lot of literature and blog posts about RxJS observables being the better promise since their subscription can be canceled and they can emit multiple results/values via next() . This question might be answered easily but how does RxJS create or simulate asynchronism? Does RxJS Observables wrap around promises and create a sequence of promises to make the code execution asynchronous? Or is it because

Angular 4 - Http request error: You provided 'undefined' where a stream was expected

自闭症网瘾萝莉.ら 提交于 2020-06-24 11:44:05
问题 While trying to do a HTTP Post request I am receiving the following error: auth.service.ts?c694:156 Something went wrong requesting a new password, error message: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. The Http request is preceded by another one, which works perfectly fine. My component calling the service: requestNewPassword(formInput: NgForm) { if(formInput.controls['email'].value != '') this.authService

Angular 2 - Show loading-information when (observableData | async) is not yet resolved

旧巷老猫 提交于 2020-06-24 08:12:12
问题 just as the title says, I want to embrace the power of rxjs Observables. What I do now: // dataview.html <div *ngIf="isLoading">Loading data...div> <ul *ngIf="!isLoading"> <li *ngFor="let d of data">{{ d.value }}</li> </ul> // dataview.ts data: any[] = []; isLoading: boolean = false; getData() { this.isLoading = true; this._api.getData().subscribe( data => { this.data = data; this.isLoading = false; }, error => { this.error = error; this.isLoading = false; }); } What I want to do: 1. Use

Angular 2 - Show loading-information when (observableData | async) is not yet resolved

我的未来我决定 提交于 2020-06-24 08:12:01
问题 just as the title says, I want to embrace the power of rxjs Observables. What I do now: // dataview.html <div *ngIf="isLoading">Loading data...div> <ul *ngIf="!isLoading"> <li *ngFor="let d of data">{{ d.value }}</li> </ul> // dataview.ts data: any[] = []; isLoading: boolean = false; getData() { this.isLoading = true; this._api.getData().subscribe( data => { this.data = data; this.isLoading = false; }, error => { this.error = error; this.isLoading = false; }); } What I want to do: 1. Use

Angular6 - Prod build fails to access

房东的猫 提交于 2020-06-17 13:24:10
问题 I'm converting my angular6 app to a pwa and facing some troubles. When I run the app with ng serve, everythings works fine. When I publish the app or run with ng serve --prod, the app open but fails to load the login screen with an error in the console "ReferenceError: Subscription is not defined". The error is comming from "SubjectSubscription.js.pre-build-optimizer.js" here is my tsconfig.json { "compileOnSave": false, "compilerOptions": { "moduleResolution": "node", "target": "es6",

Angular6 - Prod build fails to access

↘锁芯ラ 提交于 2020-06-17 13:24:06
问题 I'm converting my angular6 app to a pwa and facing some troubles. When I run the app with ng serve, everythings works fine. When I publish the app or run with ng serve --prod, the app open but fails to load the login screen with an error in the console "ReferenceError: Subscription is not defined". The error is comming from "SubjectSubscription.js.pre-build-optimizer.js" here is my tsconfig.json { "compileOnSave": false, "compilerOptions": { "moduleResolution": "node", "target": "es6",