Skip to content

Commit 63d7e27

Browse files
committed
Use a different convention for colocating reducers with selectors
1 parent 9f03794 commit 63d7e27

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

examples/shopping-cart/reducers/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { combineReducers } from 'redux'
2-
import { default as cart, getQuantity, getAddedIds } from './cart'
3-
import { default as products, getProduct } from './products'
2+
import cart, * as fromCart from './cart'
3+
import products, * as fromProducts from './products'
44

55
export function getTotal(state) {
6-
return getAddedIds(state.cart).reduce((total, id) =>
7-
total + getProduct(state.products, id).price * getQuantity(state.cart, id),
6+
return fromCart.getAddedIds(state.cart).reduce((total, id) =>
7+
total + (
8+
fromProducts.getProduct(state.products, id).price *
9+
fromCart.getQuantity(state.cart, id)
10+
),
811
0
912
).toFixed(2)
1013
}
1114

1215
export function getCartProducts(state) {
13-
return getAddedIds(state.cart).map(id => Object.assign(
16+
return fromCart.getAddedIds(state.cart).map(id => Object.assign(
1417
{},
15-
getProduct(state.products, id),
18+
fromProducts.getProduct(state.products, id),
1619
{
17-
quantity: getQuantity(state.cart, id)
20+
quantity: fromCart.getQuantity(state.cart, id)
1821
}
1922
))
2023
}

0 commit comments

Comments
 (0)