-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d5a1eff
Showing
12 changed files
with
3,484 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"presets": [ | ||
"es2015" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"env": { | ||
"jest/globals": true | ||
}, | ||
"extends": "airbnb", | ||
"plugins": [ | ||
"jest" | ||
], | ||
"rules": { | ||
"comma-dangle": "off" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
lib/ | ||
|
||
node_modules/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- '7' | ||
- '6' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Bertrand Marron <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "react-event-utils", | ||
"version": "1.0.0", | ||
"description": "Shorthand utils for dealing with React events", | ||
"main": "lib/index.js", | ||
"repository": "[email protected]:tusbar/react-event-utils.git", | ||
"author": "Bertrand Marron <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-eslint": "^7.2.3", | ||
"babel-jest": "^19.0.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^14.1.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jest": "^19.0.1", | ||
"eslint-plugin-jsx-a11y": "^4.0.0", | ||
"eslint-plugin-react": "^6.10.3", | ||
"jest": "^19.0.2" | ||
}, | ||
"scripts": { | ||
"transpile": "babel src --out-dir lib", | ||
"lint": "eslint src", | ||
"jest": "jest", | ||
"test": "yarn lint && yarn transpile && yarn jest", | ||
"prepublish": "yarn test" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# react-event-utils | ||
|
||
> Shorthand utils for dealing with React events | ||
# Install | ||
|
||
```cli | ||
$ yarn add react-event-utils | ||
``` | ||
|
||
# About | ||
|
||
This library exposes shorthand methods that call event methods for you. | ||
|
||
This will allow you to stop having components like this: | ||
|
||
```jsx | ||
class Form extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.handleSubmit = this.handleSubmit.bind(this); | ||
} | ||
|
||
handleSubmit(e) { | ||
e.preventDefault(); | ||
|
||
doSomething(e.target.title.value); | ||
} | ||
|
||
render() { | ||
return ( | ||
<form onSubmit={this.handleSubmit}> | ||
<input type="text" name="title" /> | ||
</form> | ||
); | ||
} | ||
} | ||
``` | ||
|
||
While you could just write: | ||
|
||
```jsx | ||
import { preventDefault /*, persist, stopPropagation */ } from 'react-event-utils'; | ||
|
||
export const Form = () => | ||
<form onSubmit={preventDefault(e => doSomething(e.target.title.value))}> | ||
<input type="text" name="title" /> | ||
</form>; | ||
``` | ||
|
||
Currently `persist`, `preventDefault` and `stopPropagation` are implemented. | ||
|
||
|
||
# License | ||
|
||
MIT © [Bertrand Marron](https://github.com/tusbar) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
'persist', | ||
'preventDefault', | ||
'stopPropagation' | ||
].forEach((name) => { | ||
module.exports[name] = func => (e, ...args) => { | ||
e[name](); | ||
return func(e, ...args); | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { persist, preventDefault, stopPropagation } from '../lib'; | ||
|
||
test('should be a function', () => { | ||
expect(persist).toBeInstanceOf(Function); | ||
expect(preventDefault).toBeInstanceOf(Function); | ||
expect(stopPropagation).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('should return a function', () => { | ||
expect(persist()).toBeInstanceOf(Function); | ||
expect(preventDefault()).toBeInstanceOf(Function); | ||
expect(stopPropagation()).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('should call the appropriate function', () => { | ||
const persistMock = jest.fn(); | ||
const event = { | ||
persist: persistMock | ||
}; | ||
|
||
persist(() => {})(event); | ||
|
||
expect(persistMock).toBeCalledWith(); | ||
}); | ||
|
||
test('should pass all the arguments to the passed function', () => { | ||
const funcMock = jest.fn(); | ||
const args = [ | ||
{ preventDefault: () => {} }, | ||
'hi', | ||
45 | ||
]; | ||
|
||
preventDefault(funcMock)(...args); | ||
|
||
expect(funcMock).toBeCalledWith(...args); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import utils from '../lib'; | ||
|
||
test('export 3 functions', () => { | ||
expect(Object.keys(utils)).toEqual([ | ||
'persist', | ||
'preventDefault', | ||
'stopPropagation' | ||
]); | ||
}); |
Oops, something went wrong.