Skip to content

Instantly share code, notes, and snippets.

@alexfaber2011
Created November 15, 2016 18:15
Show Gist options
  • Save alexfaber2011/6ea661a4e84087e1e82a1a0f4fd0968d to your computer and use it in GitHub Desktop.
Save alexfaber2011/6ea661a4e84087e1e82a1a0f4fd0968d to your computer and use it in GitHub Desktop.
const mapStateToProps = (state: State, ownProps: Object) => {
const scenario = _.find(state.scenarios.value, (scenario: Scenario) => scenario.id === ownProps.params.scenarioId)
// state looks something like this
/**
* {
* results: {
* value: {
* 'fooScenarioId': {
* 'fooActionId: {
* foo: 'bar',
* }
* }
* }
* }
* }
*/
//the result of the _.get(state.results.value, [ownProps.params.scenarioId]) gives me a reference to the object on line 9 (for example).
const scenarioResults = _.get(state.results.value, [ownProps.params.scenarioId])
return {
scenarioName: _.get(scenario, 'name'),
scenarioColor: _.get(scenario, 'color'),
scenarioIconUrl: _.get(scenario, 'icon_url'),
scenarioResults: (scenarioResults || {})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment