Created
September 6, 2019 21:27
-
-
Save ralfting/b546d41c81bf3c96064c53b456a39a2c to your computer and use it in GitHub Desktop.
This file contains 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
onChange = async ({ target: { value } }: SyntheticEvent<HTMLInputElement>): Promise<void> => { | |
if (value === this.props.value) return; | |
const { executeMutation, cardId, id: fieldId } = this.props; | |
const mutationVars = { variables: { cardId, fieldId, value } }; | |
if(this.state.lastUpdate) this.state.lastUpdate.cancel(); | |
const TIME_DEBOUNCE = 500; | |
const debounced = debounce(async () => { | |
try { | |
const mutationRequest: MutationResultProps = await executeMutation(mutationVars); | |
return this.handleRequest(mutationRequest); | |
} catch (e) { | |
handleErrorMessages({ message: t('errors.500') }); | |
return; | |
} | |
}, TIME_DEBOUNCE); | |
this.setState({ value, lastUpdate: debounced }); | |
debounced(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment