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(helper): expose .lastResults to .helper #4170

Merged
merged 3 commits into from Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib/__tests__/InstantSearch-test.js
Expand Up @@ -239,6 +239,24 @@ describe('InstantSearch', () => {

expect(search.insightsClient).toBe(insightsClient);
});

it("exposes helper's last results", async () => {
const searchClient = createSearchClient();

const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

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

search.start();

await runAllMicroTasks();

// could be null if we don't pretend the main helper is the one who searched
expect(search.helper.lastResults).not.toBe(null);
});
});

describe('addWidget(s)', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/widgets/index/index.ts
Expand Up @@ -459,11 +459,16 @@ See https://www.algolia.com/doc/guides/building-search-ui/widgets/customize-an-e
}
});

derivedHelper.on('result', () => {
derivedHelper.on('result', ({ results }) => {
// The index does not render the results it schedules a new render
// to let all the other indices emit their own results. It allows us to
// run the render process in one pass.
instantSearchInstance.scheduleRender();

// the derived helper is the one which actually searches, but the 'main'
// helper is exposed e.g. via instance.helper, which needs to have the
// results accessible as well.
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
helper!.lastResults = results;
});

localWidgets.forEach(widget => {
Expand Down