Replies: 4 comments
-
Hey @iam4x! Do you remember in which cases you needed to access the container node in the connector? Usually we specify the To my knowledge, the connector nevers needs to access the container node because it only calls the |
Beta Was this translation helpful? Give feedback.
-
I think the original idea here is that if you give a container to the renderfn & make elements. If you don't particularly save it on the instance, you don't have access to that selector to unmount |
Beta Was this translation helpful? Give feedback.
-
We could provide the const makeHits = instantsearch.connectors.connectHits(
function renderHits({ hits, widgetParams }) {
$(widgetParams.container).html(hits.map(hit => JSON.stringify(hit)));
},
function unmount({ widgetParams }) {
$(widgetParams.container).remove();
}
);
search.addWidget(
makeHits({
container: ".hits"
})
); |
Beta Was this translation helpful? Give feedback.
-
I don't think it makes even sense to have the unmount function being exposed as another argument of the connector. I believe we should rather see the render function as a side effect in vanilla JavaScript (because manipulating the DOM is a side effect), and then we should clean up the effect in a function returned by the renderer. Given your example above @samouss, that would look like: const makeHits = instantsearch.connectors.connectHits(
({ hits, widgetParams }) => {
$(widgetParams.container).html(hits.map(hit => JSON.stringify(hit)));
return () => {
$(widgetParams.container).remove();
};
}
);
search.addWidget(
makeHits({
container: '.hits',
})
); It makes even more sense when you start attaching events to avoid memory leaks. This assumes that we get rid of the I've been thinking a lot about our render API lately and I think I've got some interesting ideas that I'll share in multiple RFCs. |
Beta Was this translation helpful? Give feedback.
-
If we save some data, like the container node of our custom widget into
widgetParams
it would be great to have it with as param of theunmountFn
👍Beta Was this translation helpful? Give feedback.
All reactions