Skip to content

Commit

Permalink
feat(connectors): setValue() -> refine() / currentValue -> `cur…
Browse files Browse the repository at this point in the history
…rentRefinement`
  • Loading branch information
iam4x committed Mar 27, 2017
1 parent 154cdb5 commit ec7806c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ describe('connectHitsPerPageSelector', () => {
});

const firstRenderingOptions = rendering.lastCall.args[0];
const {setValue} = firstRenderingOptions;
const {refine} = firstRenderingOptions;
expect(helper.getQueryParameter('hitsPerPage')).toBe(11);
setValue(3);
refine(3);
expect(helper.getQueryParameter('hitsPerPage')).toBe(3);

widget.render({
Expand All @@ -102,7 +102,7 @@ describe('connectHitsPerPageSelector', () => {
});

const secondRenderingOptions = rendering.lastCall.args[0];
const {setValue: renderSetValue} = secondRenderingOptions;
const {refine: renderSetValue} = secondRenderingOptions;
expect(helper.getQueryParameter('hitsPerPage')).toBe(3);
renderSetValue(10);
expect(helper.getQueryParameter('hitsPerPage')).toBe(10);
Expand Down Expand Up @@ -134,8 +134,8 @@ describe('connectHitsPerPageSelector', () => {
});

const firstRenderingOptions = rendering.lastCall.args[0];
expect(firstRenderingOptions.currentValue).toBe(7);
firstRenderingOptions.setValue(3);
expect(firstRenderingOptions.currentRefinement).toBe(7);
firstRenderingOptions.refine(3);

widget.render({
results: new SearchResults(helper.state, [{}]),
Expand All @@ -145,7 +145,7 @@ describe('connectHitsPerPageSelector', () => {
});

const secondRenderingOptions = rendering.lastCall.args[0];
expect(secondRenderingOptions.currentValue).toBe(3);
expect(secondRenderingOptions.currentRefinement).toBe(3);
});

it('adds an option for the unselecting values, when the current hitsPerPage is defined elsewhere', () => {
Expand All @@ -172,7 +172,7 @@ describe('connectHitsPerPageSelector', () => {

const firstRenderingOptions = rendering.lastCall.args[0];
expect(firstRenderingOptions.options.length).toBe(3);
firstRenderingOptions.setValue(firstRenderingOptions.options[0].value);
firstRenderingOptions.refine(firstRenderingOptions.options[0].value);
expect(helper.getQueryParameter('hitsPerPage')).toBe(undefined);

// Reset the hitsPerPage to an actual value
Expand All @@ -187,7 +187,7 @@ describe('connectHitsPerPageSelector', () => {

const secondRenderingOptions = rendering.lastCall.args[0];
expect(secondRenderingOptions.options.length).toBe(3);
secondRenderingOptions.setValue(secondRenderingOptions.options[0].value);
secondRenderingOptions.refine(secondRenderingOptions.options[0].value);
expect(helper.getQueryParameter('hitsPerPage')).toBe(undefined);
});
});
20 changes: 10 additions & 10 deletions src/connectors/hits-per-page-selector/connectHitsPerPageSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const usage = `Usage:
var customHitsPerPage = connectHitsPerPageSelector(function render(params, isFirstRendering) {
// params = {
// options,
// currentValue,
// setValue,
// currentRefinement,
// refine,
// hasNoResults,
// instantSearchInstance,
// widgetParams,
Expand All @@ -29,8 +29,8 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
* @property {Object[]} options Array of objects defining the different values and labels
* @property {number} options[0].value number of hits to display per page
* @property {string} options[0].label Label to display in the option
* @property {number} currentValue the currently selected value of hitsPerPage
* @property {function(number)} setValue sets the number of hits per page and trigger a search
* @property {number} currentRefinement the currently selected value of hitsPerPage
* @property {function(number)} refine sets the number of hits per page and trigger a search
* @property {boolean} hasNoResults true if there were no results in the last search
* @property {InstantSearch} instantSearchInstance the instance of instantsearch on which the widget is attached
* @property {Object} widgetParams all original options forwarded to rendering
Expand Down Expand Up @@ -85,30 +85,30 @@ export default function connectHitsPerPageSelector(renderFn) {
options = [{value: undefined, label: ''}].concat(options);
}

const currentValue = state.hitsPerPage;
const currentRefinement = state.hitsPerPage;

this.setHitsPerPage = value => helper
.setQueryParameter('hitsPerPage', value)
.search();

renderFn({
currentValue,
currentRefinement,
options,
setValue: this.setHitsPerPage,
refine: this.setHitsPerPage,
hasNoResults: true,
widgetParams,
instantSearchInstance,
}, true);
},

render({state, results, instantSearchInstance}) {
const currentValue = state.hitsPerPage;
const currentRefinement = state.hitsPerPage;
const hasNoResults = results.nbHits === 0;

renderFn({
currentValue,
currentRefinement,
options,
setValue: this.setHitsPerPage,
refine: this.setHitsPerPage,
hasNoResults,
widgetParams,
instantSearchInstance,
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/hits-per-page-selector/hits-per-page-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const renderer = ({
cssClasses,
autoHideContainer,
}) => ({
currentValue,
currentRefinement,
options,
setValue,
refine,
hasNoResults,
}, isFirstRendering) => {
if (isFirstRendering) return;

ReactDOM.render(
<Selector
cssClasses={cssClasses}
currentValue={currentValue}
currentValue={currentRefinement}
options={options}
setValue={setValue}
setValue={refine}
shouldAutoHideContainer={autoHideContainer && hasNoResults}
/>,
containerNode
Expand Down

0 comments on commit ec7806c

Please sign in to comment.