From b5116a2b8283bb9348f7749159b4426a1a5654bf Mon Sep 17 00:00:00 2001 From: ilivanilton Date: Fri, 10 Feb 2023 20:52:00 -0300 Subject: [PATCH] removes product duplication problem --- .../products/product-list-reget/product-reget.service.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/APM-WithExtras/src/app/products/product-list-reget/product-reget.service.ts b/APM-WithExtras/src/app/products/product-list-reget/product-reget.service.ts index d0cf1d19..f0e1ddb9 100644 --- a/APM-WithExtras/src/app/products/product-list-reget/product-reget.service.ts +++ b/APM-WithExtras/src/app/products/product-list-reget/product-reget.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; -import { BehaviorSubject, catchError, combineLatest, combineLatestWith, concatMap, map, merge, Observable, of, scan, shareReplay, Subject, tap, throwError } from 'rxjs'; +import { BehaviorSubject, catchError, combineLatestWith, concatMap, + map, merge, Observable, of, startWith, Subject, tap, throwError } from 'rxjs'; import { Product } from '../product'; import { ProductCategoryService } from '../../product-categories/product-category.service'; @@ -23,10 +24,7 @@ export class ProductRegetService { products$ = this.productsSubject.asObservable(); // Action Stream for adding/updating/deleting products - private productModifiedSubject = new BehaviorSubject>({ - item: this.emptyProduct, - action: 'none' - }); + private productModifiedSubject = new Subject>(); productModifiedAction$ = this.productModifiedSubject.asObservable(); // Save the product via http @@ -35,6 +33,7 @@ export class ProductRegetService { this.products$, this.productModifiedAction$ .pipe( + startWith({item: this.emptyProduct,action: 'none'} as Action), concatMap(operation => this.saveProduct(operation)), concatMap(() => this.getProducts()) ));