react-instantsearch-core
7.25.07.26.0
dist/es/lib/useSearchResults.js~
dist/es/lib/useSearchResults.jsModified+53−57
Index: package/dist/es/lib/useSearchResults.js
===================================================================
--- package/dist/es/lib/useSearchResults.js
+++ package/dist/es/lib/useSearchResults.js
@@ -1,59 +1,55 @@
-function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
-function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
-function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
-function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
-function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
-function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
-import { isIndexWidget } from "instantsearch.js/es/lib/utils/index.js";
-import { useEffect, useState } from 'react';
-import { getIndexSearchResults } from "./getIndexSearchResults.js";
-import { useIndexContext } from "./useIndexContext.js";
-import { useInstantSearchContext } from "./useInstantSearchContext.js";
-export function useSearchResults() {
- var search = useInstantSearchContext();
- var searchIndex = useIndexContext();
- var _useState = useState(function () {
- var indexSearchResults = getIndexSearchResults(searchIndex);
- // We do this not to leak `recommendResults` in the API.
- return {
- results: indexSearchResults.results,
- scopedResults: indexSearchResults.scopedResults
- };
- }),
- _useState2 = _slicedToArray(_useState, 2),
- searchResults = _useState2[0],
- setSearchResults = _useState2[1];
- useEffect(function () {
- function handleRender() {
- var results = searchIndex.getResults();
+import { _ } from '@swc/helpers/cjs/_sliced_to_array.cjs';
+import { isIndexWidget } from 'instantsearch.js/es/lib/utils/index.js';
+import { useState, useEffect } from 'react';
+import { getIndexSearchResults } from './getIndexSearchResults.js';
+import { useIndexContext } from './useIndexContext.js';
+import { useInstantSearchContext } from './useInstantSearchContext.js';
- // Results can be `null` when the first search is stalled.
- // In this case, we skip the update.
- // See: https://github.com/algolia/instantsearch/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
- if (results !== null) {
- setSearchResults({
- results: results,
- scopedResults: searchIndex.getScopedResults()
- });
- } else if (search.mainIndex.getIndexName().length === 0) {
- // If the main index has no name, we get the scoped results from
- // the first child index instead.
- var childIndex = search.mainIndex.getWidgets().find(isIndexWidget);
- childIndex && setSearchResults({
- results: getIndexSearchResults(searchIndex).results,
- scopedResults: childIndex.getScopedResults()
- });
- }
- }
- search.addListener('render', handleRender);
+function useSearchResults() {
+ var search = useInstantSearchContext();
+ var searchIndex = useIndexContext();
+ var _useState = _(useState(function() {
+ var indexSearchResults = getIndexSearchResults(searchIndex);
+ // We do this not to leak `recommendResults` in the API.
+ return {
+ results: indexSearchResults.results,
+ scopedResults: indexSearchResults.scopedResults
+ };
+ }), 2), searchResults = _useState[0], setSearchResults = _useState[1];
+ useEffect(function() {
+ function handleRender() {
+ var results = searchIndex.getResults();
+ // Results can be `null` when the first search is stalled.
+ // In this case, we skip the update.
+ // See: https://github.com/algolia/instantsearch/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
+ if (results !== null) {
+ setSearchResults({
+ results: results,
+ scopedResults: searchIndex.getScopedResults()
+ });
+ } else if (search.mainIndex.getIndexName().length === 0) {
+ // If the main index has no name, we get the scoped results from
+ // the first child index instead.
+ var childIndex = search.mainIndex.getWidgets().find(isIndexWidget);
+ childIndex && setSearchResults({
+ results: getIndexSearchResults(searchIndex).results,
+ scopedResults: childIndex.getScopedResults()
+ });
+ }
+ }
+ search.addListener('render', handleRender);
+ // Force setting results to mitigate potential race conditions where
+ // render listener is added after search results have been returned.
+ // This edge case is currently not covered by the tests.
+ handleRender();
+ return function() {
+ search.removeListener('render', handleRender);
+ };
+ }, [
+ search,
+ searchIndex
+ ]);
+ return searchResults;
+}
- // Force setting results to mitigate potential race conditions where
- // render listener is added after search results have been returned.
- // This edge case is currently not covered by the tests.
- handleRender();
- return function () {
- search.removeListener('render', handleRender);
- };
- }, [search, searchIndex]);
- return searchResults;
-}
\ No newline at end of file
+export { useSearchResults };