Merge three asynchronous tasks into a single observable stream

I have 3 different observables that I am using to filter the HTML content.

Here is the TypeScript code snippet:

   fiscalYear$ = this.store$.select(this.tableStoreService.getFiscalYear);
isLoading$ = this.store$.select(this.tableStoreService.tableSelectors.getLoading);
isReportLoading$ = this.store$.select(isReportLoading);

All of these observables return a type of Observable<boolean>.

I then use them in filtering the HTML elements with the [disabled] attribute like so:

<button class="btn btn-primary font-weight-700 font-size-200" [disabled]="(isReportLoading$ | async) || (fiscalYear$ | async) < 2022 || (isLoading$ | async) " (click)="clickExport()">
          {{ 'homepage.export' | translate }}
          <mat-icon class="btn-icon export-icon" svgIcon="export"></mat-icon>
        </button>

I attempted to combine these observables into one using the following approach:

get isExportAvialable$ {
    return combineLatest(this.fiscalYear$, this.isLoading$, this.isReportLoading$, (fiscalYear, isLoading, isReportLoading) => isReportLoading || fiscalYear < 2022 || isLoading);
  }

However, I encountered an error with the condition fiscalYear < 2022.

Can you suggest a way to combine these observables into a single one using asynchronous operations?

Answer №1

To tackle the issue, follow these steps:

fiscalYear$ = this.store$.select(this.tableStoreService.getFiscalYear);
isLoading$ = this.store$.select(this.tableStoreService.tableSelectors.getLoading);
isReportLoading$ = this.store$.select(isReportLoading);
isExportAvailable$ = combineLatest([
    this.fiscalYear$, 
    this.isLoading$, 
    this.isReportLoading$
]).pipe(map(([year, isLoading, isReportLoading]) => return year < 2022 && isLoading && isReportLoading));

Finally, in your template, simply utilize isExportAvailable$ along with the async pipe.

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

Using the Vuex getter to populate a component with data using the v-for directive

I am currently constructing a vue2 component, utilizing a vuex store object. The structure of the component is as follows: <template> <ul id="display"> <li v-for="item in sourceData()"> {{item.id}} </li ...

What is the best way to incorporate external HTML content while ensuring HTML5 compatibility? Exploring the different approaches of using PHP, HTML

While this may seem like a simple task to the experts out there, I have been struggling for over an hour without success... My objective is to use a single footer file and menu file for all my webpages while considering blocking, speed, and other factors. ...

Learn the step-by-step process of graphing equations in React similar to Desmos

I am currently attempting to create a graph of an equation based on user input, similar to how it is done on Desmos () For example While I have come across a function plotting tool at , I have encountered difficulties when trying to plot equations contai ...

What is the best way to show only the weekdays on the x-axis?

My goal is to create a scatter-linked graph using D3.js, showcasing the people count for various shifts on different dates in January 2020. Here is the code snippet I am working with: <!DOCTYPE html> <html lang="en" > <head> & ...

Converting JSON data to an array using an Ajax request

I am currently working on an HTML project where I have the following code: <div id="main"> <div id="blogcont"> <p></p> </div> <button class="nvgt" id="prev" >Previous</button> <button ...

The Angular array stays undefined when JSON data is being passed

I am facing an issue with my API that provides JSON data related to football matches. Even after passing this data to the frontend (angular), I am encountering a problem where the array remains undefined. JSON Data: "match_id":"194200", "country_id":"41" ...

Unusual behavior observed while looping through an HTMLCollection returned by the getElementsByClassName method

After spending some time debugging, I discovered an issue with my function that changes the class of elements to modify their properties. Surprisingly, only specific elements were being affected by this change. It took me a while to troubleshoot and resolv ...

The node sends a request to the API to retrieve data, which is then stored in an array. Subsequently, another request is

var UfcAPI = require('ufc-api'); var ufc = new UfcAPI({ version: '3' }); const fighterIdList = []; function fetchFighterIds() { ufc.fighters(function(err, res) { for (let i = 0; i < res.body.length; i++) { ...

Experiencing an issue in Test Cafe when attempting to click on an invisible link using the Client Function

I need to find a way to click on an invisible button in HTML. I attempted to use ClientFunction, however I encountered an error related to the element. import { Selector,ClientFunction } from 'testcafe'; fixture('Clicking Invisible link&apo ...

Ways to quickly terminate a pipeline in a JavaScript transformation

Issue: I am facing a challenge with handling large files (>10GB). At times, I need to process the entire file while other times I only need to sample a few lines. The processing mechanism involves a pipeline: pipeline( inStream, ...

Developing a Next.js application using Typescript can become problematic when attempting to build an asynchronous homepage that fetches query string values

Having recently started delving into the world of React, Next.js, and Typescript, I must apologize in advance if my terminology is not entirely accurate... My current learning project involves creating an app to track when songs are performed. Within the ...

Leveraging google transliteration within a Flex environment

Here is an illustration of how the Google transliteration feature can be utilized in specific HTML textboxes. I am looking to incorporate this same functionality for a Flex application. Is there a method through which this can be achieved? <html> ...

A guide on sending multiple input values using the same class name or id through ajax

My goal is to send multiple input values through AJAX to my PHP script. Everything works smoothly when I use getElementById. However, I have the functionality to add a child. The issue arises when it only retrieves values from the first child while iterati ...

Angular 6 throws an error stating: "The property 'push' cannot be read of null."

The Cart model is defined as follows: //declaring a cart model for products to add export class Cart{ id:string; name:string; quantity:number; picture:string; } Below is the code for my app.service.ts: import { Injectable, Inject } fro ...

Angular is intercepting HTTP subscriptions without finalizing them

Within my code, I have a system in place where an interceptor is triggered to check for HTTP responses with the status code 401. If this code is detected, it initiates a request for a refresh-token by calling the method refreshToken(), before retrying the ...

How can I create a fading trail effect in Three.js that diminishes over time?

I am interested in achieving a similar effect to the example I found on this website: However, my goal is to have the old trail gradually fade into the background over time instead of cluttering the screen with persistent marks. I discovered that by usin ...

Changing table data using a switch in mui-datatables when my information is stored as boolean values

How can I update my boolean data in a Switch component for each row fetched from Firestore? The data is currently being displayed correctly, but when I click on the Switch to change it from true to false or vice versa, nothing happens. Can someone help me ...

Utilizing a Typescript class interface does not maintain the original method types

Struggling to define a Typescript interface and implement it in a class. The issue lies in the method signatures of the interface not being applied to the class as expected. Below is a simplified example: export interface Foo { bar(value: string): voi ...

"Capture input value changes and display the previous value when submitting a post. See an example of

Hi there! I'm facing 2 issues with my code, you can find a DEMO here When adding a product to the sale form, the input field for `description` changes for all products. Changing the input product in the sale does not reflect the change. I have shar ...

Node.js application experiences a delay when calling Mongoose Model.save()

I've been delving into the realms of node and mongo in order to construct a basic web application while also expanding my knowledge on web development. However, I'm encountering an issue when it comes to calling Model.save(); the continuation fun ...