Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): dispose sets helper to null #3415

Merged
merged 5 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ class InstantSearch extends EventEmitter {
*/
dispose() {
this.removeWidgets(this.widgets);
// You can not start an instance two times, therefore a disposed instance needs to set started as false
// otherwise this can not be restarted at a later point.
this.started = false;

// The helper needs to be reset to perform the next search from a fresh state.
// If not reset, it would use the state stored before calling `dispose()`.
this.helper = null;
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
}

createURL(params) {
Expand Down
21 changes: 21 additions & 0 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,27 @@ describe('InstantSearch lifecycle', () => {
});
});

describe('dispose', () => {
it('should set the helper to `null`', () => {
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
const search = new InstantSearch({
indexName: '',
searchClient: { async search() {} },
});

search.start();

expect(search.helper).not.toBe(null);

search.dispose();

expect(search.helper).toBe(null);

search.start();

expect(search.helper).not.toBe(null);
});
});

it('Allows to start without widgets', () => {
const instance = new InstantSearch({
searchClient: {
Expand Down