Last active
August 29, 2015 14:28
-
-
Save zerkalica/6b78836b5103fe1a4b7a 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
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