rxjs

Implementing Session Timeout service for Ionic/Angular, with Timer Reset with each new user interaction

帅比萌擦擦* 提交于 2021-02-10 20:36:55
问题 I'm trying to adapt some code I've created for a session timeout. Whenever a user interacts with the function, I want to reset the timer to start counting down again. I'm having difficulty working out how to inject similar code to this example C# code - I'm trying to integrate: var update = new Subject<bool>(); var res = update .Select(x => Observable.Interval(TimeSpan.FromSeconds(10.0))) .Switch(); res .Subscribe(_ => Console.WriteLine("Status sent.")); update.OnNext(true); res .Subscribe(_

How to pass extra parameters to RxJS map operator

妖精的绣舞 提交于 2021-02-10 17:47:46
问题 In an Angular app, I use HttpClient and RxJS operators to make some API calls. For example: return this.httpClient.put(url, JSON.stringify(treeOptions)) .pipe( map(this.extractTreeData), catchError(this.handleError) ); The extractTreeData method basically changes some properties returned by the API: private extractTreeData(res: any) { let apiTree = res.data; // The tree comes inside the 'data' field let newTree : any; try { let str = JSON.stringify(apiTree); str = str.replace(/"children"/g, '

How to dispatch an action with current value of state?

落爺英雄遲暮 提交于 2021-02-10 16:40:02
问题 I have an angular component showing items in a list. Each itemn can be selected and the ids of the selected items will be stored in the state. So my state object looks like this f.e.: { items: Item[]; selected: string[] } Now I got an action called DeleteSelectedAction that gets selected as payload. This action will call some WebAPI using an effect and so on. Now I found two ways how I could do this. First: Select selected from store and subscribe to it and pass the value with the action

RxJS - Using pairwise to confirm and revert input field

 ̄綄美尐妖づ 提交于 2021-02-10 15:41:21
问题 So I'm a little new to observables, I'm struggling with a scenario, and I thought it might be a good candidate for an SO question. Here we go... The scenario is this: I have a drop-down field; when it is changed, I want to check a condition based on the previous and new values of the field request from the user a confirmation if the condition passes, and ... then revert the value of the field if the user did not confirm. Here's the code with comments: ngOnInit(): void { // I am waiting for my

How to share data between non parent-child react components?

孤街醉人 提交于 2021-02-10 12:40:28
问题 The procedure for sharing data between components in a child-parent relationship is well documented and dealt with straightforwardly in the React docs. What is less obvious is the accepted way of how one shares state and arbitrary data between components that do not share a child-parent relationship. Flux is offered as a solution, and in the past I have rolled my own pub/sub system, but still there seems a great divide among reactjs developers in this arena. RxJS has been offered as a

Angular: refresh token only once

最后都变了- 提交于 2021-02-10 06:41:39
问题 I'm using JWT with refresh token strategy as authentication and I have an interceptor in my Angular client that sends the token as a header. I check for expiration before sending, and refresh the token with my refreshToken if needed. The problem is when sending 2 (or more) requests, both trying to refresh the token. I need a function that sends req for refresh token and when called multiple times at once, makes only 1 http req to the server for refresh and returns the new updated token to all

cannot unsubscribe ActionsSubject from ngrx/store

冷暖自知 提交于 2021-02-10 06:32:13
问题 I use ngrx/store to implement login actions which gets date from subscribe to a store. The login component is a modal, when I type a wrong password, I get data.type === 'LOGIN_FAILED' , however, when I close the modal and re-open it, the data action is still LOGIN_FAILED instead of INIT . Therefore, the login actions are not unsubscribe, I tried to manually unsubscribe the subscription, but it does not work. How can I unsubscribe the login actions properly? import { Component, OnInit,

Synchronously process an Observable dependent on another Observable using NGRX & Angular

北城以北 提交于 2021-02-10 06:31:40
问题 ngOnInit(): void { this.store.dispatch(new patients.Load([])); this.patients$ = this.store.select(fromPatients.getAll); this.patients$.map(p =>{ // patients$: Observable<Patient[]>; this.rows = p.map(pat => { //I use this on the front end return { username: pat.username, id: pat.id, hasAlert: this.hasAlerts(pat), //made this an observable for the async pipe in view settings: "Settings" }; }); this.table.recalculatePages(); console.log(this.rows); console.log("This happens first"); })

Angular 2 http - filter the observable before returning it

放肆的年华 提交于 2021-02-08 11:49:26
问题 In service I have this defined: getAllHTTP(): Observable<IUser[]> { return this.http.get(`${this.url}/users`) .map(res => res.json()) .catch(err => Observable.throw(err)); } and in the component: ngOnInit() { const self = this; this._uService.getAllHTTP().subscribe( function (data) { console.log(data); self.listOfUsers = data }, (error) => console.error(error) ); } So now I wanted to filter the data before passing the observable to component and I did this: getAllHTTP(): Observable<IUser[]> {

Angular error handling and logging - Call GlobalErrorHandler's handleError

◇◆丶佛笑我妖孽 提交于 2021-02-08 10:50:56
问题 I'm following an Angular error handling/logging tutorial here: https://www.code-sample.com/2017/09/angular-4-error-handling-and-logging.html My question is - how can I call the handleError method (residing in the global-error-handler.service.ts file, seen in step 3 below) from one of my services? In my ErrorLogService , I'm also instantiating a POST request (with data coming from a component) and using catchError to try and call handleError from global-error-handler.service.ts , but I'm