Skip to content

Commit

Permalink
feat(connector): provide instantsearch instance at render
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Stanislawski committed Mar 21, 2017
1 parent e8278d2 commit 12a7935
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/connectors/menu/connectMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default function connectMenu(renderFn) {
.toggleRefinement(attributeName, facetValue)
.search();

this._instantSearchInstance = instantSearchInstance;
this._helper = helper;

renderFn({
Expand All @@ -71,13 +70,12 @@ export default function connectMenu(renderFn) {
createURL: this._createURL,
refine: this._refine,
helper: this._helper,
isFirstSearch: true,
instantSearchInstance,
canRefine: false,
}, true);
},

render({results, state}) {
render({results, state, instantSearchInstance}) {
const items = results.getFacetValues(attributeName, {sortBy}).data || [];

renderFn({
Expand All @@ -86,8 +84,7 @@ export default function connectMenu(renderFn) {
createURL: this._createURL,
refine: this._refine,
helper: this._helper,
isFirstSearch: false,
instantSearchInstance: this._instantSearchInstance,
instantSearchInstance,
canRefine: items.length > 0,
}, false);
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Usage: instantsearch({
state,
helper,
createURL: this._createAbsoluteURL,
instantSearchInstance: this,
});
});
this.emit('render');
Expand Down
5 changes: 2 additions & 3 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import EventEmitter from 'events';


import range from 'lodash/range';
import sinon from 'sinon';

Expand Down Expand Up @@ -243,7 +241,7 @@ describe('InstantSearch lifecycle', () => {
helper.emit('result', results, helper.state);
});

it('calls widget.render({results, state, helper, templatesConfig})', () => {
it('calls widget.render({results, state, helper, templatesConfig, instantSearchInstance})', () => {
expect(widget.render.calledOnce).toBe(true, 'widget.render called once');
expect(widget.render.args[0])
.toEqual([{
Expand All @@ -252,6 +250,7 @@ describe('InstantSearch lifecycle', () => {
state: helper.state,
helper,
templatesConfig: search.templatesConfig,
instantSearchInstance: search,
}]);
});
});
Expand Down

0 comments on commit 12a7935

Please sign in to comment.