Skip to content

Commit 0d2a455

Browse files
author
vvo
committedOct 7, 2015
fix(hierarchicalFacets): use a real attribute name for the hierarchicalFacet name
To avoid collisions when reordering widgets.
1 parent 7a7c638 commit 0d2a455

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed
 

‎widgets/hierarchicalMenu.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ var headerFooter = require('../decorators/headerFooter');
77
var RefinementList = autoHide(headerFooter(require('../components/RefinementList')));
88
var Template = require('../components/Template');
99

10-
var hierarchicalCounter = 0;
1110
var defaultTemplates = {
1211
header: '',
1312
item: '<a href="{{href}}">{{name}}</a> {{count}}',
@@ -48,16 +47,17 @@ function hierarchicalMenu({
4847
templates = defaultTemplates,
4948
transformData
5049
}) {
51-
hierarchicalCounter++;
52-
5350
var containerNode = utils.getContainerNode(container);
5451
var usage = 'Usage: hierarchicalMenu({container, attributes, [separator, sortBy, limit, cssClasses.{root, list, item}, templates.{header, item, footer}, transformData]})';
5552

5653
if (!container || !attributes || !attributes.length) {
5754
throw new Error(usage);
5855
}
5956

60-
var hierarchicalFacetName = 'instantsearch.js-hierarchicalMenu' + hierarchicalCounter;
57+
// we need to provide a hierarchicalFacet name for the search state
58+
// so that we can always map $hierarchicalFacetName => real attributes
59+
// we use the first attribute name
60+
var hierarchicalFacetName = attributes[0];
6161

6262
return {
6363
getConfiguration: () => ({

‎widgets/menu.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ var headerFooter = require('../decorators/headerFooter');
77
var RefinementList = autoHide(headerFooter(require('../components/RefinementList')));
88
var Template = require('../components/Template');
99

10-
var hierarchicalCounter = 0;
1110
var defaultTemplates = {
1211
header: '',
1312
item: '<a href="{{href}}">{{name}}</a> {{count}}',
@@ -46,16 +45,16 @@ function menu({
4645
transformData,
4746
hideWhenNoResults = true
4847
}) {
49-
hierarchicalCounter++;
50-
5148
var containerNode = utils.getContainerNode(container);
5249
var usage = 'Usage: menu({container, facetName, [sortBy, limit, cssClasses.{root,list,item}, templates.{header,item,footer}, transformData, hideWhenResults]})';
5350

5451
if (container === null || facetName === null) {
5552
throw new Error(usage);
5653
}
5754

58-
var hierarchicalFacetName = 'instantsearch.js-menu' + hierarchicalCounter;
55+
// we use a hierarchicalFacet for the menu because that's one of the use cases
56+
// of hierarchicalFacet: a flat menu
57+
var hierarchicalFacetName = facetName;
5958

6059
return {
6160
getConfiguration: () => ({

0 commit comments

Comments
 (0)
Please sign in to comment.