Skip to content

Commit

Permalink
fix: reset correct product context infos when switching prorduct from…
Browse files Browse the repository at this point in the history
… retail-set to a single product
  • Loading branch information
Eisie96 committed Jan 10, 2023
1 parent 72744de commit f245f07
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions src/app/core/facades/product-context.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ export class ProductContextFacade extends RxState<ProductContext> implements OnD

this.connect(
'hasQuantityError',
this.select('children').pipe(
map(children => Object.values(children)),
skipWhile(children => !children?.length),
map(children => !children.length || children.some(child => child.hasQuantityError)),
distinctUntilChanged()
this.select('sku').pipe(
whenTruthy(),
distinctUntilChanged(),
switchMap(() =>
this.select('children').pipe(
map(children => Object.values(children)),
debounceTime(300),
skipWhile(children => !children?.length),
map(children => !children.length || children.some(child => child.hasQuantityError)),
distinctUntilChanged()
)
)
)
);

Expand All @@ -272,20 +279,27 @@ export class ProductContextFacade extends RxState<ProductContext> implements OnD

this.connect(
'quantity',
this.select('children').pipe(
map(children => Object.values(children)),
skipWhile(children => !children?.length),
map(children =>
children.reduce(
(sum, child) =>
sum +
(Number.isInteger(child.quantity) && !child.hasQuantityError && !child.hasProductError
? child.quantity
: 0),
0
this.select('sku').pipe(
whenTruthy(),
distinctUntilChanged(),
switchMap(() =>
this.select('children').pipe(
map(children => Object.values(children)),
debounceTime(300),
skipWhile(children => !children?.length),
map(children =>
children.reduce(
(sum, child) =>
sum +
(Number.isInteger(child.quantity) && !child.hasQuantityError && !child.hasProductError
? child.quantity
: 0),
0
)
),
distinctUntilChanged()
)
),
distinctUntilChanged()
)
)
);

Expand All @@ -299,11 +313,18 @@ export class ProductContextFacade extends RxState<ProductContext> implements OnD

this.connect(
'hasProductError',
this.select('children').pipe(
map(children => Object.values(children)),
skipWhile(children => !children?.length),
map(children => !children.length || children.some(child => child.hasProductError)),
distinctUntilChanged()
this.select('sku').pipe(
whenTruthy(),
distinctUntilChanged(),
switchMap(() =>
this.select('children').pipe(
map(children => Object.values(children)),
debounceTime(300),
skipWhile(children => !children?.length),
map(children => !children.length || children.some(child => child.hasProductError)),
distinctUntilChanged()
)
)
)
);

Expand Down

0 comments on commit f245f07

Please sign in to comment.