Last active
March 21, 2017 08:39
-
-
Save nicoespeon/f78c4e2ea06923684f2687b9d409d72f to your computer and use it in GitHub Desktop.
Blog - Using Observables to make our app work with barcode scanners
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
const ENTER_KEY_CODE = 13 | |
let keyCodesBuffer = [] | |
document.addEventListener("keypress", (event) => { | |
const keyCode = event.keyCode | |
if(keyCode === ENTER_KEY_CODE) { | |
fillInputWithKeyCodesBuffer() | |
cleanBuffer() | |
} else { | |
addToBuffer(keyCode) | |
} | |
}) | |
function fillInputWithKeyCodesBuffer() { | |
// … | |
} | |
function cleanBuffer() { | |
keyCodesBuffer = [] | |
} | |
function addToBuffer(keyCode) { | |
keyCodesBuffer.push(keyCode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment