instantsearch.js 4.33.2 → 4.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -1
- package/cjs/connectors/autocomplete/connectAutocomplete.js +2 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +1 -1
- package/cjs/connectors/pagination/connectPagination.js +3 -3
- package/cjs/connectors/search-box/connectSearchBox.js +4 -3
- package/cjs/connectors/sort-by/connectSortBy.js +2 -1
- package/cjs/connectors/stats/connectStats.js +4 -4
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +1 -1
- package/cjs/lib/InstantSearch.js +22 -1
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/index/index.js +20 -2
- package/dist/instantsearch.development.d.ts +8 -0
- package/dist/instantsearch.development.js +61 -19
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.development.min.d.ts +8 -0
- package/dist/instantsearch.production.d.ts +8 -0
- package/dist/instantsearch.production.min.d.ts +8 -0
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/autocomplete/connectAutocomplete.js +2 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +1 -1
- package/es/connectors/pagination/connectPagination.js +3 -3
- package/es/connectors/search-box/connectSearchBox.js +4 -3
- package/es/connectors/sort-by/connectSortBy.js +2 -1
- package/es/connectors/stats/connectStats.js +4 -4
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +1 -1
- package/es/lib/InstantSearch.d.ts +2 -1
- package/es/lib/InstantSearch.js +22 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/results.d.ts +7 -0
- package/es/widgets/index/index.js +20 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# [4.34.0](https://github.com/algolia/instantsearch.js/compare/v4.33.2...v4.34.0) (2021-12-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* rely on `state` in `getWidgetRenderState` ([#4960](https://github.com/algolia/instantsearch.js/issues/4960)) ([5006841](https://github.com/algolia/instantsearch.js/commit/50068417e5e7211802bc717b582946f6e630d7ac))
|
|
7
|
+
* support initial results (experimental) ([#4967](https://github.com/algolia/instantsearch.js/issues/4967)) ([db11c13](https://github.com/algolia/instantsearch.js/commit/db11c13ea55433491f5e924633bff12a303c1bc6))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
1
11
|
## [4.33.2](https://github.com/algolia/instantsearch.js/compare/v4.33.1...v4.33.2) (2021-11-16)
|
|
2
12
|
|
|
3
13
|
|
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ InstantSearch.js is a vanilla JavaScript library that lets you create an instant
|
|
|
29
29
|
- [Why](#why)
|
|
30
30
|
- [Getting started](#getting-started)
|
|
31
31
|
- [Installation](#installation)
|
|
32
|
+
- [TypeScript users](#typescript-users)
|
|
32
33
|
- [Documentation](#documentation)
|
|
33
34
|
- [Demos](#demos)
|
|
34
35
|
- [Playground](#playground)
|
|
@@ -132,7 +133,7 @@ The documentation is available on the [Algolia website](https://www.algolia.com/
|
|
|
132
133
|
|
|
133
134
|
| E-commerce | Media | Travel |
|
|
134
135
|
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
135
|
-
| <a href="https://instantsearchjs.netlify.com/examples/e-commerce/"><img src="https://www.algolia.com/doc/assets/images/build-search-ui/demos/e-commerce-2c7ed6b6.png" width="250" alt="E-commerce demo preview"></a> | <a href="https://instantsearchjs.netlify.com/examples/media/"><img src="
|
|
136
|
+
| <a href="https://instantsearchjs.netlify.com/examples/e-commerce/"><img src="https://www.algolia.com/doc/assets/images/build-search-ui/demos/e-commerce-2c7ed6b6.png" width="250" alt="E-commerce demo preview"></a> | <a href="https://instantsearchjs.netlify.com/examples/media/"><img src="./examples/media/capture.png" width="250" alt="Media demo preview"></a> | <a href="https://instantsearchjs.netlify.com/examples/tourism/"><img src="https://instantsearchjs.netlify.com/examples/tourism/capture.png" width="250" alt="Tourism demo preview"></a> |
|
|
136
137
|
|
|
137
138
|
See more demos [on the website](https://www.algolia.com/doc/guides/building-search-ui/resources/demos/js/).
|
|
138
139
|
|
|
@@ -60,6 +60,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
60
60
|
var _this = this;
|
|
61
61
|
|
|
62
62
|
var helper = _ref4.helper,
|
|
63
|
+
state = _ref4.state,
|
|
63
64
|
scopedResults = _ref4.scopedResults,
|
|
64
65
|
instantSearchInstance = _ref4.instantSearchInstance;
|
|
65
66
|
|
|
@@ -87,7 +88,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
87
88
|
};
|
|
88
89
|
});
|
|
89
90
|
return {
|
|
90
|
-
currentRefinement:
|
|
91
|
+
currentRefinement: state.query || '',
|
|
91
92
|
indices: indices,
|
|
92
93
|
refine: connectorState.refine,
|
|
93
94
|
widgetParams: widgetParams
|
|
@@ -173,7 +173,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
173
173
|
index: helper.getIndex(),
|
|
174
174
|
widgetType: this.$$type
|
|
175
175
|
});
|
|
176
|
-
isFirstPage =
|
|
176
|
+
isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
|
|
177
177
|
} else {
|
|
178
178
|
var _state$page3 = state.page,
|
|
179
179
|
_page = _state$page3 === void 0 ? 0 : _state$page3;
|
|
@@ -89,6 +89,7 @@ var connectPagination = function connectPagination(renderFn) {
|
|
|
89
89
|
getWidgetRenderState: function getWidgetRenderState(_ref6) {
|
|
90
90
|
var results = _ref6.results,
|
|
91
91
|
helper = _ref6.helper,
|
|
92
|
+
state = _ref6.state,
|
|
92
93
|
createURL = _ref6.createURL;
|
|
93
94
|
|
|
94
95
|
if (!connectorState.refine) {
|
|
@@ -99,14 +100,13 @@ var connectPagination = function connectPagination(renderFn) {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
if (!connectorState.createURL) {
|
|
102
|
-
connectorState.createURL = function (
|
|
103
|
+
connectorState.createURL = function (helperState) {
|
|
103
104
|
return function (page) {
|
|
104
|
-
return createURL(
|
|
105
|
+
return createURL(helperState.setPage(page));
|
|
105
106
|
};
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
var state = helper.state;
|
|
110
110
|
var page = state.page || 0;
|
|
111
111
|
var nbPages = getMaxPage(results || {
|
|
112
112
|
nbPages: 0
|
|
@@ -71,11 +71,12 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
71
71
|
},
|
|
72
72
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
73
73
|
var helper = _ref3.helper,
|
|
74
|
-
searchMetadata = _ref3.searchMetadata
|
|
74
|
+
searchMetadata = _ref3.searchMetadata,
|
|
75
|
+
state = _ref3.state;
|
|
75
76
|
|
|
76
77
|
if (!_refine) {
|
|
77
78
|
var setQueryAndSearch = function setQueryAndSearch(query) {
|
|
78
|
-
if (query !==
|
|
79
|
+
if (query !== state.query) {
|
|
79
80
|
helper.setQuery(query).search();
|
|
80
81
|
}
|
|
81
82
|
};
|
|
@@ -92,7 +93,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
92
93
|
|
|
93
94
|
_clear = clear(helper);
|
|
94
95
|
return {
|
|
95
|
-
query:
|
|
96
|
+
query: state.query || '',
|
|
96
97
|
refine: _refine,
|
|
97
98
|
clear: _cachedClear,
|
|
98
99
|
widgetParams: widgetParams,
|
|
@@ -72,6 +72,7 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
72
72
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
73
73
|
var results = _ref3.results,
|
|
74
74
|
helper = _ref3.helper,
|
|
75
|
+
state = _ref3.state,
|
|
75
76
|
parent = _ref3.parent;
|
|
76
77
|
|
|
77
78
|
if (!connectorState.initialIndex && parent) {
|
|
@@ -85,7 +86,7 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
return {
|
|
88
|
-
currentRefinement:
|
|
89
|
+
currentRefinement: state.index,
|
|
89
90
|
options: transformItems(items),
|
|
90
91
|
refine: connectorState.setIndex,
|
|
91
92
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
@@ -50,18 +50,18 @@ var connectStats = function connectStats(renderFn) {
|
|
|
50
50
|
},
|
|
51
51
|
getWidgetRenderState: function getWidgetRenderState(_ref) {
|
|
52
52
|
var results = _ref.results,
|
|
53
|
-
|
|
53
|
+
state = _ref.state;
|
|
54
54
|
|
|
55
55
|
if (!results) {
|
|
56
56
|
return {
|
|
57
|
-
hitsPerPage:
|
|
57
|
+
hitsPerPage: state.hitsPerPage,
|
|
58
58
|
nbHits: 0,
|
|
59
59
|
nbSortedHits: undefined,
|
|
60
60
|
areHitsSorted: false,
|
|
61
61
|
nbPages: 0,
|
|
62
|
-
page:
|
|
62
|
+
page: state.page || 0,
|
|
63
63
|
processingTimeMS: -1,
|
|
64
|
-
query:
|
|
64
|
+
query: state.query || '',
|
|
65
65
|
widgetParams: widgetParams
|
|
66
66
|
};
|
|
67
67
|
}
|
|
@@ -185,7 +185,7 @@ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
|
|
|
185
185
|
createURL = _ref6.createURL,
|
|
186
186
|
instantSearchInstance = _ref6.instantSearchInstance;
|
|
187
187
|
var isRefined = results ? on.every(function (v) {
|
|
188
|
-
return
|
|
188
|
+
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
189
189
|
}) : on.every(function (v) {
|
|
190
190
|
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
191
191
|
});
|
package/cjs/lib/InstantSearch.js
CHANGED
|
@@ -112,6 +112,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
112
112
|
|
|
113
113
|
_defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
|
|
114
114
|
|
|
115
|
+
_defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
|
|
116
|
+
|
|
115
117
|
_defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
|
|
116
118
|
|
|
117
119
|
_defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
|
|
@@ -216,6 +218,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
216
218
|
_this._isSearchStalled = false;
|
|
217
219
|
_this._createURL = defaultCreateURL;
|
|
218
220
|
_this._initialUiState = initialUiState;
|
|
221
|
+
_this._initialResults = null;
|
|
219
222
|
|
|
220
223
|
if (searchFunction) {
|
|
221
224
|
_this._searchFunction = searchFunction;
|
|
@@ -458,9 +461,27 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
458
461
|
parent: null,
|
|
459
462
|
uiState: this._initialUiState
|
|
460
463
|
});
|
|
461
|
-
|
|
464
|
+
|
|
465
|
+
if (this._initialResults) {
|
|
466
|
+
var originalScheduleSearch = this.scheduleSearch; // We don't schedule a first search when initial results are provided
|
|
467
|
+
// because we already have the results to render. This skips the initial
|
|
468
|
+
// network request on the browser on `start`.
|
|
469
|
+
|
|
470
|
+
this.scheduleSearch = (0, _utils.defer)(_utils.noop); // We also skip the initial network request when widgets are dynamically
|
|
471
|
+
// added in the first tick (that's the case in all the framework-based flavors).
|
|
472
|
+
// When we add a widget to `index`, it calls `scheduleSearch`. We can rely
|
|
473
|
+
// on our `defer` util to restore the original `scheduleSearch` value once
|
|
474
|
+
// widgets are added to hook back to the regular lifecycle.
|
|
475
|
+
|
|
476
|
+
(0, _utils.defer)(function () {
|
|
477
|
+
_this3.scheduleSearch = originalScheduleSearch;
|
|
478
|
+
})();
|
|
479
|
+
} else {
|
|
480
|
+
this.scheduleSearch();
|
|
481
|
+
} // Keep the previous reference for legacy purpose, some pattern use
|
|
462
482
|
// the direct Helper access `search.helper` (e.g multi-index).
|
|
463
483
|
|
|
484
|
+
|
|
464
485
|
this.helper = this.mainIndex.getHelper(); // track we started the search if we add more widgets,
|
|
465
486
|
// to init them directly after add
|
|
466
487
|
|
package/cjs/lib/version.js
CHANGED
|
@@ -289,7 +289,8 @@ var index = function index(widgetParams) {
|
|
|
289
289
|
return this;
|
|
290
290
|
},
|
|
291
291
|
init: function init(_ref2) {
|
|
292
|
-
var _this3 = this
|
|
292
|
+
var _this3 = this,
|
|
293
|
+
_instantSearchInstanc;
|
|
293
294
|
|
|
294
295
|
var instantSearchInstance = _ref2.instantSearchInstance,
|
|
295
296
|
parent = _ref2.parent,
|
|
@@ -347,11 +348,21 @@ var index = function index(widgetParams) {
|
|
|
347
348
|
|
|
348
349
|
derivedHelper = mainHelper.derive(function () {
|
|
349
350
|
return _utils.mergeSearchParameters.apply(void 0, _toConsumableArray((0, _utils.resolveSearchParameters)(_this3)));
|
|
350
|
-
});
|
|
351
|
+
});
|
|
352
|
+
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
353
|
+
|
|
354
|
+
if (indexInitialResults) {
|
|
355
|
+
// We restore the shape of the results provided to the instance to respect
|
|
356
|
+
// the helper's structure.
|
|
357
|
+
var results = new _algoliasearchHelper.default.SearchResults(new _algoliasearchHelper.default.SearchParameters(indexInitialResults.state), indexInitialResults.results);
|
|
358
|
+
derivedHelper.lastResults = results;
|
|
359
|
+
helper.lastResults = results;
|
|
360
|
+
} // Subscribe to the Helper state changes for the page before widgets
|
|
351
361
|
// are initialized. This behavior mimics the original one of the Helper.
|
|
352
362
|
// It makes sense to replicate it at the `init` step. We have another
|
|
353
363
|
// listener on `change` below, once `init` is done.
|
|
354
364
|
|
|
365
|
+
|
|
355
366
|
helper.on('change', function (_ref3) {
|
|
356
367
|
var isPageReset = _ref3.isPageReset;
|
|
357
368
|
|
|
@@ -452,6 +463,13 @@ var index = function index(widgetParams) {
|
|
|
452
463
|
instantSearchInstance.onInternalStateChange();
|
|
453
464
|
}
|
|
454
465
|
});
|
|
466
|
+
|
|
467
|
+
if (indexInitialResults) {
|
|
468
|
+
// If there are initial results, we're not notified of the next results
|
|
469
|
+
// because we don't trigger an initial search. We therefore need to directly
|
|
470
|
+
// schedule a render that will render the results injected on the helper.
|
|
471
|
+
instantSearchInstance.scheduleRender();
|
|
472
|
+
}
|
|
455
473
|
},
|
|
456
474
|
render: function render(_ref5) {
|
|
457
475
|
var _this4 = this;
|
|
@@ -2194,6 +2194,13 @@ declare type InfiniteHitsWidgetParams = {
|
|
|
2194
2194
|
cache?: InfiniteHitsCache;
|
|
2195
2195
|
};
|
|
2196
2196
|
|
|
2197
|
+
declare type InitialResult = {
|
|
2198
|
+
state: PlainSearchParameters;
|
|
2199
|
+
results: SearchResults['_rawResults'];
|
|
2200
|
+
};
|
|
2201
|
+
|
|
2202
|
+
declare type InitialResults = Record<string, InitialResult>;
|
|
2203
|
+
|
|
2197
2204
|
declare type InitOptions = SharedRenderOptions & {
|
|
2198
2205
|
uiState: UiState;
|
|
2199
2206
|
results?: undefined;
|
|
@@ -2258,6 +2265,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
|
|
|
2258
2265
|
_searchStalledTimer: any;
|
|
2259
2266
|
_isSearchStalled: boolean;
|
|
2260
2267
|
_initialUiState: UiState;
|
|
2268
|
+
_initialResults: InitialResults | null;
|
|
2261
2269
|
_createURL: CreateURL<UiState>;
|
|
2262
2270
|
_searchFunction?: InstantSearchOptions['searchFunction'];
|
|
2263
2271
|
_mainHelperSearch?: AlgoliaSearchHelper['search'];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.
|
|
1
|
+
/*! InstantSearch.js 4.34.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -8186,7 +8186,8 @@
|
|
|
8186
8186
|
return this;
|
|
8187
8187
|
},
|
|
8188
8188
|
init: function init(_ref2) {
|
|
8189
|
-
var _this3 = this
|
|
8189
|
+
var _this3 = this,
|
|
8190
|
+
_instantSearchInstanc;
|
|
8190
8191
|
|
|
8191
8192
|
var instantSearchInstance = _ref2.instantSearchInstance,
|
|
8192
8193
|
parent = _ref2.parent,
|
|
@@ -8244,11 +8245,21 @@
|
|
|
8244
8245
|
|
|
8245
8246
|
derivedHelper = mainHelper.derive(function () {
|
|
8246
8247
|
return merge$1.apply(void 0, _toConsumableArray(resolveSearchParameters(_this3)));
|
|
8247
|
-
});
|
|
8248
|
+
});
|
|
8249
|
+
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
8250
|
+
|
|
8251
|
+
if (indexInitialResults) {
|
|
8252
|
+
// We restore the shape of the results provided to the instance to respect
|
|
8253
|
+
// the helper's structure.
|
|
8254
|
+
var results = new algoliasearchHelper_1.SearchResults(new algoliasearchHelper_1.SearchParameters(indexInitialResults.state), indexInitialResults.results);
|
|
8255
|
+
derivedHelper.lastResults = results;
|
|
8256
|
+
helper.lastResults = results;
|
|
8257
|
+
} // Subscribe to the Helper state changes for the page before widgets
|
|
8248
8258
|
// are initialized. This behavior mimics the original one of the Helper.
|
|
8249
8259
|
// It makes sense to replicate it at the `init` step. We have another
|
|
8250
8260
|
// listener on `change` below, once `init` is done.
|
|
8251
8261
|
|
|
8262
|
+
|
|
8252
8263
|
helper.on('change', function (_ref3) {
|
|
8253
8264
|
var isPageReset = _ref3.isPageReset;
|
|
8254
8265
|
|
|
@@ -8349,6 +8360,13 @@
|
|
|
8349
8360
|
instantSearchInstance.onInternalStateChange();
|
|
8350
8361
|
}
|
|
8351
8362
|
});
|
|
8363
|
+
|
|
8364
|
+
if (indexInitialResults) {
|
|
8365
|
+
// If there are initial results, we're not notified of the next results
|
|
8366
|
+
// because we don't trigger an initial search. We therefore need to directly
|
|
8367
|
+
// schedule a render that will render the results injected on the helper.
|
|
8368
|
+
instantSearchInstance.scheduleRender();
|
|
8369
|
+
}
|
|
8352
8370
|
},
|
|
8353
8371
|
render: function render(_ref5) {
|
|
8354
8372
|
var _this4 = this;
|
|
@@ -8465,7 +8483,7 @@
|
|
|
8465
8483
|
instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
8466
8484
|
}
|
|
8467
8485
|
|
|
8468
|
-
var version$1 = '4.
|
|
8486
|
+
var version$1 = '4.34.0';
|
|
8469
8487
|
|
|
8470
8488
|
var NAMESPACE = 'ais';
|
|
8471
8489
|
var component = function component(componentName) {
|
|
@@ -9962,6 +9980,8 @@
|
|
|
9962
9980
|
|
|
9963
9981
|
_defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
|
|
9964
9982
|
|
|
9983
|
+
_defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
|
|
9984
|
+
|
|
9965
9985
|
_defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
|
|
9966
9986
|
|
|
9967
9987
|
_defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
|
|
@@ -10066,6 +10086,7 @@
|
|
|
10066
10086
|
_this._isSearchStalled = false;
|
|
10067
10087
|
_this._createURL = defaultCreateURL;
|
|
10068
10088
|
_this._initialUiState = initialUiState;
|
|
10089
|
+
_this._initialResults = null;
|
|
10069
10090
|
|
|
10070
10091
|
if (searchFunction) {
|
|
10071
10092
|
_this._searchFunction = searchFunction;
|
|
@@ -10308,9 +10329,27 @@
|
|
|
10308
10329
|
parent: null,
|
|
10309
10330
|
uiState: this._initialUiState
|
|
10310
10331
|
});
|
|
10311
|
-
|
|
10332
|
+
|
|
10333
|
+
if (this._initialResults) {
|
|
10334
|
+
var originalScheduleSearch = this.scheduleSearch; // We don't schedule a first search when initial results are provided
|
|
10335
|
+
// because we already have the results to render. This skips the initial
|
|
10336
|
+
// network request on the browser on `start`.
|
|
10337
|
+
|
|
10338
|
+
this.scheduleSearch = defer(noop); // We also skip the initial network request when widgets are dynamically
|
|
10339
|
+
// added in the first tick (that's the case in all the framework-based flavors).
|
|
10340
|
+
// When we add a widget to `index`, it calls `scheduleSearch`. We can rely
|
|
10341
|
+
// on our `defer` util to restore the original `scheduleSearch` value once
|
|
10342
|
+
// widgets are added to hook back to the regular lifecycle.
|
|
10343
|
+
|
|
10344
|
+
defer(function () {
|
|
10345
|
+
_this3.scheduleSearch = originalScheduleSearch;
|
|
10346
|
+
})();
|
|
10347
|
+
} else {
|
|
10348
|
+
this.scheduleSearch();
|
|
10349
|
+
} // Keep the previous reference for legacy purpose, some pattern use
|
|
10312
10350
|
// the direct Helper access `search.helper` (e.g multi-index).
|
|
10313
10351
|
|
|
10352
|
+
|
|
10314
10353
|
this.helper = this.mainIndex.getHelper(); // track we started the search if we add more widgets,
|
|
10315
10354
|
// to init them directly after add
|
|
10316
10355
|
|
|
@@ -11563,7 +11602,7 @@
|
|
|
11563
11602
|
index: helper.getIndex(),
|
|
11564
11603
|
widgetType: this.$$type
|
|
11565
11604
|
});
|
|
11566
|
-
isFirstPage =
|
|
11605
|
+
isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
|
|
11567
11606
|
} else {
|
|
11568
11607
|
var _state$page3 = state.page,
|
|
11569
11608
|
_page = _state$page3 === void 0 ? 0 : _state$page3;
|
|
@@ -12291,6 +12330,7 @@
|
|
|
12291
12330
|
getWidgetRenderState: function getWidgetRenderState(_ref6) {
|
|
12292
12331
|
var results = _ref6.results,
|
|
12293
12332
|
helper = _ref6.helper,
|
|
12333
|
+
state = _ref6.state,
|
|
12294
12334
|
createURL = _ref6.createURL;
|
|
12295
12335
|
|
|
12296
12336
|
if (!connectorState.refine) {
|
|
@@ -12301,14 +12341,13 @@
|
|
|
12301
12341
|
}
|
|
12302
12342
|
|
|
12303
12343
|
if (!connectorState.createURL) {
|
|
12304
|
-
connectorState.createURL = function (
|
|
12344
|
+
connectorState.createURL = function (helperState) {
|
|
12305
12345
|
return function (page) {
|
|
12306
|
-
return createURL(
|
|
12346
|
+
return createURL(helperState.setPage(page));
|
|
12307
12347
|
};
|
|
12308
12348
|
};
|
|
12309
12349
|
}
|
|
12310
12350
|
|
|
12311
|
-
var state = helper.state;
|
|
12312
12351
|
var page = state.page || 0;
|
|
12313
12352
|
var nbPages = getMaxPage(results || {
|
|
12314
12353
|
nbPages: 0
|
|
@@ -13028,11 +13067,12 @@
|
|
|
13028
13067
|
},
|
|
13029
13068
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
13030
13069
|
var helper = _ref3.helper,
|
|
13031
|
-
searchMetadata = _ref3.searchMetadata
|
|
13070
|
+
searchMetadata = _ref3.searchMetadata,
|
|
13071
|
+
state = _ref3.state;
|
|
13032
13072
|
|
|
13033
13073
|
if (!_refine) {
|
|
13034
13074
|
var setQueryAndSearch = function setQueryAndSearch(query) {
|
|
13035
|
-
if (query !==
|
|
13075
|
+
if (query !== state.query) {
|
|
13036
13076
|
helper.setQuery(query).search();
|
|
13037
13077
|
}
|
|
13038
13078
|
};
|
|
@@ -13049,7 +13089,7 @@
|
|
|
13049
13089
|
|
|
13050
13090
|
_clear = clear(helper);
|
|
13051
13091
|
return {
|
|
13052
|
-
query:
|
|
13092
|
+
query: state.query || '',
|
|
13053
13093
|
refine: _refine,
|
|
13054
13094
|
clear: _cachedClear,
|
|
13055
13095
|
widgetParams: widgetParams,
|
|
@@ -13135,6 +13175,7 @@
|
|
|
13135
13175
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
13136
13176
|
var results = _ref3.results,
|
|
13137
13177
|
helper = _ref3.helper,
|
|
13178
|
+
state = _ref3.state,
|
|
13138
13179
|
parent = _ref3.parent;
|
|
13139
13180
|
|
|
13140
13181
|
if (!connectorState.initialIndex && parent) {
|
|
@@ -13148,7 +13189,7 @@
|
|
|
13148
13189
|
}
|
|
13149
13190
|
|
|
13150
13191
|
return {
|
|
13151
|
-
currentRefinement:
|
|
13192
|
+
currentRefinement: state.index,
|
|
13152
13193
|
options: transformItems(items),
|
|
13153
13194
|
refine: connectorState.setIndex,
|
|
13154
13195
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
@@ -13492,18 +13533,18 @@
|
|
|
13492
13533
|
},
|
|
13493
13534
|
getWidgetRenderState: function getWidgetRenderState(_ref) {
|
|
13494
13535
|
var results = _ref.results,
|
|
13495
|
-
|
|
13536
|
+
state = _ref.state;
|
|
13496
13537
|
|
|
13497
13538
|
if (!results) {
|
|
13498
13539
|
return {
|
|
13499
|
-
hitsPerPage:
|
|
13540
|
+
hitsPerPage: state.hitsPerPage,
|
|
13500
13541
|
nbHits: 0,
|
|
13501
13542
|
nbSortedHits: undefined,
|
|
13502
13543
|
areHitsSorted: false,
|
|
13503
13544
|
nbPages: 0,
|
|
13504
|
-
page:
|
|
13545
|
+
page: state.page || 0,
|
|
13505
13546
|
processingTimeMS: -1,
|
|
13506
|
-
query:
|
|
13547
|
+
query: state.query || '',
|
|
13507
13548
|
widgetParams: widgetParams
|
|
13508
13549
|
};
|
|
13509
13550
|
}
|
|
@@ -13696,7 +13737,7 @@
|
|
|
13696
13737
|
createURL = _ref6.createURL,
|
|
13697
13738
|
instantSearchInstance = _ref6.instantSearchInstance;
|
|
13698
13739
|
var isRefined = results ? on.every(function (v) {
|
|
13699
|
-
return
|
|
13740
|
+
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
13700
13741
|
}) : on.every(function (v) {
|
|
13701
13742
|
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
13702
13743
|
});
|
|
@@ -14464,6 +14505,7 @@
|
|
|
14464
14505
|
var _this = this;
|
|
14465
14506
|
|
|
14466
14507
|
var helper = _ref4.helper,
|
|
14508
|
+
state = _ref4.state,
|
|
14467
14509
|
scopedResults = _ref4.scopedResults,
|
|
14468
14510
|
instantSearchInstance = _ref4.instantSearchInstance;
|
|
14469
14511
|
|
|
@@ -14491,7 +14533,7 @@
|
|
|
14491
14533
|
};
|
|
14492
14534
|
});
|
|
14493
14535
|
return {
|
|
14494
|
-
currentRefinement:
|
|
14536
|
+
currentRefinement: state.query || '',
|
|
14495
14537
|
indices: indices,
|
|
14496
14538
|
refine: connectorState.refine,
|
|
14497
14539
|
widgetParams: widgetParams
|