Skip to content
Advertisement

Tag: rxjs

How to keep shareReplay alive when there are no subscribers?

I need to share a hot Observable between multiple subscribers and emit the latest value to new subscribers. I am trying to achieve this with shareReplay(1), however, the first subscriber fails to retrieve the latest value because the shareReplay operator doesn’t do anything when there is no subscription, so it doesn’t store anything for the first subscriber. How do I

Return forkJoin selectively

I have a case where an application should return menu based on given context. Below are the sources of menuA and menuB. Given my limited knowledge and experience on rxjs, I was hoping something like the snippet below can accept a string of menuA or menuB to return an observable of the required menu: The above invokes warning as below:

Managing promises in RXJS observables

I’ve poked about SO and found many similar questions/answers but I may be missing something in my basic understanding on how to work with with this stack. I’m working on a react native project along with RXJS/obervables. At some point I doing file downloads, this part is not a problem. A combo of pre-existing axios-rxjs and react-native-file-system get me where

.toPromise() and lastValueFrom() in rxjs

I have this observable I call it with .toPromise() is deprecated, so I would like to change the call with lastValueFrom(): but I receive the following error: UPDATE: for now, resolved with: but is there a better solution? Answer Is there a better solution? Yes and no. In your case mergeMap(_ => EMPTY) will ensure that your observable completes without

Passing pipeline item to promise argument in `takeUntil`

I have code with a similar control flow to this example (obviously, the predicate below doesn’t need to be async, but it’s an example): But this throws a TypeError with the message “You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.” I’ve tried making predicate a promise (new Promise(…), and using takeWhile in place of takeUntil but neither

RxJS observable of results from chain of functions

I have a function getC which depends on the output of getB which depends on the output of getA. I want to create an observable stream, so that when I subscribe to it I get the output of each function, as shown in the snippet. Is there an operator in RxJS that will give me the same behaviour as in

Cannot finish a race with timer in RxJS

Code above will output 2. If I have an action that I try to repeat until condition is met but ignore it if it takes too long, then I take an approach in this answer https://stackoverflow.com/a/51644077 The problem is that race never finishes with the shortest function. The longActionObservable repeats until the condition is met and empty() is called. This

Create Custom Rxjs Observable for network

I’m a beginner with Rxjs, I’m working on a game project have a network implement is: Send by function sendPacket, and server response comes in fuction onReceived I want to refactor the current network struct like Angular HttpClient: sendPacket return an Observable and I just need subscribe like this: How can I implement this idea? Thank you so much Answer

RxJS: Modify Observable array before subscribing

I’m fetching data (students via getStudents()) from an API which returns an Observable. Within this result I need to get data from two different tables and combine the result. Here are my simplified interfaces: I now need to fetch all students and add the respective school and classroom for each student via the foreign keys school_id and classroom_id. My current

Advertisement