Skip to content

Commit

Permalink
fix: unnecessary emissions of the getCurrentBasket selector ... (#1234)
Browse files Browse the repository at this point in the history
fix: unnecessary emissions of the getCurrentBasket selector if the basket loading state changes

Co-authored-by: Danilo Hoffmann dhhyi@aol.com
  • Loading branch information
SGrueber authored Aug 4, 2022
1 parent 2bd2e72 commit d22ba7d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/app/core/store/customer/basket/basket.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import { BasketView, createBasketView } from 'ish-core/models/basket/basket.mode
import { getCustomerState } from 'ish-core/store/customer/customer-store';
import { getLoggedInCustomer } from 'ish-core/store/customer/user';

import { BasketState } from './basket.reducer';

const getBasketState = createSelector(getCustomerState, state => state?.basket);

export const getBasketValidationResults = createSelector(getBasketState, (basket): BasketValidationResultType => {
const getInternalBasket = createSelector(getBasketState, basket => basket.basket);

export const getBasketValidationResults = createSelectorFactory<object, BasketValidationResultType>(projector =>
resultMemoize(projector, isEqual)
)(getBasketState, (basket: BasketState): BasketValidationResultType => {
if (!basket || !basket.validationResults) {
return;
}
Expand All @@ -33,10 +39,10 @@ export const getBasketValidationResults = createSelector(getBasketState, (basket
export const getBasketInfo = createSelector(getBasketState, basket => basket.info);

export const getCurrentBasket = createSelector(
getBasketState,
getInternalBasket,
getBasketValidationResults,
getBasketInfo,
(basket, validationResults, basketInfo): BasketView => createBasketView(basket.basket, validationResults, basketInfo)
(basket, validationResults, basketInfo): BasketView => createBasketView(basket, validationResults, basketInfo)
);

export const getSubmittedBasket = createSelector(
Expand Down

0 comments on commit d22ba7d

Please sign in to comment.