Skip to content

Commit

Permalink
feat(helper): remove previousPage and nextPage (#6565)
Browse files Browse the repository at this point in the history
These functions are redundant with the setPage and setQueryParameter/s/setState functions and aren't used in InstantSearch

BREAKING CHANGE: remove usage of helper.previousPage, helper.nextPage and use setPage, setState or setQueryParameter instead
  • Loading branch information
Haroenv committed Feb 17, 2025
1 parent 3e9df7f commit 32f50ac
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ Finally, you can retrieve if there is an on-going search with `hasPendingRequest

{{> jsdoc jsdoc/helper/setPage}}

{{> jsdoc jsdoc/helper/nextPage}}

{{> jsdoc jsdoc/helper/previousPage}}

{{> jsdoc jsdoc/helper/getPage}}

### Query parameters
Expand Down
2 changes: 0 additions & 2 deletions packages/algoliasearch-helper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ declare namespace algoliasearchHelper {
toggleFacetExclusion(facet: string, value: string): this;
toggleFacetRefinement(facet: string, value: string): this;
toggleTag(tag: string): this;
nextPage(): this;
previousPage(): this;
setPage(page: number): this;
setQueryParameter<SearchParameter extends keyof PlainSearchParameters>(
parameter: SearchParameter,
Expand Down
28 changes: 0 additions & 28 deletions packages/algoliasearch-helper/src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,34 +989,6 @@ AlgoliaSearchHelper.prototype.toggleTag = function (tag) {
return this;
};

/**
* Increments the page number by one.
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
* @fires change
* @chainable
* @example
* helper.setPage(0).nextPage().getPage();
* // returns 1
*/
AlgoliaSearchHelper.prototype.nextPage = function () {
var page = this.state.page || 0;
return this.setPage(page + 1);
};

/**
* Decrements the page number by one.
* @fires change
* @return {AlgoliaSearchHelper} Method is chainable, it returns itself
* @chainable
* @example
* helper.setPage(1).previousPage().getPage();
* // returns 0
*/
AlgoliaSearchHelper.prototype.previousPage = function () {
var page = this.state.page || 0;
return this.setPage(page - 1);
};

/**
* Updates the current page.
* @function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var algoliasearchHelper = require('../../../index');

var fakeClient = {};

test('setChange should change the current page', function () {
test('setPage should change the current page', function () {
var helper = algoliasearchHelper(fakeClient, null, null);

expect(helper.getPage()).toBeUndefined();
Expand All @@ -14,40 +14,6 @@ test('setChange should change the current page', function () {
expect(helper.getPage()).toBe(3);
});

test('nextPage should increment the page by one', function () {
var helper = algoliasearchHelper(fakeClient, null, null);

expect(helper.getPage()).toBeUndefined();

helper.nextPage();
helper.nextPage();
helper.nextPage();

expect(helper.getPage()).toBe(3);
});

test('previousPage should decrement the current page by one', function () {
var helper = algoliasearchHelper(fakeClient, null, null);

expect(helper.getPage()).toBeUndefined();

helper.setPage(3);

expect(helper.getPage()).toBe(3);

helper.previousPage();

expect(helper.getPage()).toBe(2);
});

test('previousPage should throw an error without a current page', function () {
var helper = algoliasearchHelper(fakeClient, null, null);

expect(function () {
helper.previousPage();
}).toThrow('Page requested below 0.');
});

test('pages should be reset if the mutation might change the number of pages', function () {
var helper = algoliasearchHelper(fakeClient, '', {
facets: ['facet1', 'f2'],
Expand Down

0 comments on commit 32f50ac

Please sign in to comment.