Skip to content

Commit 2013818

Browse files
committed
[removed] handleResize
1 parent 0e84ec9 commit 2013818

File tree

7 files changed

+43
-69
lines changed

7 files changed

+43
-69
lines changed

build/Combo.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ var _reactLibReactWithAddons2 = _interopRequireDefault(_reactLibReactWithAddons)
2222

2323
var _reactDom = require('react-dom');
2424

25-
var _reactDom2 = _interopRequireDefault(_reactDom);
26-
2725
var _reactBootstrap = require('react-bootstrap');
2826

2927
var _lodashCollectionMap = require('lodash/collection/map');
@@ -39,6 +37,10 @@ var _lodashFunctionDebounce = require('lodash/function/debounce');
3937
var _lodashFunctionDebounce2 = _interopRequireDefault(_lodashFunctionDebounce);
4038

4139
var caret = _reactLibReactWithAddons2['default'].createElement('span', { className: 'caret' });
40+
var _React$PropTypes = _reactLibReactWithAddons2['default'].PropTypes;
41+
var func = _React$PropTypes.func;
42+
var object = _React$PropTypes.object;
43+
var string = _React$PropTypes.string;
4244

4345
var uid = 0;
4446

@@ -49,8 +51,9 @@ var uid = 0;
4951
* @param {Object} props - A props config
5052
* @example
5153
* import {Combo} from 'react-bootstrap-combobox';
54+
* import {render} from 'react-dom';
5255
*
53-
* ReactDOM.render(<Combo items={{
56+
* render(<Combo items={{
5457
* // keys must be unique
5558
* a: {label: 'first item', header: true}, // any combination of props supported by MenuItem
5659
* b: 'second item', // same as {label: 'second item'}
@@ -86,16 +89,6 @@ var Combo = (function (_React$Component) {
8689
*/
8790
this.viewportHeight = 0;
8891

89-
/**
90-
* Handles browser resize events, debounced by 150ms
91-
*
92-
* @memberof Combo
93-
* @instance
94-
* @private
95-
* @method handleResize
96-
*/
97-
this.handleResize = (0, _lodashFunctionDebounce2['default'])(this.onResize.bind(this), 150);
98-
9992
/**
10093
* Holds component state
10194
*
@@ -105,6 +98,8 @@ var Combo = (function (_React$Component) {
10598
* @type {Object}
10699
*/
107100
this.state = { maxHeight: null };
101+
102+
this.onResize = (0, _lodashFunctionDebounce2['default'])(this.onResize.bind(this), 150);
108103
}
109104

110105
/**
@@ -136,8 +131,8 @@ var Combo = (function (_React$Component) {
136131
}, {
137132
key: 'componentDidMount',
138133
value: function componentDidMount() {
139-
this.handleResize();
140-
window.addEventListener('resize', this.handleResize);
134+
this.onResize();
135+
window.addEventListener('resize', this.onResize);
141136
}
142137

143138
/**
@@ -151,7 +146,7 @@ var Combo = (function (_React$Component) {
151146
}, {
152147
key: 'componentWillUnmount',
153148
value: function componentWillUnmount() {
154-
window.removeEventListener('resize', this.handleResize);
149+
window.removeEventListener('resize', this.onResize);
155150
}
156151

157152
/**
@@ -172,7 +167,7 @@ var Combo = (function (_React$Component) {
172167
}
173168
this.viewportHeight = height;
174169

175-
this.setState({ maxHeight: height - _reactDom2['default'].findDOMNode(this).getBoundingClientRect().bottom - 5 });
170+
this.setState({ maxHeight: height - (0, _reactDom.findDOMNode)(this).getBoundingClientRect().bottom - 5 });
176171
}
177172

178173
/**
@@ -204,7 +199,11 @@ var Combo = (function (_React$Component) {
204199
}, {
205200
key: 'getLabel',
206201
value: function getLabel() {
207-
return this.normalize(this.props.items[this.props.value]).label;
202+
var _props = this.props;
203+
var items = _props.items;
204+
var value = _props.value;
205+
206+
return this.normalize(items[value]).label;
208207
}
209208

210209
/**
@@ -305,10 +304,6 @@ var Combo = (function (_React$Component) {
305304

306305
exports['default'] = Combo;
307306

308-
Combo.propTypes = {
309-
onChange: _reactLibReactWithAddons2['default'].PropTypes.func,
310-
items: _reactLibReactWithAddons2['default'].PropTypes.object.isRequired,
311-
value: _reactLibReactWithAddons2['default'].PropTypes.string.isRequired
312-
};
307+
Combo.propTypes = { onChange: func, items: object.isRequired, value: string.isRequired };
313308
Combo.defaultProps = { onChange: Function.prototype };
314309
module.exports = exports['default'];

development/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import React from 'react';
4-
import {Combo} from '../lib';
4+
import Combo from '../lib/Combo';
55

66
export default class App extends React.Component {
77

development/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import React from 'react';
4-
import ReactDOM from 'react-dom';
4+
import {render} from 'react-dom';
55
import App from './App';
66

7-
ReactDOM.render(<App />, document.getElementById('app'));
7+
render(<App />, document.getElementById('app'));

docs/Combo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ <h5>Parameters:</h5>
165165
<h5>Example</h5>
166166

167167
<pre class="prettyprint"><code>import {Combo} from 'react-bootstrap-combobox';
168+
import {render} from 'react-dom';
168169

169-
ReactDOM.render(&lt;Combo items={{
170+
render(&lt;Combo items={{
170171
// keys must be unique
171172
a: {label: 'first item', header: true}, // any combination of props supported by MenuItem
172173
b: 'second item', // same as {label: 'second item'}

lib/Combo.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* @flow */
22

33
import React from 'react/lib/ReactWithAddons';
4-
import ReactDOM from 'react-dom';
4+
import {findDOMNode} from 'react-dom';
55
import {Button, Dropdown, MenuItem} from 'react-bootstrap';
66
import map from 'lodash/collection/map';
77
import isString from 'lodash/lang/isString';
88
import debounce from 'lodash/function/debounce';
99

10-
const caret = <span className="caret" />;
10+
const caret = <span className="caret" />,
11+
{func, object, string} = React.PropTypes;
1112

1213
let uid = 0;
1314

@@ -18,8 +19,9 @@ let uid = 0;
1819
* @param {Object} props - A props config
1920
* @example
2021
* import {Combo} from 'react-bootstrap-combobox';
22+
* import {render} from 'react-dom';
2123
*
22-
* ReactDOM.render(<Combo items={{
24+
* render(<Combo items={{
2325
* // keys must be unique
2426
* a: {label: 'first item', header: true}, // any combination of props supported by MenuItem
2527
* b: 'second item', // same as {label: 'second item'}
@@ -36,8 +38,6 @@ export default class Combo extends React.Component {
3638

3739
viewportHeight: number;
3840

39-
handleResize: Function;
40-
4141
static propTypes: Object;
4242

4343
static defaultProps: Object;
@@ -65,16 +65,6 @@ export default class Combo extends React.Component {
6565
*/
6666
this.viewportHeight = 0;
6767

68-
/**
69-
* Handles browser resize events, debounced by 150ms
70-
*
71-
* @memberof Combo
72-
* @instance
73-
* @private
74-
* @method handleResize
75-
*/
76-
this.handleResize = debounce(this.onResize.bind(this), 150);
77-
7868
/**
7969
* Holds component state
8070
*
@@ -84,6 +74,8 @@ export default class Combo extends React.Component {
8474
* @type {Object}
8575
*/
8676
this.state = {maxHeight: null};
77+
78+
this.onResize = debounce(this.onResize.bind(this), 150);
8779
}
8880

8981
/**
@@ -110,8 +102,8 @@ export default class Combo extends React.Component {
110102
* @method componentDidMount
111103
*/
112104
componentDidMount() {
113-
this.handleResize();
114-
window.addEventListener('resize', this.handleResize);
105+
this.onResize();
106+
window.addEventListener('resize', this.onResize);
115107
}
116108

117109
/**
@@ -123,7 +115,7 @@ export default class Combo extends React.Component {
123115
* @method componentWillUnmount
124116
*/
125117
componentWillUnmount() {
126-
window.removeEventListener('resize', this.handleResize);
118+
window.removeEventListener('resize', this.onResize);
127119
}
128120

129121
/**
@@ -142,7 +134,7 @@ export default class Combo extends React.Component {
142134
}
143135
this.viewportHeight = height;
144136

145-
this.setState({maxHeight: height - ReactDOM.findDOMNode(this).getBoundingClientRect().bottom - 5});
137+
this.setState({maxHeight: height - findDOMNode(this).getBoundingClientRect().bottom - 5});
146138
}
147139

148140
/**
@@ -170,7 +162,9 @@ export default class Combo extends React.Component {
170162
* @return {string} a label of the currently active menu item
171163
*/
172164
getLabel(): string {
173-
return this.normalize(this.props.items[this.props.value]).label;
165+
const {items, value} = this.props;
166+
167+
return this.normalize(items[value]).label;
174168
}
175169

176170
/**
@@ -250,9 +244,5 @@ export default class Combo extends React.Component {
250244

251245
}
252246

253-
Combo.propTypes = {
254-
onChange: React.PropTypes.func,
255-
items: React.PropTypes.object.isRequired,
256-
value: React.PropTypes.string.isRequired
257-
};
247+
Combo.propTypes = {onChange: func, items: object.isRequired, value: string.isRequired};
258248
Combo.defaultProps = {onChange: Function.prototype};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@
5555
"proxyquire": "^1.7.3",
5656
"react-hot-loader": "^1.2.8",
5757
"release-script": "^0.5.3",
58-
"webcompiler": "^2.0.4"
58+
"webcompiler": "^2.0.5"
5959
}
6060
}

spec/ComboSpec.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('Combo', function () {
2323
if (!Combo) {
2424
return;
2525
}
26-
spyOn(Combo.prototype.onResize, 'bind').and.returnValue('bound handler');
2726
spyOn(Combo.prototype.renderMenuItem, 'bind').and.returnValue('bound renderMenuItem');
2827
cmp = new Combo({something: 'here'});
2928
});
@@ -53,17 +52,6 @@ describe('Combo', function () {
5352
expect(cmp.viewportHeight).toBe(0);
5453
});
5554

56-
it('calls the bind method', function () {
57-
if (!cmp) {
58-
return;
59-
}
60-
expect(cmp.onResize.bind).toHaveBeenCalledWith(cmp);
61-
});
62-
63-
it('debounces the bound handler', function () {
64-
expect(debounce).toHaveBeenCalledWith('bound handler', 150);
65-
});
66-
6755
it('initializes state', function () {
6856
if (!cmp) {
6957
return;
@@ -129,22 +117,22 @@ describe('Combo', function () {
129117
if (!cmp) {
130118
return;
131119
}
132-
spyOn(cmp, 'handleResize');
120+
spyOn(cmp, 'onResize');
133121
cmp.componentDidMount();
134122
});
135123

136124
it('calls handleResize', function () {
137125
if (!cmp) {
138126
return;
139127
}
140-
expect(cmp.handleResize).toHaveBeenCalled();
128+
expect(cmp.onResize).toHaveBeenCalled();
141129
});
142130

143131
it('sets up a resize listener on the window object', function () {
144132
if (!cmp) {
145133
return;
146134
}
147-
expect(addEventListener).toHaveBeenCalledWith('resize', cmp.handleResize);
135+
expect(addEventListener).toHaveBeenCalledWith('resize', cmp.onResize);
148136
});
149137

150138
});
@@ -162,7 +150,7 @@ describe('Combo', function () {
162150
if (!cmp) {
163151
return;
164152
}
165-
expect(removeEventListener).toHaveBeenCalledWith('resize', cmp.handleResize);
153+
expect(removeEventListener).toHaveBeenCalledWith('resize', cmp.onResize);
166154
});
167155

168156
});

0 commit comments

Comments
 (0)