Skip to content

Commit 7847180

Browse files
authored
Merge pull request #13 from erikras/dep-update
Upgraded deps, added flow
2 parents 570dd82 + 74ede86 commit 7847180

File tree

10 files changed

+124
-108
lines changed

10 files changed

+124
-108
lines changed

.babelrc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
2-
"stage": 0,
3-
"loose": "all"
2+
"presets": ["es2015-no-commonjs", "react", "stage-2"],
3+
"env": {
4+
"development": {
5+
"plugins": ["transform-es2015-modules-commonjs"]
6+
},
7+
"test": {
8+
"plugins": ["transform-es2015-modules-commonjs", "istanbul"]
9+
},
10+
"production": {
11+
"plugins": ["transform-es2015-modules-commonjs"]
12+
},
13+
"es": {
14+
"plugins": ["./babel-lodash-es"]
15+
}
16+
}
417
}

.eslintrc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
11
{
2-
"extends": "eslint-config-airbnb",
3-
"env": {
4-
"browser": true,
5-
"mocha": true,
6-
"node": true
7-
},
8-
"rules": {
9-
"react/jsx-uses-react": 2,
10-
"react/jsx-uses-vars": 2,
11-
"react/react-in-jsx-scope": 2,
12-
"comma-dangle": 0, // not sure why airbnb turned this on. gross!
13-
"indent": [2, 2, {"SwitchCase": 1}],
14-
15-
//Temporarirly disabled due to a possible bug in babel-eslint (todomvc example)
16-
"block-scoped-var": 0,
17-
// Temporarily disabled for test/* until babel/babel-eslint#33 is resolved
18-
"padded-blocks": 0
19-
},
20-
"plugins": [
21-
"react"
22-
]
2+
"extends": "react-app"
233
}

.flowconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ignore]
2+
3+
[include]
4+
5+
[libs]
6+
7+
[options]

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: node_js
22

33
node_js:
4-
- "0.12"
5-
- "4.0"
6-
- "4"
4+
- "6"
5+
- "stable"
76

87
script:
98
- npm run lint
9+
- flow

package.json

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,27 @@
3434
"browser"
3535
],
3636
"devDependencies": {
37-
"babel": "^5.8.23",
38-
"babel-core": "^5.8.25",
39-
"babel-eslint": "^4.1.3",
40-
"babel-loader": "^5.3.2",
41-
"eslint": "^1.6.0",
42-
"eslint-config-airbnb": "^0.1.0",
43-
"eslint-plugin-react": "^3.5.1",
37+
"babel-cli": "^6.24.1",
38+
"babel-core": "^6.24.1",
39+
"babel-eslint": "^7.2.3",
40+
"babel-loader": "^7.0.0",
41+
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
42+
"babel-preset-es2015-no-commonjs": "^0.0.2",
43+
"babel-preset-react": "^6.24.1",
44+
"babel-preset-stage-2": "^6.24.1",
45+
"eslint": "^3.19.0",
46+
"eslint-config-react-app": "^0.6.2",
47+
"eslint-plugin-flowtype": "^2.32.1",
48+
"eslint-plugin-import": "^2.2.0",
49+
"eslint-plugin-jsx-a11y": "^4.0.0",
50+
"eslint-plugin-react": "^6.10.3",
51+
"flow-bin": "^0.45.0",
4452
"prop-types": "^15.5.8",
45-
"react": "^0.14.0",
46-
"react-dom": "^0.14.0",
47-
"rifraf": "^2.0.2",
48-
"rimraf": "^2.4.3",
49-
"webpack": "^1.12.2"
53+
"react": "^15.5.4",
54+
"react-dom": "^15.5.4",
55+
"rifraf": "^2.0.3",
56+
"rimraf": "^2.6.1",
57+
"webpack": "^2.5.0"
5058
},
5159
"npmName": "react-native-listener",
5260
"npmFileMap": [

src/NativeListener.js

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,84 @@
1-
import {Component} from 'react';
2-
import PropTypes from 'prop-types';
3-
import ReactDOM from 'react-dom';
1+
// @flow
2+
import { Component } from 'react'
3+
import PropTypes from 'prop-types'
4+
import ReactDOM from 'react-dom'
45
const events = [
5-
'KeyDown',
6-
'KeyPress',
7-
'KeyUp',
8-
'Click',
9-
'ContextMenu',
10-
'DoubleClick',
11-
'Drag',
12-
'DragEnd',
13-
'DragEnter',
14-
'DragExit',
15-
'DragLeave',
16-
'DragOver',
17-
'DragStart',
18-
'Drop',
19-
'Focus',
20-
'MouseDown',
21-
'MouseEnter',
22-
'MouseLeave',
23-
'MouseMove',
24-
'MouseOut',
25-
'MouseOver',
26-
'MouseUp'
27-
];
6+
'KeyDown',
7+
'KeyPress',
8+
'KeyUp',
9+
'Click',
10+
'ContextMenu',
11+
'DoubleClick',
12+
'Drag',
13+
'DragEnd',
14+
'DragEnter',
15+
'DragExit',
16+
'DragLeave',
17+
'DragOver',
18+
'DragStart',
19+
'Drop',
20+
'Focus',
21+
'MouseDown',
22+
'MouseEnter',
23+
'MouseLeave',
24+
'MouseMove',
25+
'MouseOut',
26+
'MouseOver',
27+
'MouseUp'
28+
]
2829

