Skip to content

Commit

Permalink
Improved searchEpic (#1667)
Browse files Browse the repository at this point in the history
* Improved searchEpic

* fixed test
  • Loading branch information
MV88 authored Mar 31, 2017
1 parent 966c6a5 commit cf9d474
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web/client/components/mapcontrols/search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ let SearchBar = React.createClass({
}
},
onFocus() {
if (this.props.typeAhead ) {
if (this.props.typeAhead && this.props.searchText ) {
this.search();
}
},
Expand Down
6 changes: 3 additions & 3 deletions web/client/epics/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ describe('search Epics', () => {

let actions = store.getActions();
expect(actions.length).toBe(4);
expect(actions[1].type).toBe(CHANGE_MAP_VIEW);
expect(actions[2].type).toBe(TEXT_SEARCH_ADD_MARKER);
expect(actions[3].type).toBe(TEXT_SEARCH_RESULTS_PURGE);
expect(actions[1].type).toBe(TEXT_SEARCH_RESULTS_PURGE);
expect(actions[2].type).toBe(CHANGE_MAP_VIEW);
expect(actions[3].type).toBe(TEXT_SEARCH_ADD_MARKER);
});

it('searchItemSelected epic with nested services', () => {
Expand Down
4 changes: 2 additions & 2 deletions web/client/epics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const searchEpic = action$ =>
.mergeAll()
.scan( (oldRes, newRes) => [...oldRes, ...newRes].sort( (a, b) => get(b, "__PRIORITY__") - get(a, "__PRIORITY__") ) .slice(0, 15))
.map((results) => searchResultLoaded(results, false))
.takeUntil(action$.ofType([ TEXT_SEARCH_RESULTS_PURGE, TEXT_SEARCH_RESET, TEXT_SEARCH_ITEM_SELECTED]))
.startWith(searchTextLoading(true))
.takeUntil(action$.ofType( TEXT_SEARCH_RESULTS_PURGE, TEXT_SEARCH_RESET, TEXT_SEARCH_ITEM_SELECTED))
.concat([searchTextLoading(false)])
.catch(e => Rx.Observable.from([searchResultError(e), searchTextLoading(false)]))
);
Expand Down Expand Up @@ -144,7 +144,7 @@ const searchItemSelected = action$ =>
let searchTextTemplate = item.__SERVICE__ && item.__SERVICE__.searchTextTemplate;
let searchTextStream = searchTextTemplate ? Rx.Observable.of(searchTextChanged(generateTemplateString(searchTextTemplate)(item))) : Rx.Observable.empty();

return Rx.Observable.merge(itemSelectionStream, Rx.Observable.of(resultsPurge()), nestedServicesStream, searchTextStream);
return Rx.Observable.of(resultsPurge()).concat(itemSelectionStream, nestedServicesStream, searchTextStream);
});

/**
Expand Down

0 comments on commit cf9d474

Please sign in to comment.