Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 110b10f

Browse files
committed
Create local reference to React.PropTypes
Makes it slightly easier to read while reducing the amount of property lookups needed.
1 parent 9992b1f commit 110b10f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/Autocomplete.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const React = require('react')
2+
const { PropTypes } = React
23
const { findDOMNode } = require('react-dom')
34
const scrollIntoView = require('dom-scroll-into-view')
45

@@ -10,43 +11,43 @@ let Autocomplete = React.createClass({
1011
/**
1112
* The items to display in the dropdown menu
1213
*/
13-
items: React.PropTypes.array.isRequired,
14+
items: PropTypes.array.isRequired,
1415
/**
1516
* The value to display in the input field
1617
*/
17-
value: React.PropTypes.any,
18+
value: PropTypes.any,
1819
/**
1920
* Arguments: `event: Event, value: String`
2021
*
2122
* Invoked every time the user changes the input's value.
2223
*/
23-
onChange: React.PropTypes.func,
24+
onChange: PropTypes.func,
2425
/**
2526
* Arguments: `value: String, item: Any`
2627
*
2728
* Invoked when the user selects an item from the dropdown menu.
2829
*/
29-
onSelect: React.PropTypes.func,
30+
onSelect: PropTypes.func,
3031
/**
3132
* Arguments: `item: Any, value: String`
3233
*
3334
* Invoked for each entry in `items` and its return value is used to
3435
* determine whether or not it should be displayed in the dropdown menu.
3536
* By default all items are always rendered.
3637
*/
37-
shouldItemRender: React.PropTypes.func,
38+
shouldItemRender: PropTypes.func,
3839
/**
3940
* Arguments: `itemA: Any, itemB: Any, value: String`
4041
*
4142
* The function which is used to sort `items` before display.
4243
*/
43-
sortItems: React.PropTypes.func,
44+
sortItems: PropTypes.func,
4445
/**
4546
* Arguments: `item: Any`
4647
*
4748
* Used to read the display value from each entry in `items`.
4849
*/
49-
getItemValue: React.PropTypes.func.isRequired,
50+
getItemValue: PropTypes.func.isRequired,
5051
/**
5152
* Arguments: `item: Any, isHighlighted: Boolean, styles: Object`
5253
*
@@ -55,7 +56,7 @@ let Autocomplete = React.createClass({
5556
* an optional set of styles that can be applied to improve the look/feel
5657
* of the items in the dropdown menu.
5758
*/
58-
renderItem: React.PropTypes.func.isRequired,
59+
renderItem: PropTypes.func.isRequired,
5960
/**
6061
* Arguments: `items: Array<Any>, value: String, styles: Object`
6162
*
@@ -64,51 +65,51 @@ let Autocomplete = React.createClass({
6465
* `styles` will contain { top, left, minWidth } which are the coordinates
6566
* of the top-left corner and the width of the dropdown menu.
6667
*/
67-
renderMenu: React.PropTypes.func,
68+
renderMenu: PropTypes.func,
6869
/**
6970
* Styles that are applied to the dropdown menu in the default `renderMenu`
7071
* implementation. If you override `renderMenu` and you want to use
7172
* `menuStyles` you must manually apply them (`this.props.menuStyles`).
7273
*/
73-
menuStyle: React.PropTypes.object,
74+
menuStyle: PropTypes.object,
7475
/**
7576
* Props that are applied to the `<input />` element rendered by
7677
* `Autocomplete`. Any properties supported by `HTMLInputElement` can be
7778
* specified, apart from the following which are set by `Autocomplete`:
7879
* value, autoComplete, role, aria-autocomplete
7980
*/
80-
inputProps: React.PropTypes.object,
81+
inputProps: PropTypes.object,
8182
/**
8283
* Props that are applied to the element which wraps the `<input />` and
8384
* dropdown menu elements rendered by `Autocomplete`.
8485
*/
85-
wrapperProps: React.PropTypes.object,
86+
wrapperProps: PropTypes.object,
8687
/**
8788
* This is a shorthand for `wrapperProps={{ style: <your styles> }}`.
8889
* Note that `wrapperStyle` is applied before `wrapperProps`, so the latter
8990
* will win if it contains a `style` entry.
9091
*/
91-
wrapperStyle: React.PropTypes.object,
92+
wrapperStyle: PropTypes.object,
9293
/**
9394
* Whether or not to automatically highlight the top match in the dropdown
9495
* menu.
9596
*/
96-
autoHighlight: React.PropTypes.bool,
97+
autoHighlight: PropTypes.bool,
9798
/**
9899
* Arguments: `isOpen: Boolean`
99100
*
100101
* Invoked every time the dropdown menu's visibility changes (i.e. every
101102
* time it is displayed/hidden).
102103
*/
103-
onMenuVisibilityChange: React.PropTypes.func,
104+
onMenuVisibilityChange: PropTypes.func,
104105
/**
105106
* Used to override the internal logic which displays/hides the dropdown
106107
* menu. This is useful if you want to force a certain state based on your
107108
* UX/business logic. Use it together with `onMenuVisibilityChange` for
108109
* fine-grained control over the dropdown menu dynamics.
109110
*/
110-
open: React.PropTypes.bool,
111-
debug: React.PropTypes.bool,
111+
open: PropTypes.bool,
112+
debug: PropTypes.bool,
112113
},
113114

114115
getDefaultProps () {

0 commit comments

Comments
 (0)