Last active
February 28, 2018 15:02
-
-
Save fabriziomoscon/12b024b0e53ae2bcc45bfe75e4c326cb to your computer and use it in GitHub Desktop.
checking the validity of collectionVolume in an imperative way
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
// @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