Skip to content

Commit 2486f36

Browse files
author
Alexandre Stanislawski
committed
feat(connector): update doc, move setValue to refine in SortBySelector
1 parent e26e8e2 commit 2486f36

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/connectors/sort-by-selector/__tests__/connectSortBySelector-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ describe('connectSortBySelector', () => {
100100
{ // first rendering
101101
expect(helper.state.index).toBe(indices[0].name);
102102
const renderOptions = rendering.lastCall.args[0];
103-
const {setValue, currentValue} = renderOptions;
103+
const {refine, currentValue} = renderOptions;
104104
expect(currentValue).toBe(helper.state.index);
105-
setValue('bip');
105+
refine('bip');
106106
expect(helper.state.index).toBe('bip');
107107
expect(helper.search.callCount).toBe(1);
108108
}
@@ -117,9 +117,9 @@ describe('connectSortBySelector', () => {
117117
{ // Second rendering
118118
expect(helper.state.index).toBe('bip');
119119
const renderOptions = rendering.lastCall.args[0];
120-
const {setValue, currentValue} = renderOptions;
120+
const {refine, currentValue} = renderOptions;
121121
expect(currentValue).toBe('bip');
122-
setValue('bop');
122+
refine('bop');
123123
expect(helper.state.index).toBe('bop');
124124
expect(helper.search.callCount).toBe(2);
125125
}

src/connectors/sort-by-selector/connectSortBySelector.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ var customSortBySelector = connectSortBySelector(function render(params, isFirst
55
// params = {
66
// currentValue,
77
// options,
8-
// setValue,
8+
// refine,
99
// hasNoResults,
10+
// instantSearchInstance
1011
// }
1112
});
1213
search.addWidget(
@@ -24,10 +25,11 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
2425

2526
/**
2627
* @typedef {Object} SortBySelectorRenderingOptions
27-
* @property {string} currentValue
28-
* @property {Object[]} options
29-
* @property {function} setValue
30-
* @property {boolean} hasNoResults
28+
* @property {string} currentValue the currently selected index
29+
* @property {Object[]} options all the available indices
30+
* @property {function} refine switch indices and do a new search
31+
* @property {boolean} hasNoResults a boolean that indicates if there were no results during that last search
32+
* @property {InstantSearch} instantSearchInstance the instance of instantsearch on which the widget is attached
3133
*/
3234

3335
/**
@@ -46,7 +48,7 @@ export default function connectSortBySelector(renderFn) {
4648
const selectorOptions = indices.map(({label, name}) => ({label, value: name}));
4749

4850
return {
49-
init({helper}) {
51+
init({helper, instantSearchInstance}) {
5052
const currentIndex = helper.getIndex();
5153
const isIndexInList = indices.find(({name}) => name === currentIndex);
5254

@@ -61,17 +63,19 @@ export default function connectSortBySelector(renderFn) {
6163
renderFn({
6264
currentValue: currentIndex,
6365
options: selectorOptions,
64-
setValue: this.setIndex,
66+
refine: this.setIndex,
6567
hasNoResults: true,
68+
instantSearchInstance,
6669
}, true);
6770
},
6871

69-
render({helper, results}) {
72+
render({helper, results, instantSearchInstance}) {
7073
renderFn({
7174
currentValue: helper.getIndex(),
7275
options: selectorOptions,
73-
setValue: this.setIndex,
76+
refine: this.setIndex,
7477
hasNoResults: results.nbHits === 0,
78+
instantSearchInstance,
7579
}, false);
7680
},
7781
};

src/widgets/sort-by-selector/sort-by-selector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const renderer = ({
1515
}) => ({
1616
currentValue,
1717
options,
18-
setValue,
18+
refine,
1919
hasNoResults,
2020
}, isFirstRendering) => {
2121
if (isFirstRendering) return;
@@ -27,7 +27,7 @@ const renderer = ({
2727
cssClasses={cssClasses}
2828
currentValue={currentValue}
2929
options={options}
30-
setValue={setValue}
30+
setValue={refine}
3131
shouldAutoHideContainer={shouldAutoHideContainer}
3232
/>,
3333
containerNode

0 commit comments

Comments
 (0)