File

src/app/cart/cart-data/reducers/cart-status.reducer.ts

Index

Properties

Properties

bookIds
bookIds: number[]
Type : number[]
import { createReducer, on, Action } from '@ngrx/store'

import * as cartActions from '../actions/cart.actions'

export interface State {
  bookIds: number[]
}

export const initialState: State = {
  bookIds: []
}

const cartStatusReducer = createReducer(
  initialState,
  on(
    cartActions.addBookToCart,
    (state, { bookId }) => ({...state, bookIds: [...state.bookIds, bookId]})
  ),
  on(
    cartActions.removeBookFromCart,
    (state, { bookId }) => ({...state, bookIds: state.bookIds.filter(id => id !== bookId)})
  ),
  on(
    cartActions.clearCart,
    state => ({...state, bookIds: []})
  )
)

export function reducer(state: State | undefined, action: Action) {
  return cartStatusReducer(state, action)
}

result-matching ""

    No results matching ""