Last active
July 2, 2019 14:57
-
-
Save happymishra/ed47cfa8f8c6705ea5eb454b32b66a1a 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
<html> | |
<body> | |
<label>Search</label> | |
<!-- Renders an HTML input box --> | |
<input type="text" id="search-box"> | |
<p>No of times user actually clicked</p> | |
<p id='show-api-call-count'></p> | |
</body> | |
<script> | |
var searchBoxDom = document.getElementById('search-box'); | |
function makeAPICall() { | |
// This represents a very heavy method. Which takes a lot of time to | |
// execute | |
} | |
// Event listener on the input box | |
searchBoxDom.addEventListener('input', function () { | |
var apiCallCountDom = document.getElementById('show-api-call-count'); | |
var apiCallCount = apiCallCountDom.innerHTML || 0; | |
apiCallCount = parseInt(apiCallCount) + 1; | |
// Updates the number of times makeAPICall method is called | |
apiCallCountDom.innerHTML = apiCallCount; | |
// A very heavy method which takes a lot of time to execute | |
makeAPICall() | |
}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment