Last active
April 20, 2018 18:04
-
-
Save tastycode/e5aad4ad300a38ab252eb0da3d1d5c30 to your computer and use it in GitHub Desktop.
Auto generated action creators
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
// 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