Skip to content

Commit 7aadf80

Browse files
committed
fix(insights): remove bindEvent
bindEvent is no longer handled in the component since #6403 (https://github.com/algolia/instantsearch/pull/6403/files#diff-e7717d55fdbbc94c7dd996f78b6f0f860332545d6fa8f6b843c940798334532cL94) [FX-3191] BREAKING CHANGE: the `bindEvent` related functions are non longer usable, use `sendEvent` instead
1 parent 9894ac8 commit 7aadf80

File tree

17 files changed

+33
-530
lines changed

17 files changed

+33
-530
lines changed

packages/instantsearch-core/src/connectors/__tests__/connectHits.test.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
createInitOptions,
2121
createRenderOptions,
2222
} from '../../../test/createWidget';
23-
import { deserializePayload } from '../../lib/utils';
2423

2524
import type {
2625
EscapedHits,
@@ -509,7 +508,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
509508
hits: [],
510509
items: [],
511510
sendEvent: expect.any(Function),
512-
bindEvent: expect.any(Function),
513511
results: undefined,
514512
widgetParams: {},
515513
});
@@ -541,7 +539,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
541539
hits: expectedHits,
542540
items: expectedHits,
543541
sendEvent: renderState1.hits.sendEvent,
544-
bindEvent: renderState1.hits.bindEvent,
545542
results,
546543
widgetParams: {},
547544
});
@@ -573,7 +570,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
573570
items: [],
574571
banner: undefined,
575572
sendEvent: expect.any(Function),
576-
bindEvent: expect.any(Function),
577573
results: undefined,
578574
widgetParams: {},
579575
});
@@ -611,7 +607,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
611607
items: expectedHits,
612608
banner,
613609
sendEvent: renderState1.sendEvent,
614-
bindEvent: renderState2.bindEvent,
615610
results,
616611
widgetParams: {},
617612
});
@@ -1033,71 +1028,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
10331028
});
10341029
});
10351030
});
1036-
1037-
describe('bindEvent', () => {
1038-
it('returns a payload for click event', () => {
1039-
const { renderFn, hits } = createRenderedWidget();
1040-
const { bindEvent } =
1041-
renderFn.mock.calls[renderFn.mock.calls.length - 1][0];
1042-
const payload = bindEvent('click', hits[0], 'Product Added');
1043-
expect(payload.startsWith('data-insights-event=')).toBe(true);
1044-
expect(
1045-
deserializePayload(payload.substr('data-insights-event='.length))
1046-
).toEqual([
1047-
{
1048-
eventType: 'click',
1049-
hits: [
1050-
{
1051-
__position: 0,
1052-
__queryID: 'test-query-id',
1053-
fake: 'data',
1054-
objectID: '1',
1055-
},
1056-
],
1057-
insightsMethod: 'clickedObjectIDsAfterSearch',
1058-
payload: {
1059-
eventName: 'Product Added',
1060-
index: '',
1061-
objectIDs: ['1'],
1062-
positions: [0],
1063-
queryID: 'test-query-id',
1064-
},
1065-
widgetType: 'ais.hits',
1066-
},
1067-
]);
1068-
});
1069-
1070-
it('returns a payload for conversion event', () => {
1071-
const { renderFn, hits } = createRenderedWidget();
1072-
const { bindEvent } =
1073-
renderFn.mock.calls[renderFn.mock.calls.length - 1][0];
1074-
const payload = bindEvent('conversion', hits[1], 'Product Ordered');
1075-
expect(payload.startsWith('data-insights-event=')).toBe(true);
1076-
expect(
1077-
deserializePayload(payload.substr('data-insights-event='.length))
1078-
).toEqual([
1079-
{
1080-
eventType: 'conversion',
1081-
hits: [
1082-
{
1083-
__position: 1,
1084-
__queryID: 'test-query-id',
1085-
objectID: '2',
1086-
sample: 'infos',
1087-
},
1088-
],
1089-
insightsMethod: 'convertedObjectIDsAfterSearch',
1090-
payload: {
1091-
eventName: 'Product Ordered',
1092-
index: '',
1093-
objectIDs: ['2'],
1094-
queryID: 'test-query-id',
1095-
},
1096-
widgetType: 'ais.hits',
1097-
},
1098-
]);
1099-
});
1100-
});
11011031
});
11021032
});
11031033
});

packages/instantsearch-core/src/connectors/__tests__/connectInfiniteHits.test.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
createRenderOptions,
1919
} from '../../../test/createWidget';
2020
import { createInfiniteHitsSessionStorageCache } from '../../lib/infiniteHitsCache';
21-
import { deserializePayload } from '../../lib/utils';
2221

