Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: integrate debounce to qty inputs #55

Closed
wants to merge 1 commit into from

Conversation

nedu64
Copy link
Contributor

@nedu64 nedu64 commented Nov 15, 2024

Attempted fix for debouncing qty inputs

Notes for Review

  • For some reasons i can't seem to decipher why i can't access this.qty in the callback function passed to the debounce function:
function debounce(fn, delay) {
	let timeout;
	return function (...args) {
		clearTimeout(timeout);
		// We have access to this
		console.log(this);
		timeout = setTimeout(() => fn.apply(...args), delay);
	};
}

const LineItem = (props) => {
	return {
		qty: props.qty
		input: debounce(() => {
			// this is undefined
			this.qty = this.qty.replace(/\D/g, '');

			if(this.qty) {
				this.updateQty();
				console.log('update quantity');
			}
		}, 700),
}

This debounce function works in terms of the 700ms delay after every input, however, i can't access this.qty as stated above

All i've tried so far always leads me back to this point, currently out of ideas on what to try next

@nedu64 nedu64 marked this pull request as draft November 15, 2024 04:47
@johnnynotsolucky johnnynotsolucky deleted the feat/integrate-debounce-to-qty-inputs branch February 28, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants