Last active
June 22, 2018 09:55
-
-
Save timdeschryver/35bf59b660ae1f0d5d558af4a173ccdd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| export const getCatalogState = createFeatureSelector<fromCatalog.State>('catalog'); | |
| export const getProducts = createSelector( | |
| getCatalogState, | |
| catalog => catalog.products, | |
| ); | |
| export const getProductSkus = createSelector( | |
| getCatalogState, | |
| catalog => catalog.productSkus, | |
| ); | |
| export const getCatalog = createSelector( | |
| getProductSkus, | |
| getProducts, | |
| (skus, products) => skus.map(sku => products[sku]), | |
| ); | |
| export const getCartState = createFeatureSelector<fromCart.State>('cart'); | |
| export const getCartItems = createSelector( | |
| getCartState, | |
| cart => cart.cartItems, | |
| ); | |
| export const getAllCartSummary = createSelector( | |
| getProducts, | |
| getCartItems, | |
| (products, cart): CartItem[] => | |
| Object.keys(cart).map(sku => ({ | |
| product: products[sku], | |
| amount: cart[sku], | |
| })), | |
| ); | |
| export const getCartSummary = createSelector(getAllCartSummary, cart => | |
| cart.filter(item => item.amount > 0), | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment