Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
refactor(ssr): reuse index helpers (#900)
Browse files Browse the repository at this point in the history
* refactor(ssr): reuse index helpers

* update instantsearch
  • Loading branch information
Haroenv authored Jan 15, 2021
1 parent 9fa3645 commit 5d79990
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"algoliasearch-helper": "^3.1.0",
"instantsearch.js": "^4.7.0"
"instantsearch.js": "^4.11.0"
},
"peerDependencies": {
"algoliasearch": ">= 3.32.0 < 5",
Expand Down
40 changes: 2 additions & 38 deletions src/util/createServerRootMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,49 +177,13 @@ function augmentInstantSearch(instantSearchOptions, searchClient, indexName) {
// parameters, because those are from the lastResults
localHelper.state = state;

// TODO: copied from index widget, since it's only accessible once sent to render()
// a possible solution is making createURL accessible from the index widget.
const createURL = nextState =>
search._createURL({
[parent.getIndexId()]: parent
.getWidgets()
.filter(w => w.$$type !== 'ais.index')
.reduce((uiState, w) => {
if (!w.getWidgetState) {
return uiState;
}

return w.getWidgetState(uiState, {
searchParameters: nextState,
helper: localHelper,
});
}, {}),
});

function resolveScopedResultsFromWidgets(widgets) {
const indexWidgets = widgets.filter(w => w.$$type === 'ais.index');

return indexWidgets.reduce(
(scopedResults, current) =>
scopedResults.concat(
{
indexId: current.getIndexId(),
results: search.__initialSearchResults[current.getIndexId()],
helper: current.getHelper(),
},
...resolveScopedResultsFromWidgets(current.getWidgets())
),
[]
);
}

widget.render({
helper: localHelper,
results,
scopedResults: resolveScopedResultsFromWidgets([parent]),
scopedResults: parent.getScopedResults(),
state,
templatesConfig: {},
createURL,
createURL: parent.createURL,
instantSearchInstance: search,
searchMetadata: {
isSearchStalled: false,
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ algoliasearch-helper@^3.1.0:
dependencies:
events "^1.1.1"

algoliasearch-helper@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/algoliasearch-helper/-/algoliasearch-helper-3.1.1.tgz#4cdfbaed6670d82626ac1fae001ccbf53192f497"
integrity sha512-Jkqlp8jezQRixf7sbQ2zFXHpdaT41g9sHBqT6pztv5nfDmg94K+pwesAy6UbxRY78IL54LIaV1FLttMtT+IzzA==
algoliasearch-helper@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/algoliasearch-helper/-/algoliasearch-helper-3.3.4.tgz#4a3c56d42a2a81589d5722b73653b2deaf3e7064"
integrity sha512-1Ts2XcgGdjGlDrp3v6zbY8VW+X9+jJ5rBmtPBmXOQLd4b5t/LpJlaBdxoAnlMfVFjywP7KSAdmyFUNNYVHDyRQ==
dependencies:
events "^1.1.1"

Expand Down Expand Up @@ -7878,13 +7878,13 @@ instantsearch.css@7.3.1:
resolved "https://registry.yarnpkg.com/instantsearch.css/-/instantsearch.css-7.3.1.tgz#7ab74a8f355091ae040947a9cf5438f379026622"
integrity sha512-/kaMDna5D+Q9mImNBHEhb9HgHATDOFKYii7N1Iwvrj+lmD9gBJLqVhUw67gftq2O0QI330pFza+CRscIwB1wQQ==

instantsearch.js@^4.7.0:
version "4.7.0"
resolved "https://registry.npmjs.org/instantsearch.js/-/instantsearch.js-4.7.0.tgz#4062b98daf7278e51028d1453dc5d629cb708702"
integrity sha512-OkTcyHLcSu6eymWmVXsu2Tt0GRtkoRQXM+SCxj+nyvBY3y3hmGDjcb8bzkrACrhfR8SDbpEUiBGI1IUHjtvOGA==
instantsearch.js@^4.11.0:
version "4.11.0"
resolved "https://registry.yarnpkg.com/instantsearch.js/-/instantsearch.js-4.11.0.tgz#9e55426fbcf1929df9a772c53eeae282575e1a13"
integrity sha512-SVdS63S7skry5ebttPOq9D/BB2H61lYL2qdRiGdeuxsbrkwNssvpmtt/kAKxrnySUNxiSI2ZKTH2wa2WaMU98A==
dependencies:
"@types/googlemaps" "^3.39.6"
algoliasearch-helper "^3.1.1"
algoliasearch-helper "^3.3.4"
classnames "^2.2.5"
events "^1.1.0"
hogan.js "^3.0.2"
Expand Down

0 comments on commit 5d79990

Please sign in to comment.