Skip to content

Commit

Permalink
fixed isEqual util
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Einstein committed Jun 23, 2017
1 parent 8c3ba65 commit 0933445
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
12 changes: 5 additions & 7 deletions config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ var projectPaths = require('./projectPaths')

// default to prod dev configuration
var devtool = ''

// exclude React in prod build
var externals = {}
// entry differs based on env
var entry = []

// initial set of plugins
var plugins = [
new webpack.NamedModulesPlugin(),
Expand All @@ -22,10 +22,10 @@ var plugins = [
if (process.env.NODE_ENV === 'production') {
// entry
entry.push(projectPaths.entry)

// use production configuration instead
devtool = ''

// do not include react in build
externals = {'react': 'react'}
// optmize the build for production
plugins.push(
new webpack.LoaderOptionsPlugin({
Expand Down Expand Up @@ -106,9 +106,7 @@ module.exports = {
'node_modules',
]
},
externals: {
'react': 'react'
},
externals: externals,
plugins: plugins,
devtool: devtool
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-autotip",
"version": "0.0.3",
"version": "0.0.4",
"description": "A variety of simple auto-positioning tooltips",
"main": "index.js",
"module": "lib/index.js",
Expand Down
6 changes: 3 additions & 3 deletions src/Tooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Tooltip extends React.Component {
children: PropTypes.node.isRequired,
text: PropTypes.string.isRequired,
style: PropTypes.object,
tooltipStyle: PropTypes.object,
tooltipStyles: PropTypes.object,
type: PropTypes.oneOf(['info', 'dialog'])
}

Expand All @@ -26,7 +26,7 @@ class Tooltip extends React.Component {
detail: {
text: this.props.text,
type: this.props.type,
tooltipStyle: this.props.tooltipStyle,
tooltipStyles: this.props.tooltipStyles,
containerDims: getBoundingClientRect(this.node)
}
})
Expand All @@ -41,7 +41,7 @@ class Tooltip extends React.Component {
detail: {
text: '',
type: '',
tooltipStyle: {},
tooltipStyles: {},
containerDims: {}
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/TooltipContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class TooltipContainer extends React.Component {
}

render() {
const { text, type, tooltipStyle, containerDims, tooltipDims } = this.state
const { text, type, tooltipStyles, containerDims, tooltipDims } = this.state
const { pos = 'top', ...rest } = calcPosition({ containerDims, tooltipDims })

return (
<div
className={`react-autotip-${isEmpty(rest) ? 'hidden' : 'active'}`}
style={{ ...styles.container[type], ...rest, ...tooltipStyle }}
style={{ ...styles.container[type], ...rest, ...tooltipStyles }}
ref={tooltip => this.tooltip = tooltip}
>
<div style={styles.content[type]}>
Expand Down
2 changes: 1 addition & 1 deletion src/TooltipContainer/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Tooltip Container', () => {
const detail = {
text: 'test',
type: 'info',
tooltipStyle: {},
tooltipStyles: {},
containerDims: {}
}

Expand Down
2 changes: 0 additions & 2 deletions src/utils/get-bounding-client-rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const getBoundingClientRect = ele => {
left: rect.left,
width: rect.width,
height: rect.height,
x: rect.x,
y: rect.y
}
}

Expand Down
24 changes: 16 additions & 8 deletions src/utils/is-equal.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
const isEqual = (a, b) => {
Object.keys(a).forEach(key => {
if (typeof b[key] === 'undefined') {
return false
}
export default function(a, b) {
// grab keys of respective objects
const aKeys = Object.keys(a)
const bKeys = Object.keys(b)

// if two empty objects
if (aKeys.length === 0 && bKeys.length === 0) {
return true
}

// if lengths are different
if (aKeys.length !== bKeys.length) {
return false
}

for (const key of aKeys) {
if (a[key] !== b[key]) {
return false
}
})
}

return true
}

export default isEqual
22 changes: 22 additions & 0 deletions src/utils/is-equal.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// local imports
import isEqual from './is-equal'

describe('utils', () => {
describe('isEqual()', () => {

test('two empty objects', () => {
const res = isEqual({}, {})
expect(res).toEqual(true)
})

test('two objects with diff num of keys', () => {
const res = isEqual({a: 2, b: 1}, {a: 2})
expect(res).toEqual(false)
})

test('two objects with same keys/props in diff order', () => {
const res = isEqual({a: 2, b: 1}, {b: 1, a: 2})
expect(res).toEqual(true)
})
})
})

0 comments on commit 0933445

Please sign in to comment.