Skip to content

Instantly share code, notes, and snippets.

@boo1ean
Created November 10, 2016 15:06
Show Gist options
  • Save boo1ean/6e3f459985c447363af88737b5a56858 to your computer and use it in GitHub Desktop.
Save boo1ean/6e3f459985c447363af88737b5a56858 to your computer and use it in GitHub Desktop.
const EditPage = (props) => {
switch (true) {
case editPlatformNoData(props): return fetchPlatform(props)
case editPlatformHasData(props): return <EditForm onSubmit={props.updatePlatform} initialValues={props.data} />
case newPlatform(props): return <EditForm onSubmit={props.createPlatform} />
case error(props): return <h2>нельзя такое редактировать</h2>
default: throw new Error('Undefined state')
}
function newPlatform (props) {
return !props.params.id
}
function editPlatformNoData (props) {
return !error(props) && props.params.id && !props.data
}
function editPlatformHasData (props) {
return !!props.params.id && props.data
}
function fetchPlatform () {
props.fetchPlatform({ _id: props.params.id })
return <h2>ожидайте</h2>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment