Skip to content

Instantly share code, notes, and snippets.

@tastycode
Last active April 20, 2018 18:04
Show Gist options
  • Save tastycode/e5aad4ad300a38ab252eb0da3d1d5c30 to your computer and use it in GitHub Desktop.
Save tastycode/e5aad4ad300a38ab252eb0da3d1d5c30 to your computer and use it in GitHub Desktop.
Auto generated action creators
// types.js
const REPORTER_PENDING_REPORT_UPDATE = "[reporter] pending report update"
// actions/reporter.js
const simpleActionCreatorProxy = new Proxy(module.exports, {
get (target, key) {
const actionName = camelToUnderscore(key).toUpperCase()
if (key in target) {
return target[key]
} else if (actionName in types) {
return () => ({
type: types[actionName]
})
} else {
throw new Error(`Undefined action creator '${key}' invoked`)
}
}
})
export default simpleActionCreatorProxy
// components/PromptHarm.js
import reporterActions from 'actions/reporter'
const PromptHarm = ({reporterPendingReportUpdate}) => ( <PromptContainer>
<PromptText>Is anyone at risk of immediate harm to themselves or others?</PromptText>
<PromptButtonsContainer>
<PromptButton onPress={reporterPendingReportUpdate} text="YES"/>
<PromptButton text="CANCEL"/>
</PromptButtonsContainer>
</PromptContainer>
)
connect(bindStateToProps, {reporterPendingReportUpdate: reporterActions.reporterPendingReportUpdate)(PromptHarm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment