Skip to content

Commit f783fea

Browse files
committed
feat(pagination): setPage() -> refine() / currentPage -> currentRefinement
1 parent 998faf1 commit f783fea

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/connectors/pagination/__tests__/connectPagination-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('connectPagination', () => {
3737

3838
// should provide good values for the first rendering
3939
const firstRenderingOptions = rendering.lastCall.args[0];
40-
expect(firstRenderingOptions.currentPage).toBe(0);
40+
expect(firstRenderingOptions.currentRefinement).toBe(0);
4141
expect(firstRenderingOptions.nbHits).toBe(0);
4242
expect(firstRenderingOptions.nbPages).toBe(0);
4343
expect(firstRenderingOptions.widgetParams).toEqual({
@@ -64,7 +64,7 @@ describe('connectPagination', () => {
6464

6565
// should call the rendering with values from the results
6666
const secondRenderingOptions = rendering.lastCall.args[0];
67-
expect(secondRenderingOptions.currentPage).toBe(0);
67+
expect(secondRenderingOptions.currentRefinement).toBe(0);
6868
expect(secondRenderingOptions.nbHits).toBe(1);
6969
expect(secondRenderingOptions.nbPages).toBe(1);
7070
}
@@ -88,8 +88,8 @@ describe('connectPagination', () => {
8888

8989
{ // first rendering
9090
const renderOptions = rendering.lastCall.args[0];
91-
const {setPage} = renderOptions;
92-
setPage(2);
91+
const {refine} = renderOptions;
92+
refine(2);
9393
expect(helper.getPage()).toBe(2);
9494
expect(helper.search.callCount).toBe(1);
9595
}
@@ -103,8 +103,8 @@ describe('connectPagination', () => {
103103

104104
{ // Second rendering
105105
const renderOptions = rendering.lastCall.args[0];
106-
const {setPage} = renderOptions;
107-
setPage(7);
106+
const {refine} = renderOptions;
107+
refine(7);
108108
expect(helper.getPage()).toBe(7);
109109
expect(helper.search.callCount).toBe(2);
110110
}

src/connectors/pagination/connectPagination.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const usage = `Usage:
44
var customPagination = connectPagination(function render(params, isFirstRendering) {
55
// params = {
66
// createURL,
7-
// currentPage,
7+
// currentRefinement,
88
// nbHits,
99
// nbPages,
10-
// setPage,
10+
// refine,
1111
// widgetParams,
1212
// }
1313
});
@@ -27,10 +27,10 @@ Full documentation available at https://community.algolia.com/instantsearch.js/c
2727
/**
2828
* @typedef PaginationRenderingOptions
2929
* @property {function(number)} createURL create URL's for the next state, the number is the page to generate the URL for
30-
* @property {number} currentPage the number of the page currently displayed
30+
* @property {number} currentRefinement the number of the page currently displayed
3131
* @property {number} nbHits the number of hits computed for the last query (can be approximated)
3232
* @property {number} nbPages the number of pages for the result set
33-
* @property {function} setPage set the current page and trigger a search
33+
* @property {function} refine set the current page and trigger a search
3434
* @property {Object} widgetParams all original options forwarded to rendering
3535
* @property {InstantSearch} instantSearchInstance the instance of instantsearch on which the widget is attached
3636
*/
@@ -48,19 +48,19 @@ export default function connectPagination(renderFn) {
4848

4949
return {
5050
init({helper, createURL, instantSearchInstance}) {
51-
this.setPage = page => {
51+
this.refine = page => {
5252
helper.setPage(page);
5353
helper.search();
5454
};
5555

56-
this.createURL = state => page => createURL(state.setPage(page));
56+
this.createURL = state => page => createURL(state.refine(page));
5757

5858
renderFn({
5959
createURL: this.createURL(helper.state),
60-
currentPage: helper.getPage() || 0,
60+
currentRefinement: helper.getPage() || 0,
6161
nbHits: 0,
6262
nbPages: 0,
63-
setPage: this.setPage,
63+
refine: this.refine,
6464
widgetParams,
6565
instantSearchInstance,
6666
}, true);
@@ -75,8 +75,8 @@ export default function connectPagination(renderFn) {
7575
render({results, state, instantSearchInstance}) {
7676
renderFn({
7777
createURL: this.createURL(state),
78-
currentPage: state.page,
79-
setPage: this.setPage,
78+
currentRefinement: state.page,
79+
refine: this.refine,
8080
nbHits: results.nbHits,
8181
nbPages: this.getMaxPage(results),
8282
widgetParams,

src/widgets/pagination/__tests__/pagination-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('pagination()', () => {
5151
});
5252

5353
it('sets the page', () => {
54-
widget.setPage(helper, 42);
54+
widget.refine(helper, 42);
5555
expect(helper.setPage.calledOnce).toBe(true);
5656
expect(helper.search.calledOnce).toBe(true);
5757
});
@@ -81,7 +81,7 @@ describe('pagination()', () => {
8181
it('should not scroll', () => {
8282
widget = pagination({container, scrollTo: false});
8383
widget.init({helper});
84-
widget.setPage(helper, 2);
84+
widget.refine(helper, 2);
8585
expect(scrollIntoView.calledOnce).toBe(false, 'scrollIntoView never called');
8686
});
8787

src/widgets/pagination/pagination.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const renderer = ({
2828
scrollToNode,
2929
}) => ({
3030
createURL,
31-
currentPage,
31+
currentRefinement,
3232
nbHits,
3333
nbPages,
34-
setPage,
34+
refine,
3535
}, isFirstRendering) => {
3636
if (isFirstRendering) return;
3737

38-
const setCurrentPage = () => {
39-
setPage();
38+
const setCurrrentPage = () => {
39+
refine();
4040

4141
if (scrollToNode !== false) {
4242
scrollToNode.scrollIntoView();
@@ -49,12 +49,12 @@ const renderer = ({
4949
<Pagination
5050
createURL={createURL}
5151
cssClasses={cssClasses}
52-
currentPage={currentPage}
52+
currentPage={currentRefinement}
5353
labels={labels}
5454
nbHits={nbHits}
5555
nbPages={nbPages}
5656
padding={padding}
57-
setCurrentPage={setCurrentPage}
57+
setCurrentPage={setCurrrentPage}
5858
shouldAutoHideContainer={shouldAutoHideContainer}
5959
showFirstLast={showFirstLast}
6060
/>,

0 commit comments

Comments
 (0)