Skip to content

Commit

Permalink
feat: Update project to react16, jest, enzyme3 (#103)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This version is only compatible with React >= 16
  • Loading branch information
tleunen committed Sep 6, 2018
1 parent fc4bd23 commit 74adbd1
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 462 deletions.
11 changes: 3 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"presets": [
"latest",
"env",
"react"
],
"plugins": [
"transform-object-rest-spread",
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
"transform-object-rest-spread"
]
}
15 changes: 6 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[*.{json,yml}]
indent_size = 2

[.*]
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
extends: ['eslint:recommended', 'plugin:react/recommended'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'react/no-find-dom-node': '0',
},
globals: {
document: true,
MouseEvent: true,
},
};
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ npm-debug.log

/lib
coverage/
.nyc_output
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
singleQuote: true
printWidth: 100
trailingComma: es5
75 changes: 38 additions & 37 deletions examples/basic/app.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
'use strict';

var React = require('react');
var clickDrag = require('../../lib/clickdrag');

var ExampleComponent = React.createClass({

getInitialState: function() {
return {
lastPositionX: 0,
lastPositionY: 0,
currentX: 0,
currentY: 0
};
},

componentWillReceiveProps: function(nextProps) {
if(nextProps.dataDrag.isMoving) {
this.setState({
currentX: this.state.lastPositionX + nextProps.dataDrag.moveDeltaX,
currentY: this.state.lastPositionY + nextProps.dataDrag.moveDeltaY
});
}
else {
this.setState({
lastPositionX: this.state.currentX,
lastPositionY: this.state.currentY
});
}
},

render: function () {
var translation = 'translate('+this.state.currentX+'px, '+this.state.currentY+'px)';

return React.createElement('div', {
style: {width: '200px', height: '200px', backgroundColor: 'red', transform: translation}
});
var { render } = require('react-dom');
var clickDrag = require('../../lib/clickdrag').default;

class ExampleComponent extends React.Component {
constructor(props) {
super(props);

this.state = {
lastPositionX: 0,
lastPositionY: 0,
currentX: 0,
currentY: 0,
};
}

componentWillReceiveProps(nextProps) {
if (nextProps.dataDrag.isMoving) {
this.setState({
currentX: this.state.lastPositionX + nextProps.dataDrag.moveDeltaX,
currentY: this.state.lastPositionY + nextProps.dataDrag.moveDeltaY,
});
} else {
this.setState({
lastPositionX: this.state.currentX,
lastPositionY: this.state.currentY,
});
}
});
}

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

React.render(React.createElement(ClickDragExample), document.getElementById('App'));
return React.createElement('div', {
style: { width: '200px', height: '200px', backgroundColor: 'red', transform: translation },
});
}
}

var ClickDragExample = clickDrag(ExampleComponent, { touch: true });

render(React.createElement(ClickDragExample), document.getElementById('App'));
5 changes: 4 additions & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"scripts": {
"build": "browserify app.js --debug -o app.min.js"
"build": "npx browserify app.js --debug -o app.min.js"
},
"devDependencies": {
"babelify": "^5.0.4"
},
"dependencies": {
"browserify": "^16.2.2"
}
}
73 changes: 29 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,66 +29,51 @@
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-plugin-istanbul": "^3.0.0",
"babel-jest": "^23.4.2",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"babel-preset-latest": "^6.16.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.16.0",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"cross-env": "^3.1.3",
"enzyme": "^2.7.0",
"eslint": "^3.12.2",
"eslint-config-tleunen-react": "^1.0.3",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"jsdom": "^9.9.1",
"mocha": "^3.2.0",
"nyc": "^10.0.0",
"react": "^15.4.1",
"react-addons-test-utils": "^15.4.1",
"react-dom": "^15.4.1",
"rimraf": "^2.5.4",
"sinon": "^1.17.6",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"eslint": "^5.5.0",
"eslint-plugin-react": "^7.11.1",
"husky": "^0.14.3",
"jest": "^23.5.0",
"lint-staged": "^7.2.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"standard-version": "^4.0.0"
},
"peerDependencies": {
"react": "0.14.x || ^15.0.0-rc",
"react-dom": "0.14.x || ^15.0.0-rc"
"react": "^16.0.0-0",
"react-dom": "^16.0.0-0"
},
"scripts": {
"clean": "rimraf coverage lib out",
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
"react:14": "npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14",
"react:15": "npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15",
"test:react:14": "npm run react:14 && cross-env NODE_ENV=test npm run test:suite",
"test:react:15": "npm run react:15 && cross-env NODE_ENV=test npm run test:suite",
"test:suite": "mocha -r babel-register -r ./test/setup.js 'test/*'",
"test:watch": "npm run test:suite -- -w",
"test:only": "npm run test:react:14 && npm run test:react:15",
"pretest": "npm run lint",
"test": "npm run test:react:14 && cross-env NODE_ENV=test nyc npm run test:react:15",
"lint": "eslint src test",
"compile": "rimraf lib && cross-env NODE_ENV=production babel src --out-dir lib",
"test": "jest --coverage",
"lint": "eslint src test --ext .jsx,.js",
"compile": "babel src --out-dir lib",
"prepublish": "npm run compile",
"release": "standard-version"
},
"nyc": {
"sourceMap": false,
"instrument": false,
"reporter": [
"lcov",
"text"
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,json,md}": [
"prettier --write",
"git add"
]
},
"greenkeeper": {
"ignore": [
"eslint",
"eslint-plugin-import",
"eslint-plugin-jsx-a11y",
"eslint-plugin-react",
"react-dom",
"react-addons-test-utils"
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.js",
"collectCoverageFrom": [
"src/**/*.js{x}"
]
}
}
Loading

0 comments on commit 74adbd1

Please sign in to comment.