rxjs-pipeable-operators

Angular/RxJS update piped subject manually (even if no data changed), “unit conversion in rxjs pipe”

ε祈祈猫儿з 提交于 2021-01-29 14:30:55
问题 I am working on an app using Angular 9 and RxJS 6.5. The functionality I have problems with uses Angular services to fetch some data from a server and provides this data to views (using RxJS behaviorSubjects). Before passing that data to the views though, I want to do some unit conversion, so that the user can use a toggle/switch to change between two units for the entire app, specifically "metric tons" and "short tons". While the actual conversion functions are provided within a dedicated

How to reset a RXJS scan operator based on another Observable

主宰稳场 提交于 2021-01-20 04:13:53
问题 I have a component which triggers an onScrollEnd event when the last item in a virtual list is rendered. This event will do a new API request to fetch the next page and merge them with the previous results using the scan operator. This component also has a search field which triggers an onSearch event. How do I clear the previous accumulated results from the scan operator when a search event is triggered? Or do I need to refactor my logic here? const loading$ = new BehaviorSubject(false);

How to reset a RXJS scan operator based on another Observable

走远了吗. 提交于 2021-01-20 04:11:26
问题 I have a component which triggers an onScrollEnd event when the last item in a virtual list is rendered. This event will do a new API request to fetch the next page and merge them with the previous results using the scan operator. This component also has a search field which triggers an onSearch event. How do I clear the previous accumulated results from the scan operator when a search event is triggered? Or do I need to refactor my logic here? const loading$ = new BehaviorSubject(false);

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)

What is the difference between throttleTime vs debounceTime in rxjs and when to choose which?

会有一股神秘感。 提交于 2019-12-22 08:51:35
问题 I'm trying to understand throttleTime vs debounceTime and which one is to be used when? I have an upvote button that makes an API request to the backend (which counts the votes). User can submit button multiple times, but I'd like to limit the times per second button can be pressed. I know throttleTime and debounceTime operators can do that, but which should I choose better? const upvoteClicks = fromEvent(this.el.nativeElement, 'click') .pipe(debounceTime(500)) .subscribe(() => this.myService

Observable and how to control results pace

喜夏-厌秋 提交于 2019-12-12 17:51:06
问题 I am looking for an operator that would help me pace the results emitted from an observable, it would look like this : [--A-BC--D-E----------------] [--A----B----C----D----E----] I tried AuditTime() but it does not replay the results that was emitted between intervals, it does something like this : [--A-BC--D-E----------------] [--A----C----E--------------] Thanks for your help. 回答1: I think this should do what you need: const e1 = cold('--A-BC--D-E----------------|'); const expected = '--A--

Queuing function using RxJS

萝らか妹 提交于 2019-12-11 16:36:55
问题 I'm using rxjs with NodeJS in backend. I have a Rest API which allow consumers to run remote yarn installation process. The install function returns an observable of the process. So when the module is installed successfully it emits a value in the observable and complete. At this point, the Rest API will returns a response to the user to say that the installation is successful. In case that the installation fails, the process will throw an Error in the stream and the Rest API returns another