-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cart): item states get added for a cart retrieval actions (#2799)
- Loading branch information
Showing
3 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libs/cart/state/src/reducers/cart-item-entities/set-state-meta-reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ActionReducer } from '@ngrx/store'; | ||
|
||
import { DaffCart } from '@daffodil/cart'; | ||
|
||
import { | ||
DaffCartItemActionTypes, | ||
DaffCartItemActions, | ||
} from '../../actions/public_api'; | ||
import { daffCartItemsEntityTransform } from '../../helpers/public_api'; | ||
import { DaffCartReducersState } from '../cart-reducers-state.interface'; | ||
|
||
type Reducer<T extends DaffCart = DaffCart> = ActionReducer<DaffCartReducersState<T>, DaffCartItemActions<T>>; | ||
|
||
/** | ||
* A meta reducer for determining and setting the correct `daffState` values on cart items. | ||
*/ | ||
export function daffCartSetItemStateMetaReducer<T extends DaffCart = DaffCart>(reducer: Reducer<T>): Reducer<T> { | ||
return (state, action) => { | ||
switch (action.type) { | ||
case DaffCartItemActionTypes.CartItemAddSuccessAction: | ||
case DaffCartItemActionTypes.CartItemUpdateSuccessAction: | ||
return reducer( | ||
state, | ||
{ | ||
...action, | ||
payload: { | ||
...action.payload, | ||
items: daffCartItemsEntityTransform<T['items'][number]>(state.cartItems.entities, action.payload.items), | ||
}, | ||
}, | ||
); | ||
|
||
default: | ||
return reducer(state, action); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters