Is there a way to terminate API requests within my ngrx effect?

When working on a single page, I often trigger multiple actions to initiate search requests to the same API endpoint. Within my effects setup, I have an effect specifically for handling these requests. It looks something like this:

    runSearchSuccess$ = createEffect(() =>
    this.actions$.pipe(
            ofType(MyActions.runSearch),
            mergeMap(({searchRequest}) => this.myService.runSearch(searchRequest).pipe(
                map((response) => {
                    return MyActions.runSearchSuccess({ searchResponse: response })
                }),
                catchError(error => {
                    const searchResponse = null;
                    return [
                        MyActions.updateSearchStatuses({searchResponse}),
                    ]
                }),
            )),
        )
    );

However, since these requests can sometimes take a significant amount of time, there is a need to cancel unnecessary ones when user input changes on the page. The relevant data regarding search requests is stored in the state, and I use a selector to retrieve all active requests. My goal is to monitor changes in this selector and cancel any search request that becomes irrelevant. Using TakeUntil doesn't seem feasible as it depends on the selector output. I've also attempted to utilize TakeWhile but haven't found a way to cancel the API call itself, rather than just halting the effect. Is there a way to achieve this using TakeWhile or is there a more effective approach to managing and cancelling active network calls as needed?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Passing a JavaScript Object to an ASP.NET Handler

How can I send a JavaScript object to an ASP.NET Handler and extract its values? I have defined a complex type object as follows: function AccountObjCreate() { var AccountsView = {}; AccountsView.Username = null; AccountsView.Email = null; AccountsView.P ...

How come my Three.js objects are all showing up simultaneously instead of appearing individually?

I'm having trouble switching between two 3D models. After clicking a button on the first page load, I can display either of the objects, but they both end up loading simultaneously when trying to switch between them. Is there a way to solve this issu ...

What steps can I take to troubleshoot issues when creating a React app?

While attempting to set up a react application using npx create-react-app projectreact, I encountered the following error message: PS C:\Users\ahnaa\OneDrive\Documents\Web Developent\Reaact JS> npx create-react-app project ...

Having difficulty grasping the concept of AngularJS Promises

As I deepen my understanding of AngularJS, I find myself faced with the challenge of adapting code examples to fit my own projects. In this particular example sourced from Urish, it is clear that the variable "promise" must encompass the necessary functio ...

Blazor compatibility issue with Bootstrap 5 carousel functionality

Check out the link below to view a carousel that is functioning with the help of jquery and bootstrap 4.3.1 (code lines 48,50). I attempted to switch to using Bootstrap 5 JS files for the carousel, but it did not work as expected due to issues with code li ...

Volta alert: Temporary directory creation failed

Recently, I attempted to globally download and install TypeScript using the npm install -g typescript command in my terminal. Unfortunately, an error occurred: Volta error: Could not create temporary directory in /Users/username/.volta/tmp/image/packages ...

send a parameter to a bootstrap dialog box

It seems like the title of my question is pretty common, but I haven't been able to find a solution that works for my specific issue. I have a Bootstrap template and what I'm trying to do is pass some variables to a modal. Currently, I am using ...

Encountering difficulties in establishing connection between Angular project and .Net API

I have been working on creating a login page using .Net Core Web API and Angular. However, I am encountering an error when trying to call the login method and make the API call upon button click. Below is the code snippet for the API: [HttpGet] [Route(&qu ...

Issue with Angular project: View not being updated when using behaviorSubjects

Within my Angular project, I am retrieving data from an API using a service and storing the data within a BehaviorSubject as shown below private categorySubject = new BehaviorSubject<number | null>(null); apiBehavior = new ReplaySubject<ApiRes ...

Develop a time-sensitive store system using HTML and JavaScript that toggles between open and closed status based on set

I am looking to develop a time-based Open/Closed store using HTML and JavaScript. The concept is that on Fridays, the element with id="friday" should be displayed, otherwise, show the element with id="week". Additionally, if the time i ...

Verify the text file for any data, and if it contains any, display it on the web browser using JavaScript

I have a program in C that works with a temperature sensor. It creates a file to store the temperature and indicates whether it falls within specific values. I want to display this data on a web browser and update it every 5 minutes. I'm looking for ...

Can Angular 2 support the implementation of multiple levels of Nested Routes?

Is it possible to have multiple levels of nesting for Angular routing? I am attempting the following structure but encountering an error message stating [Child routes are not allowed for "/cash/..". Use "..." on the parent's route path]. Intended rou ...

Two components are loaded simultaneously by Angular

I encountered a strange bug in my Angular2 frontend application. After logging in, I see two components appearing simultaneously - the login component and the main component. https://i.sstatic.net/KFH4l.png In the screenshot above, the login functionalit ...

Troubleshooting: Unable to modify value with function in AngularJS

Why can't I change a value using a function in AngularJS? html: <div ng-controler='TestCtrl' id='TestCtrl'> <h1>Test: {{test.name}}</h1> <div ng-hide='showTest'> <div class=&a ...

Creating a dropdown button with three dots in a table row using jQuery

I've been working with tables and I'm trying to create a dropdown list with 3 dots in each table row. I've experimented with a few libraries and custom dropdown options, but none of them seem to be working properly. What I'm looking fo ...

What causes the discrepancy in margin values between desktop and mobile devices?

In my project, I have a collection of div elements that need to be spaced vertically from one another by the height of the window plus an additional 100px. However, I encountered a discrepancy when setting this margin using jQuery between mobile and deskto ...

Is it possible to remove generic T in typescript if the mysql result value is an array but generic T is not an array?

type User = { name: string email: string } This is the code snippet, import type { PoolConnection, RowDataPacket, OkPacket } from "mysql2/promise"; type dbDefaults = RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[]; type dbQuery& ...

Converting Javascript Array to PHP Array: A Step-by-Step Guide

For my web application, I am utilizing PHP and MySql. When inserting a string into Mysql, it is formatted as a JavaScript Array ["0","1","2","3","4","5","6"] After retrieving the value from the database, it is saved in a PHP Variable $dow I am now looki ...

Obtain purified strings from an array of elements

In my collection of objects, there is a specific string mentioned: [ { "id": 2240, "relatedId": "1000" }, { "id": 1517, "relatedId": "100200" }, { "id": 151 ...

Is there a way to deactivate the spin buttons for an input number field?

Is there a way to create an input element with type number in Vue using createElement() in TypeScript and then disable the spin buttons for increment and decrement? I attempted to use the following CSS: input[type=number]::-webkit-inner-spin-button, input ...