Skip to content

Commit 74adbd1

Browse files
authored
feat: Update project to react16, jest, enzyme3 (#103)
BREAKING CHANGE: This version is only compatible with React >= 16
1 parent fc4bd23 commit 74adbd1

File tree

14 files changed

+461
-462
lines changed

14 files changed

+461
-462
lines changed

.babelrc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
{
22
"presets": [
3-
"latest",
3+
"env",
44
"react"
55
],
66
"plugins": [
7-
"transform-object-rest-spread",
8-
],
9-
"env": {
10-
"test": {
11-
"plugins": ["istanbul"]
12-
}
13-
}
7+
"transform-object-rest-spread"
8+
]
149
}

.editorconfig

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1+
root = true
2+
13
[*]
2-
end_of_line = lf
3-
insert_final_newline = true
4-
charset = utf-8
54
indent_style = space
6-
indent_size = 4
7-
8-
[*.{json,yml}]
9-
indent_size = 2
10-
11-
[.*]
125
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['eslint:recommended', 'plugin:react/recommended'],
4+
parserOptions: {
5+
ecmaVersion: 2018,
6+
sourceType: 'module',
7+
ecmaFeatures: {
8+
jsx: true,
9+
},
10+
},
11+
rules: {
12+
'react/no-find-dom-node': '0',
13+
},
14+
globals: {
15+
document: true,
16+
MouseEvent: true,
17+
},
18+
};

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ npm-debug.log
44

55
/lib
66
coverage/
7-
.nyc_output

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
singleQuote: true
2+
printWidth: 100
3+
trailingComma: es5

examples/basic/app.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
'use strict';
22

33
var React = require('react');
4-
var clickDrag = require('../../lib/clickdrag');
5-
6-
var ExampleComponent = React.createClass({
7-
8-
getInitialState: function() {
9-
return {
10-
lastPositionX: 0,
11-
lastPositionY: 0,
12-
currentX: 0,
13-
currentY: 0
14-
};
15-
},
16-
17-
componentWillReceiveProps: function(nextProps) {
18-
if(nextProps.dataDrag.isMoving) {
19-
this.setState({
20-
currentX: this.state.lastPositionX + nextProps.dataDrag.moveDeltaX,
21-
currentY: this.state.lastPositionY + nextProps.dataDrag.moveDeltaY
22-
});
23-
}
24-
else {
25-
this.setState({
26-
lastPositionX: this.state.currentX,
27-
lastPositionY: this.state.currentY
28-
});
29-
}
30-
},
31-
32-
render: function () {
33-
var translation = 'translate('+this.state.currentX+'px, '+this.state.currentY+'px)';
34-
35-
return React.createElement('div', {
36-
style: {width: '200px', height: '200px', backgroundColor: 'red', transform: translation}
37-
});
4+
var { render } = require('react-dom');
5+
var clickDrag = require('../../lib/clickdrag').default;
6+
7+
class ExampleComponent extends React.Component {
8+
constructor(props) {
9+
super(props);
10+
11+
this.state = {
12+
lastPositionX: 0,
13+
lastPositionY: 0,
14+
currentX: 0,
15+
currentY: 0,
16+
};
17+
}
18+
19+
componentWillReceiveProps(nextProps) {
20+
if (nextProps.dataDrag.isMoving) {
21+
this.setState({
22+
currentX: this.state.lastPositionX + nextProps.dataDrag.moveDeltaX,
23+
currentY: this.state.lastPositionY + nextProps.dataDrag.moveDeltaY,
24+
});
25+
} else {
26+
this.setState({
27+
lastPositionX: this.state.currentX,
28+
lastPositionY: this.state.currentY,
29+
});
3830
}
39-
});
31+
}
4032

41-
var ClickDragExample = clickDrag(ExampleComponent, {touch: true});
33+
render() {
34+
var translation = 'translate(' + this.state.currentX + 'px, ' + this.state.currentY + 'px)';
4235

43-
React.render(React.createElement(ClickDragExample), document.getElementById('App'));
36+
return React.createElement('div', {
37+
style: { width: '200px', height: '200px', backgroundColor: 'red', transform: translation },
38+
});
39+
}
40+
}
41+
42+
var ClickDragExample = clickDrag(ExampleComponent, { touch: true });
43+
44+
render(React.createElement(ClickDragExample), document.getElementById('App'));

examples/basic/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"scripts": {
3-
"build": "browserify app.js --debug -o app.min.js"
3+
"build": "npx browserify app.js --debug -o app.min.js"
44
},
55
"devDependencies": {
66
"babelify": "^5.0.4"
7+
},
8+
"dependencies": {
9+
"browserify": "^16.2.2"
710
}
811
}

