Skip to content

Commit

Permalink
feat(core): add a reload method on the InstantSearch component (#2637)
Browse files Browse the repository at this point in the history
  • Loading branch information
marielaures authored and bobylito committed Dec 29, 2017
1 parent 71c2d68 commit e73ff13
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dev/app/builtin/init-stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import initPriceRangesStories from './stories/price-ranges.stories';
import initRangeInputStories from './stories/range-input.stories.js';
import initRangeSliderStories from './stories/range-slider.stories';
import initRefinementListStories from './stories/refinement-list.stories';
import initReloadStories from './stories/reload.stories';
import initSearchBoxStories from './stories/search-box.stories';
import initSortBySelectorStories from './stories/sort-by-selector.stories';
import initStarRatingStories from './stories/star-rating.stories';
Expand All @@ -39,6 +40,7 @@ export default () => {
initRangeInputStories();
initRangeSliderStories();
initRefinementListStories();
initReloadStories();
initSearchBoxStories();
initSortBySelectorStories();
initStatsStories();
Expand Down
24 changes: 24 additions & 0 deletions dev/app/builtin/stories/reload.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable import/default */

import { storiesOf } from 'dev-novel';
import instantsearch from '../../../../index';
import { wrapWithHits } from '../../utils/wrap-with-hits.js';

const stories = storiesOf('Reload');

export default () => {
stories.add(
'default',
wrapWithHits(container => {
const button = document.createElement('button');
button.addEventListener('click', () => window.search.reload());
button.innerHTML = 'Reload InstantSearch';
const searchBoxContainer = document.createElement('div');
window.search.addWidget(
instantsearch.widgets.searchBox({ container: searchBoxContainer })
);
container.appendChild(button);
container.appendChild(searchBoxContainer);
})
);
};
13 changes: 12 additions & 1 deletion src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,18 @@ Usage: instantsearch({
}

/**
* The start methods ends the initialization of InstantSearch.js and triggers the
* The reload method clears the cached answers from Algolia and triggers a new search.
*
* @return {undefined} Does not return anything
*/
reload() {
if (this.helper) {
this.helper.clearCache().search();
}
}

/**
* The start method ends the initialization of InstantSearch.js and triggers the
* first search. This method should be called after all widgets have been added
* to the instance of InstantSearch.js. InstantSearch.js also supports adding and removing
* widgets after the start as an **EXPERIMENTAL** feature.
Expand Down

0 comments on commit e73ff13

Please sign in to comment.