Skip to content

Commit

Permalink
Merge pull request #300 from unchartedsoftware/issue/299
Browse files Browse the repository at this point in the history
#299 - make change events optional when manually setting/clearing sug…
  • Loading branch information
Ghnuberath authored Apr 24, 2018
2 parents 87dde2d + f5d8ad4 commit d95290f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/components/search-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class SearchBar extends Component {
}
}

async setValue (newValue) {
async setValue (newValue, shouldFireChangeEvent = true) {
const oldQueryValues = this.state.tokenValues;
this.blur();
const tokens = await Promise.all(newValue.map(v => {
Expand All @@ -151,10 +151,12 @@ export class SearchBar extends Component {
active: false,
editing: false
});
this.queryChanged(oldQueryValues, false);
if (shouldFireChangeEvent) {
this.queryChanged(oldQueryValues, false);
}
}

async setSuggestions (newSuggestions) {
async setSuggestions (newSuggestions, shouldFireChangeEvent = true) {
const oldSuggestions = this.state.suggestions;
this.blur();
const suggestions = await Promise.all(newSuggestions.map((v) => {
Expand All @@ -164,7 +166,9 @@ export class SearchBar extends Component {
this.setState({
suggestions: suggestions
});
this.suggestionsChanged(oldSuggestions);
if (shouldFireChangeEvent) {
this.suggestionsChanged(oldSuggestions);
}
}

componentWillMount () {
Expand Down
12 changes: 6 additions & 6 deletions src/lex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class Lex extends EventEmitter {
/**
* Completely reset the search state.
*/
reset () {
reset (shouldFireChangeEvent = true) {
if (this.searchBar) {
this.searchBar.setValue(_defaultValue.get(this));
this.searchBar.setValue(_defaultValue.get(this), shouldFireChangeEvent);
}
}

Expand All @@ -211,9 +211,9 @@ class Lex extends EventEmitter {
* @param {Object[]} suggestions - One or more token values (an array of objects of boxed or unboxed values) to display as "suggestions" in the search bar. Will have different styling than a traditional token, and offer the user an "ADD" button they can use to lock the preview token into their query.
* @returns {Promise} Resolves when the attempt to rewrite the query is finished. This is `async` due to the fact that `State`s such as `OptionState`s might retrieve their options asynchronously.
*/
async setSuggestions (suggestions) {
async setSuggestions (suggestions, shouldFireChangeEvent = true) {
if (this.searchBar) {
return this.searchBar.setSuggestions(suggestions);
return this.searchBar.setSuggestions(suggestions, shouldFireChangeEvent);
}
}

Expand All @@ -232,9 +232,9 @@ class Lex extends EventEmitter {
* @param {Object[]} query - One or more token values (an array of objects of boxed or unboxed values) to display to overwrite the current query with.
* @returns {Promise} Resolves when the attempt to rewrite the query is finished. This is `async` due to the fact that `State`s such as `OptionState`s might retrieve their options asynchronously.
*/
async setQuery (query) {
async setQuery (query, shouldFireChangeEvent = true) {
if (this.searchBar) {
return this.searchBar.setValue(query);
return this.searchBar.setValue(query, shouldFireChangeEvent);
}
}
}
Expand Down

0 comments on commit d95290f

Please sign in to comment.