package.json

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,66 +29,51 @@
2929
"devDependencies": {
3030
"babel-cli": "^6.18.0",
3131
"babel-core": "^6.21.0",
32-
"babel-plugin-istanbul": "^3.0.0",
32+
"babel-jest": "^23.4.2",
3333
"babel-plugin-transform-object-rest-spread": "^6.20.2",
34-
"babel-preset-latest": "^6.16.0",
34+
"babel-preset-env": "^1.7.0",
3535
"babel-preset-react": "^6.16.0",
36-
"babel-register": "^6.18.0",
37-
"chai": "^3.5.0",
38-
"cross-env": "^3.1.3",
39-
"enzyme": "^2.7.0",
40-
"eslint": "^3.12.2",
41-
"eslint-config-tleunen-react": "^1.0.3",
42-
"eslint-plugin-import": "^2.2.0",
43-
"eslint-plugin-jsx-a11y": "^2.2.3",
44-
"eslint-plugin-react": "^6.8.0",
45-
"jsdom": "^9.9.1",
46-
"mocha": "^3.2.0",
47-
"nyc": "^10.0.0",
48-
"react": "^15.4.1",
49-
"react-addons-test-utils": "^15.4.1",
50-
"react-dom": "^15.4.1",
51-
"rimraf": "^2.5.4",
52-
"sinon": "^1.17.6",
36+
"enzyme": "^3.6.0",
37+
"enzyme-adapter-react-16": "^1.5.0",
38+
"eslint": "^5.5.0",
39+
"eslint-plugin-react": "^7.11.1",
40+
"husky": "^0.14.3",
41+
"jest": "^23.5.0",
42+
"lint-staged": "^7.2.2",
43+
"react": "^16.4.2",
44+
"react-dom": "^16.4.2",
5345
"standard-version": "^4.0.0"
5446
},
5547
"peerDependencies": {
56-
"react": "0.14.x || ^15.0.0-rc",
57-
"react-dom": "0.14.x || ^15.0.0-rc"
48+
"react": "^16.0.0-0",
49+
"react-dom": "^16.0.0-0"
5850
},
5951
"scripts": {
6052
"clean": "rimraf coverage lib out",
61-
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
62-
"react:14": "npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14",
63-
"react:15": "npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15",
64-
"test:react:14": "npm run react:14 && cross-env NODE_ENV=test npm run test:suite",
65-
"test:react:15": "npm run react:15 && cross-env NODE_ENV=test npm run test:suite",
6653
"test:suite": "mocha -r babel-register -r ./test/setup.js 'test/*'",
6754
"test:watch": "npm run test:suite -- -w",
68-
"test:only": "npm run test:react:14 && npm run test:react:15",
6955
"pretest": "npm run lint",
70-
"test": "npm run test:react:14 && cross-env NODE_ENV=test nyc npm run test:react:15",
71-
"lint": "eslint src test",
72-
"compile": "rimraf lib && cross-env NODE_ENV=production babel src --out-dir lib",
56+
"test": "jest --coverage",
57+
"lint": "eslint src test --ext .jsx,.js",
58+
"compile": "babel src --out-dir lib",
7359
"prepublish": "npm run compile",
7460
"release": "standard-version"
7561
},
76-
"nyc": {
77-
"sourceMap": false,
78-
"instrument": false,
79-
"reporter": [
80-
"lcov",
81-
"text"
62+
"husky": {
63+
"hooks": {
64+
"pre-commit": "lint-staged"
65+
}
66+
},
67+
"lint-staged": {
68+
"*.{js,jsx,json,md}": [
69+
"prettier --write",
70+
"git add"
8271
]
8372
},
84-
"greenkeeper": {
85-
"ignore": [
86-
"eslint",
87-
"eslint-plugin-import",
88-
"eslint-plugin-jsx-a11y",
89-
"eslint-plugin-react",
90-
"react-dom",
91-
"react-addons-test-utils"
73+
"jest": {
74+
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.js",
75+
"collectCoverageFrom": [
76+
"src/**/*.js{x}"
9277
]
9378
}
9479
}

0 commit comments

Comments
 (0)