-
-
Save pi0/3f23d5803556de68ce996927bbfaba93 to your computer and use it in GitHub Desktop.
This is what I call clean coding
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
import assert from 'assert'; | |
updateStepFourProps(type, operation, id) { | |
assert(Array.isArray(this.state[type]), `Cannot do operation on type '${type}'`) | |
switch (operation) { | |
case 'add': | |
this.setState({ | |
[type]: this.state[type].concat(id) | |
}) | |
break; | |
case 'remove': | |
this.setState({ | |
[type]: this.state[type].filter(item => item.id !== id) | |
}) | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment