Created
November 11, 2015 15:30
-
-
Save chrisui/5a0ec9c299f29f80f3a2 to your computer and use it in GitHub Desktop.
Redux selector examples
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 Page from 'components/messenger-inbox-page'; | |
import { | |
selectRoutedSupplierThread, | |
selectRoutedSupplierThreadMessages | |
} from 'services/messenger-service'; | |
const selector = createSelector([ | |
selectRoutedSupplierThread, | |
selectRoutedSupplierThreadMessages | |
], ( | |
thread, | |
messages | |
) => ({ | |
thread, | |
messages | |
})); | |
export default connect(selector)(Page); |
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
function reduceMessenger(state, action) { | |
// ... reduce state | |
} | |
/** Select messenger state from our global state tree */ | |
export function selectMessengerState(state) { | |
return state.messenger; | |
} | |
/** Select the thread between routed supplier (:supplierId) and authed team */ | |
export const selectRoutedSupplierThread = createSelector( | |
[selectParams, selectAuthTeamId, selectDenormaliser, selectMessengerState], | |
({supplierId}, teamId, denormalise, messenger) => | |
denormalise(messenger.threads.get(makeThreadKey(supplierId, teamId))) | |
); | |
/** Select the thread messages between routed supplier (:supplierId) and authed team */ | |
export const selectRoutedSupplierThreadMessages = createSelector( | |
[selectRoutedSupplierThread, selectDenormaliser, selectMessengerState], | |
(thread, denormalise, messenger) => | |
(thread && denormalise(messenger.threadMessages.get(thread.id))) || new List() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @chrisui! Thank you for posting this. I am very curious about your
denormalise
function - could you share code/logic/thinking in there?