2930
const aliases = {
30-
'DoubleClick': 'dblclick'
31-
};
31+
DoubleClick: 'dblclick'
32+
}
3233

33-
const toEventName = event =>
34-
(aliases[event] || event).toLowerCase();
34+
const toEventName = (event: string): string =>
35+
(aliases[event] || event).toLowerCase()
3536

3637
export default class NativeListener extends Component {
37-
static displayName = 'NativeListener';
38-
static propTypes = {
39-
children: (props, propName) => {
40-
if (props[propName].length) {
41-
return new Error('NativeListener can only wrap one element');
42-
}
43-
},
44-
...events.reduce((accumulator, event) => ({
45-
...accumulator,
46-
[`on${event}`]: PropTypes.func,
47-
[`on${event}Capture`]: PropTypes.func,
48-
[`stop${event}`]: PropTypes.bool
49-
}), {})
50-
};
38+
static displayName = 'NativeListener'
39+
static propTypes = {
40+
children: (props, propName) => {
41+
if (props[propName].length) {
42+
return new Error('NativeListener can only wrap one element')
43+
}
44+
},
45+
...events.reduce(
46+
(accumulator, event) => ({
47+
...accumulator,
48+
[`on${event}`]: PropTypes.func,
49+
[`on${event}Capture`]: PropTypes.func,
50+
[`stop${event}`]: PropTypes.bool
51+
}),
52+
{}
53+
)
54+
}
5155

52-
componentDidMount() {
53-
const props = this.props;
54-
const element = ReactDOM.findDOMNode(this);
55-
events.forEach(event => {
56-
const capture = props['on' + event + 'Capture'];
57-
const bubble = props['on' + event];
58-
const stop = props['stop' + event];
59-
if (capture && typeof capture === 'function') {
60-
element.addEventListener(toEventName(event), capture, true);
61-
}
62-
if (bubble && typeof bubble === 'function') {
63-
element.addEventListener(toEventName(event), bubble, false);
64-
}
65-
if (stop === true) {
66-
element.addEventListener(toEventName(event), nativeEvent => nativeEvent.stopPropagation(), false);
67-
}
68-
});
69-
}
56+
componentDidMount() {
57+
const props = this.props
58+
const element = ReactDOM.findDOMNode(this)
59+
if (element) {
60+
events.forEach(event => {
61+
const capture = props['on' + event + 'Capture']
62+
const bubble = props['on' + event]
63+
const stop = props['stop' + event]
64+
if (capture && typeof capture === 'function') {
65+
element.addEventListener(toEventName(event), capture, true)
66+
}
67+
if (bubble && typeof bubble === 'function') {
68+
element.addEventListener(toEventName(event), bubble, false)
69+
}
70+
if (stop === true) {
71+
element.addEventListener(
72+
toEventName(event),
73+
nativeEvent => nativeEvent.stopPropagation(),
74+
false
75+
)
76+
}
77+
})
78+
}
79+
}
7080

71-
render() {
72-
return this.props.children;
73-
}
81+
render() {
82+
return this.props.children
83+
}
7484
}

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import NativeListener from './NativeListener';
2-
export default NativeListener;
1+
import NativeListener from './NativeListener'
2+
export default NativeListener

webpack.config.base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ module.exports = {
2222
libraryTarget: 'umd'
2323
},
2424
resolve: {
25-
extensions: ['', '.js']
25+
extensions: ['.js']
2626
}
2727
};

webpack.config.development.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var baseConfig = require('./webpack.config.base');
55

66
var config = Object.create(baseConfig);
77
config.plugins = [
8-
new webpack.optimize.OccurenceOrderPlugin(),
98
new webpack.DefinePlugin({
109
'process.env.NODE_ENV': JSON.stringify('development')
1110
})

webpack.config.production.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var baseConfig = require('./webpack.config.base');
55

66
var config = Object.create(baseConfig);
77
config.plugins = [
8-
new webpack.optimize.OccurenceOrderPlugin(),
98
new webpack.DefinePlugin({
109
'process.env.NODE_ENV': JSON.stringify('production')
1110
}),

0 commit comments

Comments
 (0)