@accurat/event-utils
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -46,3 +46,11 @@ function preventingDefault(fn) { | ||
function attachListenersToKeys(keysListenersAssociation) { | ||
return e => { | ||
if (keysListenersAssociation.hasOwnProperty(e.key)) { | ||
return keysListenersAssociation[e.key](e) | ||
} | ||
} | ||
} | ||
module.exports = { | ||
@@ -55,2 +63,3 @@ preventingDefault, | ||
replaceArguments, | ||
attachListenersToKeys, | ||
} |
{ | ||
"name": "@accurat/event-utils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "High order functions to use in React's JSX when working with events", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -57,3 +57,3 @@ # @accurat/event-utils | ||
/// ... | ||
// ... | ||
@@ -71,3 +71,2 @@ <div> | ||
</div> | ||
``` | ||
@@ -77,3 +76,19 @@ | ||
Another thing you can get rid of is the `onKeyDown` method with the switch case inside that fires a function on a certain `event.key`, you can use an object association instead: | ||
```js | ||
import { attachListenersToKeys } from '@accurat/event-utils' | ||
// ... | ||
<input | ||
type="text" | ||
onKeyDown={attachListenersToKeys({ | ||
Enter: preventingDefault(state.commit), | ||
ArrowDown: state.selectNext, | ||
ArrowUp: state.selectPrev, | ||
})} | ||
/> | ||
``` | ||
## API | ||
@@ -80,0 +95,0 @@ |
5872
47
112