Skip to content

Commit 095af5c

Browse files
committed
Merge pull request #9 from jokeyrhyme/post-mount-resize
after first browser render, check sizes again (fixes #8)
2 parents 9baedc4 + 0611ea6 commit 095af5c

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

.eslintrc renamed to .eslintrc.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
"afterColon": true
173173
}
174174
],
175+
"keyword-spacing": 2,
175176
"max-nested-callbacks": [
176177
2,
177178
3
@@ -221,10 +222,6 @@
221222
"never"
222223
],
223224
"sort-vars": 0,
224-
"space-after-keywords": [
225-
1,
226-
"always"
227-
],
228225
"space-before-blocks": 0,
229226
"space-before-function-paren": [
230227
1,
@@ -243,7 +240,6 @@
243240
"never"
244241
],
245242
"space-infix-ops": 2,
246-
"space-return-throw-case": 2,
247243
"space-unary-ops": [
248244
1,
249245
{

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: node_js
22
node_js:
33
- "4"
44
- "5"
5+
- "stable"
56

67
script:
78
- "npm run nsp && npm run lint && npm test"
@@ -13,3 +14,9 @@ sudo: false
1314

1415
before_install:
1516
- "npm install -g npm@latest"
17+
18+
# https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI
19+
before_script:
20+
- "export DISPLAY=:99.0"
21+
- "sh -e /etc/init.d/xvfb start"
22+
- sleep 3 # give xvfb some time to start

index.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, {PropTypes, Component, Children, cloneElement} from 'react'
22
import {findDOMNode} from 'react-dom'
3-
import identity from 'lodash/utility/identity'
4-
import sortBy from 'lodash/collection/sortBy'
5-
import first from 'lodash/array/first'
6-
import isNumber from 'lodash/lang/isNumber'
3+
import identity from 'lodash.identity'
4+
import sortBy from 'lodash.sortby'
5+
import first from 'lodash.first'
6+
import isNumber from 'lodash.isnumber'
77
import raf from 'raf'
88
import pureRender from 'pure-render-decorator'
99

@@ -25,6 +25,7 @@ export default class ElementQuery extends Component {
2525
if (size === 0) {
2626
return new Error(`${componentName} received a width of \`${size}\` for \`${props.name}\`. Widths are min-widths, and should be treated as "mobile-first". The default state can be set with the \`default\` prop, or even better with the "default" styles in CSS.`)
2727
}
28+
return null
2829
}
2930
})).isRequired
3031
, makeClassName: PropTypes.func
@@ -50,6 +51,10 @@ export default class ElementQuery extends Component {
5051

5152
componentDidMount () {
5253
ElementQuery.sizeComponent(this, this.state.sizes)
54+
// wait a few frames then check sizes again
55+
raf(() => raf(() => {
56+
ElementQuery.sizeComponent(this, this.state.sizes)
57+
}))
5358
}
5459

5560
componentWillReceiveProps (newProps) {
@@ -60,9 +65,9 @@ export default class ElementQuery extends Component {
6065
ElementQuery.unregister(this)
6166
}
6267

63-
static _isListening = false
68+
static _isListening = false
6469

65-
static _componentMap = new Map()
70+
static _componentMap = new Map()
6671

6772
// use only one global listener … for perf!
6873
static listen () {
@@ -110,18 +115,18 @@ static _componentMap = new Map()
110115
let matchedSize = ''
111116
let matchedWidth = smallestSize.width
112117

118+
// use Array#some() here because #forEach() has no early exit
113119
sizes.some((test) => {
114120
// check for:
115121
// 1. the el width is greater or equal to the test width
116122
// 2. the el width is greater or equal to the min test width
117123
if (width >= test.width && width >= matchedWidth) {
118124
matchedSize = test.name
119125
matchedWidth = test.width
126+
return false
120127
}
121128
// once that condition isn't true, we've found the correct match; bail
122-
else {
123-
return true
124-
}
129+
return true
125130
})
126131
component.setSize(matchedSize)
127132
}

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"browser": "index.es5",
5555
"devDependencies": {
5656
"babel": "^5.6.14",
57-
"babel-eslint": "^4.1.3",
57+
"babel-eslint": "^6.0.4",
5858
"babel-plugin-closure-elimination": "^0.0.2",
5959
"babel-plugin-undefined-to-void": "^1.1.6",
6060
"babel-runtime": "^5.6.15",
@@ -63,8 +63,8 @@
6363
"browserify": "^12.0.1",
6464
"dmn": "^1.0.5",
6565
"doctoc": "^0.15.0",
66-
"eslint": "^1.7.3",
67-
"eslint-plugin-react": "^3.6.3",
66+
"eslint": "^2.8.0",
67+
"eslint-plugin-react": "^5.0.1",
6868
"ghooks": "^0.3.2",
6969
"hihat": "^2.5.0",
7070
"in-publish": "^2.0.0",
@@ -87,8 +87,11 @@
8787
"react-dom": ">=0.14.1"
8888
},
8989
"dependencies": {
90-
"lodash": "^3.10.1",
91-
"pure-render-decorator": "^0.2.0",
90+
"lodash.first": "^3.0.0",
91+
"lodash.identity": "^3.0.0",
92+
"lodash.isnumber": "^3.0.3",
93+
"lodash.sortby": "^4.4.2",
94+
"pure-render-decorator": "^1.1.0",
9295
"raf": "^3.0.0"
9396
}
9497
}

scripts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
IFS=$'\n\t'
55

66
function lint(){
7-
eslint --no-eslintrc --config .eslintrc "${@-.}" --ext .jsx --ext .js --ext .es6
7+
eslint --no-eslintrc --config .eslintrc.json "${@-.}" --ext .jsx --ext .js --ext .es6
88
}
99

1010
function git_require_clean_work_tree(){

0 commit comments

Comments
 (0)