2322
import type {
2423
SearchClient,
@@ -1328,7 +1327,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
13281327
items: [],
13291328
currentPageHits: [],
13301329
sendEvent: expect.any(Function),
1331-
bindEvent: expect.any(Function),
13321330
isFirstPage: true,
13331331
isLastPage: true,
13341332
banner: undefined,
@@ -1392,7 +1390,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
13921390
items: expectedHits,
13931391
currentPageHits: expectedCurrentPageHits,
13941392
sendEvent: renderState1.infiniteHits.sendEvent,
1395-
bindEvent: renderState1.infiniteHits.bindEvent,
13961393
isFirstPage: true,
13971394
isLastPage: true,
13981395
banner: undefined,
@@ -1423,7 +1420,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
14231420
items: [],
14241421
currentPageHits: [],
14251422
sendEvent: expect.any(Function),
1426-
bindEvent: expect.any(Function),
14271423
isFirstPage: true,
14281424
isLastPage: true,
14291425
banner: undefined,
@@ -1500,7 +1496,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
15001496
items: expectedHits,
15011497
currentPageHits: expectedCurrentPageHits,
15021498
sendEvent: renderState1.sendEvent,
1503-
bindEvent: renderState1.bindEvent,
15041499
isFirstPage: true,
15051500
isLastPage: true,
15061501
banner,
@@ -1870,71 +1865,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi
18701865
});
18711866
});
18721867
});
1873-
1874-
describe('bindEvent', () => {
1875-
it('returns a payload for click event', () => {
1876-
const { renderFn, hits } = createRenderedWidget();
1877-
const { bindEvent } =
1878-
renderFn.mock.calls[renderFn.mock.calls.length - 1][0];
1879-
const payload = bindEvent('click', hits[0], 'Product Added');
1880-
expect(payload.startsWith('data-insights-event=')).toBe(true);
1881-
expect(
1882-
deserializePayload(payload.substr('data-insights-event='.length))
1883-
).toEqual([
1884-
{
1885-
eventType: 'click',
1886-
hits: [
1887-
{
1888-
__position: 0,
1889-
__queryID: 'test-query-id',
1890-
fake: 'data',
1891-
objectID: '1',
1892-
},
1893-
],
1894-
insightsMethod: 'clickedObjectIDsAfterSearch',
1895-
payload: {
1896-
eventName: 'Product Added',
1897-
index: '',
1898-
objectIDs: ['1'],
1899-
positions: [0],
1900-
queryID: 'test-query-id',
1901-
},
1902-
widgetType: 'ais.infiniteHits',
1903-
},
1904-
]);
1905-
});
1906-
1907-
it('returns a payload for conversion event', () => {
1908-
const { renderFn, hits } = createRenderedWidget();
1909-
const { bindEvent } =
1910-
renderFn.mock.calls[renderFn.mock.calls.length - 1][0];
1911-
const payload = bindEvent('conversion', hits[1], 'Product Ordered');
1912-
expect(payload.startsWith('data-insights-event=')).toBe(true);
1913-
expect(
1914-
deserializePayload(payload.substr('data-insights-event='.length))
1915-
).toEqual([
1916-
{
1917-
eventType: 'conversion',
1918-
hits: [
1919-
{
1920-
__position: 1,
1921-
__queryID: 'test-query-id',
1922-
objectID: '2',
1923-
sample: 'infos',
1924-
},
1925-
],
1926-
insightsMethod: 'convertedObjectIDsAfterSearch',
1927-
payload: {
1928-
eventName: 'Product Ordered',
1929-
index: '',
1930-
objectIDs: ['2'],
1931-
queryID: 'test-query-id',
1932-
},
1933-
widgetType: 'ais.infiniteHits',
1934-
},
1935-
]);
1936-
});
1937-
});
19381868
});
19391869
});
19401870
});

packages/instantsearch-core/src/connectors/connectHits.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
addAbsolutePosition,
1010
addQueryID,
1111
createSendEventForHits,
12-
createBindEventForHits,
1312
} from '../lib/utils';
1413

1514
import type {
@@ -21,7 +20,6 @@ import type {
2120
Unmounter,
2221
Renderer,
2322
SendEventForHits,
24-
BindEventForHits,
2523
Widget,
2624
} from '../types';
2725
import type { Banner, SearchResults } from 'algoliasearch-helper';
@@ -57,11 +55,6 @@ export type HitsRenderState<THit extends NonNullable<object> = BaseHit> = {
5755
* Sends an event to the Insights middleware.
5856
*/
5957
sendEvent: SendEventForHits;
60-
61-
/**
62-
* Returns a string for the `data-insights-event` attribute for the Insights middleware
63-
*/
64-
bindEvent: BindEventForHits;
6558
};
6659

6760
export type HitsConnectorParams<THit extends NonNullable<object> = BaseHit> = {
@@ -107,7 +100,6 @@ export const connectHits = function connectHits<TWidgetParams>(
107100
>,
108101
} = (widgetParams || {}) as HitsConnectorParams<THit>;
109102
let sendEvent: SendEventForHits;
110-
let bindEvent: BindEventForHits;
111103

112104
type HitsWidget = Widget<
113105
HitsWidgetDescription<THit> & {
@@ -160,22 +152,13 @@ export const connectHits = function connectHits<TWidgetParams>(
160152
});
161153
}
162154

163-
if (!bindEvent) {
164-
bindEvent = createBindEventForHits({
165-
getIndex: () => helper.getIndex(),
166-
widgetType: this.$$type,
167-
instantSearchInstance,
168-
});
169-
}
170-
171155
if (!results) {
172156
return {
173157
hits: [],
174158
items: [],
175159
results: undefined,
176160
banner: undefined,
177161
sendEvent,
178-
bindEvent,
179162
widgetParams,
180163
};
181164
}
@@ -207,7 +190,6 @@ export const connectHits = function connectHits<TWidgetParams>(
207190
results,
208191
banner,
209192
sendEvent,
210-
bindEvent,
211193
widgetParams,
212194
};
213195
},

