Permalink
Browse files

Merge branch 'TheSharpieOne-fix/remove-shared-cache'

  • Loading branch information...
bvaughn committed Oct 21, 2016
2 parents b4a087e + 4ba7bb2 commit a8f4118fea020f05516ce2216c1e4920c73a1373
Showing with 1,061 additions and 678 deletions.
  1. +14 −15 examples/dist/app.js
  2. +102 −25 examples/dist/bundle.js
  3. +825 −612 examples/dist/common.js
  4. +1 −0 examples/dist/example.css
  5. +100 −24 examples/dist/standalone.js
  6. +8 −2 src/Async.js
  7. +3 −0 src/Creatable.js
  8. +8 −0 test/Async-test.js
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -210,6 +210,7 @@
margin: -1px;
clip: rect(0, 0, 0, 0);
overflow: hidden;
float: left;
}
@-webkit-keyframes Select-animation-fadeIn {
from {
View
@@ -38,18 +38,26 @@ var propTypes = {
children: _react2['default'].PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element
ignoreAccents: _react2['default'].PropTypes.bool, // strip diacritics when filtering; defaults to true
ignoreCase: _react2['default'].PropTypes.bool, // perform case-insensitive filtering; defaults to true
loadingPlaceholder: _react.PropTypes.string.isRequired, // replaces the placeholder while options are loading
loadingPlaceholder: _react2['default'].PropTypes.oneOfType([// replaces the placeholder while options are loading
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
loadOptions: _react2['default'].PropTypes.func.isRequired, // callback to load options asynchronously; (inputValue: string, callback: Function): ?Promise
options: _react.PropTypes.array.isRequired, // array of options
placeholder: _react2['default'].PropTypes.oneOfType([// field placeholder, displayed when there's no value (shared with Select)
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
noResultsText: _react2['default'].PropTypes.oneOfType([// field noResultsText, displayed when no options come back from the server
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
onChange: _react2['default'].PropTypes.func, // onChange handler: function (newValue) {}
searchPromptText: _react2['default'].PropTypes.oneOfType([// label to prompt for search input
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node])
};
_react2['default'].PropTypes.string, _react2['default'].PropTypes.node]),
onInputChange: _react2['default'].PropTypes.func, // optional for keeping track of what is being typed
value: _react2['default'].PropTypes.any };
// initial field value
var defaultCache = {};
var defaultProps = {
autoload: true,
cache: {},
cache: defaultCache,
children: defaultChildren,
ignoreAccents: true,
ignoreCase: true,
@@ -66,6 +74,8 @@ var Async = (function (_Component) {
_get(Object.getPrototypeOf(Async.prototype), 'constructor', this).call(this, props, context);
this._cache = props.cache === defaultCache ? {} : props.cache;
this.state = {
isLoading: false,
options: props.options
@@ -95,14 +105,19 @@ var Async = (function (_Component) {
}
});
}
}, {
key: 'clearOptions',
value: function clearOptions() {
this.setState({ options: [] });
}
}, {
key: 'loadOptions',
value: function loadOptions(inputValue) {
var _this2 = this;
var _props = this.props;
var cache = _props.cache;
var loadOptions = _props.loadOptions;
var loadOptions = this.props.loadOptions;
var cache = this._cache;
if (cache && cache.hasOwnProperty(inputValue)) {
this.setState({
@@ -152,9 +167,10 @@ var Async = (function (_Component) {
}, {
key: '_onInputChange',
value: function _onInputChange(inputValue) {
var _props2 = this.props;
var ignoreAccents = _props2.ignoreAccents;
var ignoreCase = _props2.ignoreCase;
var _props = this.props;
var ignoreAccents = _props.ignoreAccents;
var ignoreCase = _props.ignoreCase;
var onInputChange = _props.onInputChange;
if (ignoreAccents) {
inputValue = (0, _utilsStripDiacritics2['default'])(inputValue);
@@ -164,24 +180,65 @@ var Async = (function (_Component) {
inputValue = inputValue.toLowerCase();
}
if (onInputChange) {
onInputChange(inputValue);
}
return this.loadOptions(inputValue);
}
}, {
key: 'inputValue',
value: function inputValue() {
if (this.select) {
return this.select.state.inputValue;
}
return '';
}
}, {
key: 'noResultsText',
value: function noResultsText() {
var _props2 = this.props;
var loadingPlaceholder = _props2.loadingPlaceholder;
var noResultsText = _props2.noResultsText;
var searchPromptText = _props2.searchPromptText;
var isLoading = this.state.isLoading;
var inputValue = this.inputValue();
if (isLoading) {
return loadingPlaceholder;
}
if (inputValue && noResultsText) {
return noResultsText;
}
return searchPromptText;
}
}, {
key: 'render',
value: function render() {
var _this3 = this;
var _props3 = this.props;
var children = _props3.children;
var loadingPlaceholder = _props3.loadingPlaceholder;
var placeholder = _props3.placeholder;
var searchPromptText = _props3.searchPromptText;
var _state = this.state;
var isLoading = _state.isLoading;
var options = _state.options;
var props = {
noResultsText: isLoading ? loadingPlaceholder : searchPromptText,
noResultsText: this.noResultsText(),
placeholder: isLoading ? loadingPlaceholder : placeholder,
options: isLoading ? [] : options
options: isLoading && loadingPlaceholder ? [] : options,
ref: function ref(_ref) {
return _this3.select = _ref;
},
onChange: function onChange(newValues) {
if (_this3.props.value && newValues.length > _this3.props.value.length) {
_this3.clearOptions();
}
_this3.props.onChange(newValues);
}
};
return children(_extends({}, this.props, props, {
@@ -305,6 +362,9 @@ var Creatable = _react2['default'].createClass({
// ({ label: string, labelKey: string, valueKey: string }): Object
newOptionCreator: _react2['default'].PropTypes.func,
// input keyDown handler: function (event) {}
onInputKeyDown: _react2['default'].PropTypes.func,
// See Select.propTypes.options
options: _react2['default'].PropTypes.array,
@@ -433,7 +493,9 @@ var Creatable = _react2['default'].createClass({
},
onInputKeyDown: function onInputKeyDown(event) {
var shouldKeyDownEventCreateNewOption = this.props.shouldKeyDownEventCreateNewOption;
var _props3 = this.props;
var shouldKeyDownEventCreateNewOption = _props3.shouldKeyDownEventCreateNewOption;
var onInputKeyDown = _props3.onInputKeyDown;
var focusedOption = this.select.getFocusedOption();
@@ -442,6 +504,8 @@ var Creatable = _react2['default'].createClass({
// Prevent decorated Select from doing anything additional with this keyDown event
event.preventDefault();
} else if (onInputKeyDown) {
onInputKeyDown(event);
}
},
@@ -456,13 +520,13 @@ var Creatable = _react2['default'].createClass({
render: function render() {
var _this = this;
var _props3 = this.props;
var _props3$children = _props3.children;
var children = _props3$children === undefined ? defaultChildren : _props3$children;
var newOptionCreator = _props3.newOptionCreator;
var shouldKeyDownEventCreateNewOption = _props3.shouldKeyDownEventCreateNewOption;
var _props4 = this.props;
var _props4$children = _props4.children;
var children = _props4$children === undefined ? defaultChildren : _props4$children;
var newOptionCreator = _props4.newOptionCreator;
var shouldKeyDownEventCreateNewOption = _props4.shouldKeyDownEventCreateNewOption;
var restProps = _objectWithoutProperties(_props3, ['children', 'newOptionCreator', 'shouldKeyDownEventCreateNewOption']);
var restProps = _objectWithoutProperties(_props4, ['children', 'newOptionCreator', 'shouldKeyDownEventCreateNewOption']);
var props = _extends({}, restProps, {
allowCreate: true,
@@ -938,14 +1002,26 @@ var Select = _react2['default'].createClass({
},
componentWillUnmount: function componentWillUnmount() {
document.removeEventListener('touchstart', this.handleTouchOutside);
if (!document.removeEventListener && document.detachEvent) {
document.detachEvent('ontouchstart', this.handleTouchOutside);
} else {
document.removeEventListener('touchstart', this.handleTouchOutside);
}
},
toggleTouchOutsideEvent: function toggleTouchOutsideEvent(enabled) {
if (enabled) {
document.addEventListener('touchstart', this.handleTouchOutside);
if (!document.addEventListener && document.attachEvent) {
document.attachEvent('ontouchstart', this.handleTouchOutside);
} else {
document.addEventListener('touchstart', this.handleTouchOutside);
}
} else {
document.removeEventListener('touchstart', this.handleTouchOutside);
if (!document.removeEventListener && document.detachEvent) {
document.detachEvent('ontouchstart', this.handleTouchOutside);
} else {
document.removeEventListener('touchstart', this.handleTouchOutside);
}
}
},
@@ -1601,7 +1677,7 @@ var Select = _react2['default'].createClass({
}
if (this.props.autosize) {
return _react2['default'].createElement(_reactInputAutosize2['default'], _extends({}, inputProps, { minWidth: '5px' }));
return _react2['default'].createElement(_reactInputAutosize2['default'], _extends({}, inputProps, { minWidth: '5' }));
}
return _react2['default'].createElement(
'div',
View
@@ -22,6 +22,7 @@ const propTypes = {
React.PropTypes.string,
React.PropTypes.node
]),
onChange: React.PropTypes.func, // onChange handler: function (newValue) {}
searchPromptText: React.PropTypes.oneOfType([ // label to prompt for search input
React.PropTypes.string,
React.PropTypes.node
@@ -30,9 +31,11 @@ const propTypes = {
value: React.PropTypes.any, // initial field value
};
const defaultCache = {};
const defaultProps = {
autoload: true,
cache: {},
cache: defaultCache,
children: defaultChildren,
ignoreAccents: true,
ignoreCase: true,
@@ -45,6 +48,8 @@ export default class Async extends Component {
constructor (props, context) {
super(props, context);
this._cache = props.cache === defaultCache ? {} : props.cache;
this.state = {
isLoading: false,
options: props.options,
@@ -77,7 +82,8 @@ export default class Async extends Component {
}
loadOptions (inputValue) {
const { cache, loadOptions } = this.props;
const { loadOptions } = this.props;
const cache = this._cache;
if (
cache &&
View
@@ -31,6 +31,9 @@ const Creatable = React.createClass({
// ({ label: string, labelKey: string, valueKey: string }): Object
newOptionCreator: React.PropTypes.func,
// input keyDown handler: function (event) {}
onInputKeyDown: React.PropTypes.func,
// See Select.propTypes.options
options: React.PropTypes.array,
View
@@ -117,6 +117,14 @@ describe('Async', () => {
typeSearchText('a');
return expect(loadOptions, 'was called times', 1);
});
it('should not use the same cache for every instance by default', () => {
createControl();
const instance1 = asyncInstance;
createControl();
const instance2 = asyncInstance;
expect(instance1._cache !== instance2._cache, 'to equal', true);
});
});
describe('loadOptions', () => {

0 comments on commit a8f4118

Please sign in to comment.