Skip to content

Instantly share code, notes, and snippets.

@zerkalica
Last active August 29, 2015 14:28
Show Gist options
  • Save zerkalica/6b78836b5103fe1a4b7a to your computer and use it in GitHub Desktop.
Save zerkalica/6b78836b5103fe1a4b7a to your computer and use it in GitHub Desktop.
export function killEvent(fn) {
return function _killEvent(event) {
event.preventDefault()
event.stopPropagation()
return fn(event)
}
}
export function onChangeEvent(cb, isEnabled = true) {
return function onChangeEventHandler(e) {
if (cb && isEnabled) {
e.preventDefault()
e.stopPropagation()
return cb(e.currentTarget.value)
}
}
}
export function onKey(cb, key) {
return function onKeyHandler(e) {
if (cb && e.key === key) {
e.preventDefault()
e.stopPropagation()
cb(e)
}
}
}
export function onKeyEnter(cb) {
return onKey(cb, 'Enter')
}
export function onKeyEsc(cb) {
return onKey(cb, 'Escape')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment