Skip to content

Instantly share code, notes, and snippets.

@nicoespeon
Last active March 23, 2017 14:16
Show Gist options
  • Save nicoespeon/dfdfd8e568bc9aa02d025b63f912c8fe to your computer and use it in GitHub Desktop.
Save nicoespeon/dfdfd8e568bc9aa02d025b63f912c8fe to your computer and use it in GitHub Desktop.
Blog - Using Observables to make our app work with barcode scanners
const MAX_INTERVAL_BETWEEN_EVENTS_IN_MS = 50
const keyCode$ = Rx.Observable.fromEvent(document, "keypress")
.pluck('keyCode')
const keyCodesBuffer$ = keyCode$
// --(43)-(64)----(32)-----(65)-(77)-(13)--->
.buffer(keyCode$.debounce(MAX_INTERVAL_BETWEEN_EVENTS_IN_MS))
// --([43,64])----([32])-----([65,77,13])--->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment