Skip to content

Instantly share code, notes, and snippets.

@fabriziomoscon
Last active February 28, 2018 15:02
Show Gist options
  • Save fabriziomoscon/12b024b0e53ae2bcc45bfe75e4c326cb to your computer and use it in GitHub Desktop.
Save fabriziomoscon/12b024b0e53ae2bcc45bfe75e4c326cb to your computer and use it in GitHub Desktop.
checking the validity of collectionVolume in an imperative way
// @flow
const MAX_VOLUME = 100
type CollectionState = {
volume: number,
}
function getCollectionVolume(data: CollectionState): number {
if (data && data.volume) {
return data.volume
}
return 0
}
const collectionVolume = getCollectionVolume(data)
// ATTENTION => perform this check any time you want to use the volume
if (collectionVolume === 0) {
// undefined
} else if (collectionVolume > MAX_VOLUME) {
// display error
}
// collectionValue is the volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment