Unable to retrieve the previous payload value once mergeMap has been used

Below is the code snippet I am working with:

export const googleTagManagerInternalActionsEpic: Epic<RootAction, RootAction, RootState, Services> = (action$, state$) => {

  return action$.pipe(
    mergeMap(action => merge(
      of(action).pipe(
        filter(isActionOf(triggerGTMEvent)),
        tap(({ payload: eventName }) => {
            console.log(eventName);
        }),
        mergeMap(() => loadQuestion()),
        map(questionImport => questionImport.default),
        tap((question) => {
          console.log(question);
          debugger;
        }),
        ignoreElements(),
      ),
    )),
  );

}

I am trying to access the same value of eventName in the second console.log(...) as I have in the first one. The issue I'm facing here is that the mergeMap I have in between is interfering with the payload propagation. I only introduced that mergeMap to gather information from the loadQuestion() call.

Is there a way for me to retrieve both values successfully?

Thank you!

Answer №1

To utilize the second argument with mergeMap, follow this example:

...
        tap(({ data: item }) => {
            console.log(item);
        }),
        mergeMap(() => fetchData(), (item, result) => ({
          item,
          result
        })),
        map(({ item, result }) => ({
          item,
          updatedResult: result.data
        })),
        tap(({ item, updatedResult }) => {
          console.log(item, updatedResult);
          debugger;
        }),
...

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

Implementing Caching in Angular 5 Services

Searching for the best way to implement Angular services has led me here. The Service: const url = 'http://127.0.0.1:8000/api/brands/' @Injectable() export class BrandService { private brands:Observable<Array<Brand>>; constru ...

Ways to troubleshoot and resolve the npx create-next-app issue

Every time I try to create a new app using npx create-next-app@latest --typescript, it keeps giving me this error message: npm ERR! code ENETUNREACH npm ERR! syscall connect npm ERR! errno ENETUNREACH npm ERR! request to https://registry.npmjs.org/create-n ...

Testing a TypeScript function with Jest by mocking a function that is invoked from a separate file

In my code, there is a function called processCosts located in the file prepareStatement.ts. This function makes a call to another function named calculatePrice, which is imported from coreLogic.ts. Within my test file reports.integration.ts, I have impor ...

Changing the value of an object in Angular can be achieved by utilizing the two

I have a service with the following methods: getLastStatus(id): Observable<string> { let url_detail = this.apiurl + `/${id}`; return this.http.get<any>(url_detail, this.httpOptions).pipe( map(data => { ...

How to transfer a parameter in Angular 2

I am currently facing a challenge in passing a value from the HTML file to my component and then incorporating it into my JSON feed URL. While I have successfully transferred the value to the component and displayed it in the HTML file, I am struggling to ...

Utilizing D3 to fetch geographic data in the form of a TopoJSON file for U.S. counties

After retrieving a set of coordinates, the goal is to use D3 to find the corresponding county from a U.S. TopoJSON file. Here is an example code snippet: navigator.geolocation.getCurrentPosition(function(position) { let coordinates: [number, number] = [p ...

Using the Airbnb style guide in conjunction with NextJS

Incorporating the Airbnb style guide into my NextJS 13.4.9 project is a priority for me. When setting up a NextJS application, the prompt to enable ESLint arises. Opting to say "yes" is typically the recommended approach, as it allows for running npm run l ...

Tips for transfering variables from an electron application to the backend of an Angular project

My goal is to develop a website and desktop application using the same code base. However, due to some minor differences between the two platforms, I need a way for my Angular app to distinguish whether it has been called from the web or from Electron. I& ...

What is the reason for the allowance of numeric keys in the interface extension of Record<string, ...>

I am currently working on a method to standardize typing for POST bodies and their corresponding responses with API routes in my Next.js application. To achieve this, I have created an interface that enforces the inclusion of a body type and a return type ...

Using TypeScript to interpret JSON - insert a 'data' label

Consider the following example of a JSON structure: [ { "id":1, "position":3, "articleNumber":"ServiceElement" }, { "id":2, "position":2, "articleNumber":"ServiceElement" } ] Is there a way to transfo ...

Leveraging TypeScript Declarations for an External JavaScript Library

Struggling to find clear documentation on how to properly use the ALKMaps JavaScript library in my Ionic application. I created a local npm module with an alkmaps.d.ts file, but I can't seem to import it into my Angular code without encountering error ...

What is the best way to configure webpack for ng build instead of ng serve?

My .NET web application is hosted in IIS and it also hosts an Angular application. This setup requires both applications to be served on the same port by IIS, primarily because they share the same session cookie. Additionally, they are integral parts of th ...

Using Angular2 - How to pass the router parameter as a variable in ngForm

Struggling to pass a router param (id) to an ngForm and then to an event emitter. I am able to retrieve the id from the router successfully, but when trying to assign it to my singleOpenHome object, I encounter an undefined error: @Input() singleOpenHome: ...

Angular 5 - Reverting back to the previous state

In my Angular web application, I encounter a scenario where I need to navigate back to the previous state. Let's say I am currently on a page at http://localhost/someURL. On this particular page, users have the ability to search for items and see the ...

Angularjs 2 Error: Unable to access the 'infos' property of an undefined object using the Http Client

I've been working on an AngularJS app for about a week now, developing a backoffice application for my service. My main challenge lies in using data retrieved from a remote server. I have 4 HTTP GET requests in my app - 2 of them fetching lists of us ...

Remove an item from an array within Express using Mongoose

{ "_id": "608c3d353f94ae40aff1dec4", "userId": "608425c08a3f8db8845bee84", "experiences": [ { "designation": "Manager", "_id": "609197056bd0ea09eee94 ...

Tips for utilizing a ternary operator to set a className in an element

I'm in the process of developing a website using React and Next.js. One of the components on my site is section.tsx, which displays a subsection of an article based on the provided props. I'm looking to add an 'align' property to this c ...

Looking for guidance on locating Typescript type definitions?

As a newcomer to Typescript, I have recently delved into using it with React. While I have grasped the fundamentals of TS, I find myself perplexed when it comes to discovering or deriving complex types. For example, in React, when dealing with an input el ...

The current error message is: "ReferenceError: spyOnProperty is not defined

it('needs to be able to update treatment instructions in the user interface', async(() => { const spy = spyOnProperty(appService.treatmentInstruction, 'next', 'get').and.returnValue(treatmentInst); component ...

The "rest" variable is automatically assigned the type of "any" because it lacks a specified type and is used within its own initializer

Attempting to set up a private route using react router 4 and Typescript. Check out the code I'm working with: type CustomRouteProps<T> = T & { component: any, authRequired: boolean }; function PrivateRoute({ component: Component, authRequ ...