Skip to content

Instantly share code, notes, and snippets.

@ralfting
Created September 6, 2019 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfting/b546d41c81bf3c96064c53b456a39a2c to your computer and use it in GitHub Desktop.
Save ralfting/b546d41c81bf3c96064c53b456a39a2c to your computer and use it in GitHub Desktop.
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