Created
November 23, 2015 16:25
-
-
Save fairchild/35b6e8235ff029747c3b 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
import { createSelector } from 'reselect'; | |
import _ from 'lodash'; | |
const contractDataSelector = state => state.contracts.data; | |
const currentContractIdSelector = state => state.contracts.currentId; | |
const contractSelectors = { | |
contracts() { | |
createSelector([contractDataSelector], | |
(data) => data) | |
}, | |
contractsGroupedByCommodity() { | |
createSelector([this.contracts], | |
(items) => _.groupBy(items, item => item.commodity.id) | |
)}, | |
purchaseContractsGroupedByCommodity() { | |
createSelector([contractDataSelector], | |
(items) => { | |
debugger | |
let results = _.chain(items) | |
// .filter(contract => contract.kind === 'Purchase') | |
.groupBy(contract => contract.commodity.id) | |
console.debug(' selector results :', results ); | |
return results; | |
} | |
)}, | |
currentContract() { | |
createSelector([currentContractIdSelector, this.contracts], | |
(items, id) => { | |
if (items && id) { | |
return items[id] | |
} | |
}) | |
}, | |
} | |
export default contractSelectors; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment