Skip to content

Commit

Permalink
Merge pull request #4 from datatrans/code-hygiene
Browse files Browse the repository at this point in the history
Code hygiene
  • Loading branch information
mephju authored Feb 19, 2018
2 parents 4bde40a + 4795153 commit 8b4a8e2
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 236 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
example/
20 changes: 2 additions & 18 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
// I want to use babel-eslint for parsing!
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
Expand All @@ -10,9 +9,7 @@
}
},
"env": {
// I write for browser
"browser": true,
// in CommonJS
"node": true,
"es6":true
},
Expand All @@ -22,7 +19,6 @@
"eslint:recommended",
"plugin:react/recommended"
],
// To give you an idea how to override rule options:
"rules": {
"no-unresovled":0,
"quotes": [2, "single"],
Expand All @@ -34,24 +30,21 @@
"indent": [1, 2],
"linebreak-style": ["error", "unix"],

"semi": ["error", "never"], // never use semicolons
"semi": ["error", "never"],

// override default options for rules from base configurations
"comma-dangle": [0, "always"],
"no-cond-assign": ["error", "always"],

"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,

// disable rules from base configurations
"no-console": 0,
"no-dupe-args":2,
"no-dupe-keys":2,
"array-bracket-spacing": 2,
"camelcase": 2,
"comma-spacing": [0, {"before": false, "after": true}],
// "curly": [2, "multi"],
"no-self-assign": 2,
"no-extra-boolean-cast": 0,
"flowtype/boolean-style": [
Expand All @@ -73,15 +66,6 @@
2,
"comma"
],
// "flowtype/require-parameter-type": 2,
// "flowtype/require-return-type": [
// 2,
// "always",
// {
// "annotateUndefined": "never"
// }
// ],
// "flowtype/require-valid-file-annotation": 2,
"flowtype/semi": [
2,
"always"
Expand Down Expand Up @@ -110,4 +94,4 @@
"flowtype/valid-syntax": 1

}
}
}
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
machine:
node:
version: 8.9
2 changes: 1 addition & 1 deletion example/lib/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<title>UPP Admin</title>
<title>Datatrans React Lightbox</title>
</head>


Expand Down
158 changes: 102 additions & 56 deletions example/lib/main.js

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import React, {PropTypes, Component} from 'react'
import React, { Component } from 'react'
import LightBox from 'react-datatrans-light-box'


