Skip to content

Commit c6c353a

Browse files
Haroenvbobylito
authored andcommitted
fix(connectBreadcrumb): allow unmounting (#2815)
* fix(connectBreadcrumb): allow unmounting 1. added `unmountFn` 2. copied the `dispose` function from `HierarchicalMenu`, but remove the part about limit * chore: don't do anything with the facets * fix(breadcrumb): allow unmounting of the widget * chore: add novel * chore: unmount widget on unmount
1 parent c773f1a commit c6c353a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

dev/app/init-unmount-widgets.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ export default () => {
112112
)
113113
);
114114

115+
storiesOf('Breadcrumb').add(
116+
'default',
117+
wrapWithUnmount(
118+
container =>
119+
instantsearch.widgets.breadcrumb({
120+
container,
121+
attributes: [
122+
'hierarchicalCategories.lvl0',
123+
'hierarchicalCategories.lvl1',
124+
'hierarchicalCategories.lvl2',
125+
],
126+
rootPath: 'Cameras & Camcorders',
127+
}),
128+
{
129+
searchParameters: {
130+
hierarchicalFacetsRefinements: {
131+
'hierarchicalCategories.lvl0': [
132+
'Cameras & Camcorders > Digital Cameras',
133+
],
134+
},
135+
},
136+
}
137+
)
138+
);
139+
115140
storiesOf('Hits').add(
116141
'default',
117142
wrapWithUnmount(container => instantsearch.widgets.hits({ container }))

src/connectors/breadcrumb/connectBreadcrumb.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ Full documentation available at https://community.algolia.com/instantsearch.js/v
5050
* This is commonly used in websites that have a large amount of content organized in a hierarchical manner (usually e-commerce websites).
5151
* @type {Connector}
5252
* @param {function(BreadcrumbRenderingOptions, boolean)} renderFn Rendering function for the custom **Breadcrumb* widget.
53+
* @param {function} unmountFn Unmount function called when the widget is disposed.
5354
* @return {function(CustomBreadcrumbWidgetOptions)} Re-usable widget factory for a custom **Breadcrumb** widget.
5455
*/
55-
export default function connectBreadcrumb(renderFn) {
56+
export default function connectBreadcrumb(renderFn, unmountFn) {
5657
checkRendering(renderFn, usage);
5758
return (widgetParams = {}) => {
5859
const { attributes, separator = ' > ', rootPath = null } = widgetParams;
@@ -161,6 +162,10 @@ export default function connectBreadcrumb(renderFn) {
161162
false
162163
);
163164
},
165+
166+
dispose() {
167+
unmountFn();
168+
},
164169
};
165170
};
166171
}

src/widgets/breadcrumb/breadcrumb.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { render } from 'preact-compat';
1+
import React, { render, unmountComponentAtNode } from 'preact-compat';
22
import cx from 'classnames';
33

44
import Breadcrumb from '../../components/Breadcrumb/Breadcrumb';
5-
import { connectBreadcrumb } from '../../connectors';
5+
import connectBreadcrumb from '../../connectors/breadcrumb/connectBreadcrumb';
66
import defaultTemplates from './defaultTemplates.js';
77

88
import {
@@ -183,7 +183,9 @@ export default function breadcrumb({
183183
});
184184

185185
try {
186-
const makeBreadcrumb = connectBreadcrumb(specializedRenderer);
186+
const makeBreadcrumb = connectBreadcrumb(specializedRenderer, () =>
187+
unmountComponentAtNode(containerNode)
188+
);
187189
return makeBreadcrumb({ attributes, rootPath });
188190
} catch (e) {
189191
throw new Error(usage);

0 commit comments

Comments
 (0)