Tapping to trigger an action as a side effect is failing to function as expected

I am currently polling for the status of a process. My goal is to continue polling until I receive a status from the server that is not marked as IN_PROGRESS. At the same time, I want to update the status of the process in my store. Below is how I have been approaching this task:

pollForProcessStatusEffect = createEffect(() => 
      this.actions$.pipe(
        ofType(MigrationActions.importInProcess),
        switchMap((payload) => 
          this.pollForProcessStatus(payload.importedFileId).pipe(
            map(data => MigrationActions.importProcessFinished(data.status)),
            catchError(() => of(MigrationActions.importInProcess(payload.importedFileId)))
          )
        )
      )
  );

private pollForProcessStatus(importedFileId: number): Observable<ImportFileProcessStatus> {
    return timer(0, 2000).pipe(
      concatMap(() => this.apiClient.getImportProcessStatus(importedFileId)),
      tap((importFileProcessStatus: ImportFileProcessStatus) =>
        // This action won't be dispatched:
        MigrationActions.importStatusUpdated(importFileProcessStatus)
      ),
      takeWhile((importFileProcessStatus: ImportFileProcessStatus) =>
        importFileProcessStatus.status === FileStatus.IN_PROGRESS, true
      ),
      takeLast(1)
    );
  }

I've observed that the importStatusUpdated action is not being triggered. I'm unsure if there's an issue with my approach.

Answer №1

To properly dispatch an action, you must not only create it but also execute the dispatch method as shown below:

this.store.dispatch(MigrationActions.importStatusUpdated(importFileProcessStatus))           

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

Svelte with Typescript: Uncovering the Types of Props

Issue: I am trying to create a function that can take a component as the first argument and its props as the second argument in a generic manner import Modal from "./Modal.svelte"; function openModal(component: typeof Modal, componentProps: ...

How to retrieve the value of an input field in Angular from a different element

I have a mat-table where each row contains a mat-slide-toggle and a button. I am looking for a way to pass the value of the mat-slide-toggle to the button's click function as an argument. <ng-container matColumnDef="show waiting list"> <ma ...

TestingCompilerFactory is not available as a provider

Currently troubleshooting my test file to identify the issue that is hindering a successful test run: import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Component, Directive, Input, OnInit } from '@angula ...

Filtering Columns in Angular2 DataTable

Is there a way to filter an entire column, including the header and data, using Angular2 data-table? I have figured out how to filter the column data, but the header remains unaffected: https://stackblitz.com/edit/data-table-filter-columns UPDATE: Afte ...

Having trouble importing d3.js and typescript in IntelliJ?

Encountering errors in browsers' console when utilizing d3.select() in typescript code. Despite trying alternative methods like d3-timer.now(), the issue persists. As a newcomer to typescript, I am utilizing intelliJ Ultimate 2019.1. Through npm, I h ...

Angular 2 is unable to locate the module '@angular/core' and is throwing an error

After following the Angular2 quick start guide to set up my project, I encountered a persistent error when running the "tsc -w" command in the command line: app/components/company/company.ts(1,36): error TS2307: Cannot find module '@angular/core&apos ...

Combining Typescript interfaces to enhance the specificity of a property within an external library's interface

I have encountered a scenario where I am utilizing a function from an external library. This function returns an object with a property typed as number. However, based on my data analysis, I know that this property actually represents an union of 1 | 2. Ho ...

Exploring end-to-end testing with NestJS and Guards

I'm trying to test an endpoint called /users using nestjs, but I encountered some errors. I'm unsure how to fix the issues and make the test pass with a guard. First Issue Nest is unable to resolve dependencies of the UserModel (?). Please en ...

An onClick event is triggered only after being clicked twice

It seems that the onClick event is not firing on the first click, but only works when clicked twice. The action this.props.PostLike(id) gets triggered with a delay of one click. How can I ensure it works correctly with just one click? The heart state togg ...

Define the base URL for the Angular ClientApp hosted by the ASP.NET Core WebApi

After setting up an ASP.NET Core project that serves an Angular app using various methods like services.AddSpaStaticFiles(), app.UseSpaStaticFiles(), and app.UseSpa(), I encountered a challenge. The issue is that the application is currently being served ...

Creating a factory method within a parent class to generate instances of child classes

I am in the process of implementing a generic factory method on my base class that can create instances of any of the descendant classes, without the base class being aware of all the descendants. My current approach generates functional JS code, but... ...

Obtaining child component references in Angular using @ViewChildren

Currently, I am generating several ModuleItemComponents by utilizing the following Angular syntax: <div #moduleItems *ngFor="let module of seriesItem.modules; let i = index"> <app-module-item [videoModule]="module" >< ...

You cannot use 'ReactPlayer' as a JSX element

I'm currently facing an issue with my React project where I am trying to integrate react-player. In my TypeScript setup, I encountered the following error during the build process: 'ReactPlayer' cannot be used as a JSX component. Its instan ...

Is it possible to dynamically retrieve an element's style from @ViewChild in an Angular 2 component without needing an active approach?

For instance, there's an element in the template that uses a local variable #targetElement to retrieve its current width whenever needed. However, I prefer not to calculate the style programmatically. I attempted using a setter with the @ViewChild ann ...

What could be causing the lack of reflection of Angular changes in the browser post-build process?

I'm having trouble seeing changes reflected in my Angular project after making them. I've tried clearing the cache pages and cookies in Chrome, as well as enabling disable cache in the network tab of developer tools. In addition, I cleared the a ...

Error in Vue & TS: Property does not exist

Currently working with Vue.js and TypeScript, I've managed to create a DatePicker. However, I'm facing issues when trying to build the project due to TypeScript errors. Below is a snippet from my DatePicker TypeScript file: import Vue from " ...

Utilizing Angular 2+: How to Retrieve Query Parameters in a Route Transition, Not the Currently Active Route

Issue: I am facing a challenge in accessing query parameters that a route guard is checking, rather than the query parameters of the current URL snapshot. The ActivatedRoute only displays the current route status, not the route in transit. For example, wh ...

Deactivate the button until the input meets validation criteria using Angular

What I'm trying to achieve is to restrict certain input fields to only accept integer or decimal values. Here's the code snippet that I currently have: <input type="text" pattern="[0-9]*" [(ngModel)]="myValue" pInputText class="medium-field" ...

When I switch fields or lose focus, react-select unfortunately erases the value I have typed

As a newcomer to React, I am currently developing a typeahead component using the react-select library. The main functionality involves asynchronously fetching suggested options based on the user's input. However, I encountered an issue where if I typ ...

Tips for assigning a value to a Reactive Form control within Angular 6

I am looking to dynamically set the value of a text box when clicking on a button that is located outside of the form. How can I achieve this? <form [formGroup]='student' (ngSubmit)='click()'> <input type='text' form ...