const config = {
merchantId: '1100004624',
refno: '11000asdfasdf4624',
Expand Down Expand Up @@ -97,11 +95,8 @@ class LightBoxHocApproachBase extends Component {

}


LightBoxHocApproachBase.propTypes = {
lightBox: LightBox.Hoc.propType,

}

const LightBoxHocApproach = LightBox.Hoc(LightBoxHocApproachBase)

2 changes: 1 addition & 1 deletion example/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<title>UPP Admin</title>
<title>Datatrans React Lightbox</title>
</head>


Expand Down
29 changes: 7 additions & 22 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
const path = require('path')
const webpack = require('webpack')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
module: {
loaders: [{
test: /\.js$/, // Transform all .js files required somewhere with Babel
loader: 'babel-loader',
// include: ['../../shared'],
// exclude: [/node_modules/],
// query: env.babelQuery,
}]
loaders: [
{
test: /\.js$/,
loader: 'babel-loader'
}
]

},
entry: {
main: ['./src/index.js'],

},
plugins: [
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false, // ...but do not show warnings in the console (there is a lot of them)
// },
// comments: false,
// }),
// new webpack.HotModuleReplacementPlugin(), // Tell webpack we want hot reloading
// new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({
inject: true,
chunks:['app'],
Expand All @@ -38,9 +27,5 @@ module.exports = {
output: {
path: path.resolve(__dirname, 'lib'),
filename: '[name].js'
},

// resolve: {
// modules:[path.resolve(__dirname, '../../shared'), 'node_modules']
// }
}
}
4 changes: 1 addition & 3 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2400,9 +2400,7 @@ rc@^1.1.7:
strip-json-comments "~2.0.1"

react-datatrans-light-box@../:
version "1.0.2"
dependencies:
prop-types "^15.6.0"
version "1.0.4"

react-dom@^16.2.0:
version "16.2.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"author": "Datatrans AG",
"license": "MIT",
"scripts": {
"test": "npm run build",
"test": "npm run lint && npm run build",
"build": "NODE_ENV=production webpack --color --progress",
"watch": "NODE_ENV=production webpack --color --progress --watch"
"watch": "NODE_ENV=production webpack --color --progress --watch",
"lint": "eslint ."
},
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0-0"
Expand All @@ -40,16 +41,14 @@
"babel-preset-latest": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
"compression-webpack-plugin": "^0.3.2",
"eslint": "^3.11.1",
"eslint-import-resolver-webpack": "^0.8.0",
"eslint-loader": "^1.5.0",
"eslint-plugin-flowtype": "^2.29.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.1",
"eslint-plugin-react": "^6.8.0",
"prop-types": "^15.6.0",
"webpack": "^2.3.2"
},
"dependencies": {
}
}
37 changes: 18 additions & 19 deletions src/LightBox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Component} from 'react'
// import PropTypes from 'prop-types'
import PropTypes from 'prop-types'
import PaymentPageFrame from './PaymentPageFrame'
import {
filterProps, toUrlParams, parseUrl,
Expand Down Expand Up @@ -49,14 +49,14 @@ export default class LightBox extends Component {
this.props.onCancelled()
}

componentDidMount() {
componentDidMount() {
const addListener = window.addEventListener || window.attachEvent
addListener('message', this.onMessage)
addListener('message', this.onMessage)
}

componentWillUnmount() {
componentWillUnmount() {
const removeListener = window.removeEventListener || window.detachEvent
removeListener('message', this.onMessage)
removeListener('message', this.onMessage)
releaseLock()
}

Expand All @@ -72,22 +72,21 @@ export default class LightBox extends Component {

}

LightBox.propTypes = {
merchantId: PropTypes.string.isRequired,
refno: PropTypes.string.isRequired,
amount: PropTypes.string.isRequired,
currency: PropTypes.string.isRequired,
sign: PropTypes.string.isRequired,

// LightBox.propTypes = {
// merchantId: PropTypes.string.isRequired,
// refno: PropTypes.string.isRequired,
// amount: PropTypes.string.isRequired,
// currency: PropTypes.string.isRequired,
// sign: PropTypes.string.isRequired,
production: PropTypes.bool,
showsPaymentPage: PropTypes.bool.isRequired,

// production: PropTypes.bool,
// showsPaymentPage: PropTypes.bool.isRequired,
onCancelled: PropTypes.func.isRequired,
onLoaded: PropTypes.func.isRequired,
onError: PropTypes.func.isRequired,

// onCancelled: PropTypes.func.isRequired,
// onLoaded: PropTypes.func.isRequired,
// onError: PropTypes.func.isRequired,

// }
}

LightBox.defaultProps = {
onCancelled() {},
Expand All @@ -97,4 +96,4 @@ LightBox.defaultProps = {
theme: 'DT2015',
version: '1.0.2',
showsPaymentPage: true,
}
}
28 changes: 13 additions & 15 deletions src/LightBoxHoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Component} from 'react'
// import PropTypes from 'prop-types'
import PropTypes from 'prop-types'
import LightBox from './LightBox'
import {filterProps} from './utils'

Expand Down Expand Up @@ -105,19 +105,17 @@ const LightBoxHoc = Wrapee => class Wrapper extends Component {
}
}

// LightBoxHoc.propType = PropTypes.shape({


// //LightBox state
// visible: PropTypes.bool.isRequired,
// loaded: PropTypes.bool.isRequired,
// cancelled: PropTypes.bool.isRequired,
// error: PropTypes.any,

// //Methods
// load: PropTypes.func.isRequired,
// show: PropTypes.func.isRequired,
// on: PropTypes.func.isRequired,
// })
LightBoxHoc.propType = PropTypes.shape({
//LightBox state
visible: PropTypes.bool.isRequired,
loaded: PropTypes.bool.isRequired,
cancelled: PropTypes.bool.isRequired,
error: PropTypes.any,

//Methods
load: PropTypes.func.isRequired,
show: PropTypes.func.isRequired,
on: PropTypes.func.isRequired,
})

export default LightBoxHoc
9 changes: 4 additions & 5 deletions src/PaymentPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
// import PropTypes from 'prop-types'
import PropTypes from 'prop-types'
import styles from './styles'

const PaymentPage = props => {
Expand All @@ -14,9 +14,8 @@ const PaymentPage = props => {
/>
}


// PaymentPage.propTypes = {
// url: PropTypes.string.isRequired,
// }
PaymentPage.propTypes = {
url: PropTypes.string.isRequired,
}

export default PaymentPage
14 changes: 7 additions & 7 deletions src/PaymentPageFrame.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
// import PropTypes from 'prop-types'
import PropTypes from 'prop-types'
import PaymentPage from './PaymentPage'
import styles from './styles'

Expand All @@ -8,18 +8,18 @@ const display = 'block'
const PaymentPageFrame = props => {

const style = props.showsPaymentPage
? {...styles.pageFrame, display}
: styles.pageFrame
? {...styles.pageFrame, display}
: styles.pageFrame


return <div style={style}>
<PaymentPage url={props.url} />
</div>
}

// PaymentPageFrame.propTypes = {
// url: PropTypes.string.isRequired,
// showsPaymentPage: PropTypes.bool.isRequired,
// }
PaymentPageFrame.propTypes = {
url: PropTypes.string.isRequired,
showsPaymentPage: PropTypes.bool.isRequired,
}

export default PaymentPageFrame
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import LightBox from './LightBox.js'
import LightBox from './LightBox'
import LightBoxHoc from './LightBoxHoc'

LightBox.Hoc = LightBoxHoc

export {LightBoxHoc, LightBoxHoc as withLightBox}
export default LightBox



Loading

0 comments on commit 8b4a8e2

Please sign in to comment.