packages/instantsearch-core/src/connectors/connectInfiniteHits.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
addAbsolutePosition,
1212
addQueryID,
1313
createSendEventForHits,
14-
createBindEventForHits,
1514
} from '../lib/utils';
1615

1716
import type {
@@ -24,7 +23,6 @@ import type {
2423
Unmounter,
2524
UnknownWidgetParams,
2625
SendEventForHits,
27-
BindEventForHits,
2826
Widget,
2927
} from '../types';
3028
import type {
@@ -117,11 +115,6 @@ export type InfiniteHitsRenderState<
117115
*/
118116
sendEvent: SendEventForHits;
119117

120-
/**
121-
* Returns a string of data-insights-event attribute for insights middleware
122-
*/
123-
bindEvent: BindEventForHits;
124-
125118
/**
126119
* Hits for the current page
127120
*/
@@ -237,7 +230,6 @@ export const connectInfiniteHits = function connectInfiniteHits<
237230
let showPrevious: () => void;
238231
let showMore: () => void;
239232
let sendEvent: SendEventForHits;
240-
let bindEvent: BindEventForHits;
241233
const getFirstReceivedPage = (
242234
state: SearchParameters,
243235
cachedHits: InfiniteHitsCachedHits<THit>
@@ -365,11 +357,6 @@ export const connectInfiniteHits = function connectInfiniteHits<
365357
getIndex: () => helper.getIndex(),
366358
widgetType: this.$$type,
367359
});
368-
bindEvent = createBindEventForHits({
369-
getIndex: () => helper.getIndex(),
370-
widgetType: this.$$type,
371-
instantSearchInstance,
372-
});
373360
isFirstPage =
374361
state.page === undefined ||
375362
getFirstReceivedPage(state, cachedHits) === 0;
@@ -440,7 +427,6 @@ export const connectInfiniteHits = function connectInfiniteHits<
440427
items,
441428
currentPageHits,
442429
sendEvent,
443-
bindEvent,
444430
banner,
445431
results: results || undefined,
446432
showPrevious,

packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForFacet.test.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,35 @@ describe('createSendEventForFacet', () => {
3434
expect(() => {
3535
sendEvent('click');
3636
}).toThrowErrorMatchingInlineSnapshot(`
37-
"You need to pass between two and four arguments like:
38-
sendEvent('click', facetValue, eventName?, additionalData?);
37+
"You need to pass between two and four arguments like:
38+
sendEvent('click', facetValue, eventName?, additionalData?);
3939
40-
If you want to send a custom payload, you can pass one object: sendEvent(customPayload);
41-
"
42-
`);
40+
If you want to send a custom payload, you can pass one object: sendEvent(customPayload);"
41+
`);
4342
});
4443

4544
it('throws with unknown eventType', () => {
4645
const { sendEvent } = createTestEnvironment();
4746
expect(() => {
4847
sendEvent('my custom event type');
4948
}).toThrowErrorMatchingInlineSnapshot(`
50-
"You need to pass between two and four arguments like:
51-
sendEvent('click', facetValue, eventName?, additionalData?);
49+
"You need to pass between two and four arguments like:
50+
sendEvent('click', facetValue, eventName?, additionalData?);
5251
53-
If you want to send a custom payload, you can pass one object: sendEvent(customPayload);
54-
"
55-
`);
52+
If you want to send a custom payload, you can pass one object: sendEvent(customPayload);"
53+
`);
5654
});
5755

5856
it('throws when eventType is not click', () => {
5957
const { sendEvent } = createTestEnvironment();
6058
expect(() => {
6159
sendEvent('custom event type');
6260
}).toThrowErrorMatchingInlineSnapshot(`
63-
"You need to pass between two and four arguments like:
64-
sendEvent('click', facetValue, eventName?, additionalData?);
61+
"You need to pass between two and four arguments like:
62+
sendEvent('click', facetValue, eventName?, additionalData?);
6563
66-
If you want to send a custom payload, you can pass one object: sendEvent(customPayload);
67-
"
68-
`);
64+
If you want to send a custom payload, you can pass one object: sendEvent(customPayload);"
65+
`);
6966
});
7067

7168
it('does not send event when a facet is removed', () => {

0 commit comments

Comments
 (0)