instantsearch.js 4.41.0 → 4.41.1

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.
@@ -4,6 +4,7 @@ import type { IndexWidget } from '../widgets/index/index';
4
4
  import type { InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, UiState, CreateURL, Middleware, MiddlewareDefinition, RenderState, InitialResults } from '../types';
5
5
  import type { RouterProps } from '../middlewares/createRouterMiddleware';
6
6
  import type { InsightsEvent } from '../middlewares/createInsightsMiddleware';
7
+ declare type NoInfer<T> = [T][T extends any ? 0 : never];
7
8
  /**
8
9
  * Global options for an InstantSearch instance.
9
10
  */
@@ -58,8 +59,8 @@ export declare type InstantSearchOptions<TUiState extends UiState = UiState, TRo
58
59
  * become in charge of updating the UI state with the `setUiState` function.
59
60
  */
60
61
  onStateChange?: (params: {
61
- uiState: UiState;
62
- setUiState(uiState: UiState | ((previousUiState: UiState) => UiState)): void;
62
+ uiState: TUiState;
63
+ setUiState(uiState: TUiState | ((previousUiState: TUiState) => TUiState)): void;
63
64
  }) => void;
64
65
  /**
65
66
  * Injects a `uiState` to the `instantsearch` instance. You can use this option
@@ -67,7 +68,7 @@ export declare type InstantSearchOptions<TUiState extends UiState = UiState, TRo
67
68
  * for the first search. To unconditionally pass additional parameters to the
68
69
  * Algolia API, take a look at the `configure` widget.
69
70
  */
70
- initialUiState?: TUiState;
71
+ initialUiState?: NoInfer<TUiState>;
71
72
  /**
72
73
  * Time before a search is considered stalled. The default is 200ms
73
74
  */
@@ -94,7 +95,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
94
95
  client: InstantSearchOptions['searchClient'];
95
96
  indexName: string;
96
97
  insightsClient: AlgoliaInsightsClient | null;
97
- onStateChange: InstantSearchOptions['onStateChange'] | null;
98
+ onStateChange: InstantSearchOptions<TUiState>['onStateChange'] | null;
98
99
  helper: AlgoliaSearchHelper | null;
99
100
  mainHelper: AlgoliaSearchHelper | null;
100
101
  mainIndex: IndexWidget;
@@ -104,9 +105,9 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
104
105
  _stalledSearchDelay: number;
105
106
  _searchStalledTimer: any;
106
107
  _isSearchStalled: boolean;
107
- _initialUiState: UiState;
108
+ _initialUiState: TUiState;
108
109
  _initialResults: InitialResults | null;
109
- _createURL: CreateURL<UiState>;
110
+ _createURL: CreateURL<TUiState>;
110
111
  _searchFunction?: InstantSearchOptions['searchFunction'];
111
112
  _mainHelperSearch?: AlgoliaSearchHelper['search'];
112
113
  middleware: Array<{
@@ -176,13 +177,13 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
176
177
  cancel(): void;
177
178
  };
178
179
  scheduleStalledRender(): void;
179
- setUiState(uiState: UiState | ((previousUiState: UiState) => UiState)): void;
180
- getUiState(): UiState;
180
+ setUiState(uiState: TUiState | ((previousUiState: TUiState) => TUiState)): void;
181
+ getUiState(): TUiState;
181
182
  onInternalStateChange: ((...args: any[]) => void) & {
182
183
  wait(): Promise<void>;
183
184
  cancel(): void;
184
185
  };
185
- createURL(nextState?: UiState): string;
186
+ createURL(nextState?: TUiState): string;
186
187
  refresh(): void;
187
188
  }
188
189
  export default InstantSearch;
@@ -40,10 +40,9 @@ var withUsage = createDocumentationMessageGenerator({
40
40
 
41
41
  function defaultCreateURL() {
42
42
  return '#';
43
- }
44
- /**
45
- * Global options for an InstantSearch instance.
46
- */
43
+ } // this purposely breaks typescript's type inference to ensure it's not used
44
+ // as it's used for a default parameter for example
45
+ // source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
47
46
 
48
47
 
49
48
  /**
@@ -20,7 +20,8 @@ var buildPayloads = function buildPayloads(_ref) {
20
20
  var index = _ref.index,
21
21
  widgetType = _ref.widgetType,
22
22
  methodName = _ref.methodName,
23
- args = _ref.args;
23
+ args = _ref.args,
24
+ isSearchStalled = _ref.isSearchStalled;
24
25
 
25
26
  // when there's only one argument, that means it's custom
26
27
  if (args.length === 1 && _typeof(args[0]) === 'object') {
@@ -67,6 +68,10 @@ var buildPayloads = function buildPayloads(_ref) {
67
68
  });
68
69
 
69
70
  if (eventType === 'view') {
71
+ if (isSearchStalled) {
72
+ return [];
73
+ }
74
+
70
75
  return hitsChunks.map(function (batch, i) {
71
76
  return {
72
77
  insightsMethod: 'viewedObjectIDs',
@@ -137,7 +142,8 @@ export function createSendEventForHits(_ref2) {
137
142
  widgetType: widgetType,
138
143
  index: index,
139
144
  methodName: 'sendEvent',
140
- args: args
145
+ args: args,
146
+ isSearchStalled: instantSearchInstance._isSearchStalled
141
147
  });
142
148
  payloads.forEach(function (payload) {
143
149
  return instantSearchInstance.sendEventToInsights(payload);
@@ -159,7 +165,8 @@ export function createBindEventForHits(_ref3) {
159
165
  widgetType: widgetType,
160
166
  index: index,
161
167
  methodName: 'bindEvent',
162
- args: args
168
+ args: args,
169
+ isSearchStalled: false
163
170
  });
164
171
  return payloads.length ? "data-insights-event=".concat(serializePayload(payloads)) : '';
165
172
  };
@@ -1,2 +1,2 @@
1
- declare const _default: "4.41.0";
1
+ declare const _default: "4.41.1";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.41.0';
1
+ export default '4.41.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.41.0",
3
+ "version": "4.41.1",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",