@searchspring/snap-controller 0.61.5 → 0.63.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/dist/cjs/Autocomplete/AutocompleteController.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/AutocompleteController.js +52 -65
- package/dist/cjs/Finder/FinderController.d.ts.map +1 -1
- package/dist/cjs/Finder/FinderController.js +30 -41
- package/dist/cjs/Recommendation/RecommendationController.d.ts.map +1 -1
- package/dist/cjs/Recommendation/RecommendationController.js +39 -42
- package/dist/cjs/Search/SearchController.d.ts +0 -1
- package/dist/cjs/Search/SearchController.d.ts.map +1 -1
- package/dist/cjs/Search/SearchController.js +67 -97
- package/dist/esm/Autocomplete/AutocompleteController.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteController.js +25 -24
- package/dist/esm/Finder/FinderController.d.ts.map +1 -1
- package/dist/esm/Finder/FinderController.js +12 -13
- package/dist/esm/Recommendation/RecommendationController.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationController.js +17 -11
- package/dist/esm/Search/SearchController.d.ts +0 -1
- package/dist/esm/Search/SearchController.d.ts.map +1 -1
- package/dist/esm/Search/SearchController.js +15 -26
- package/package.json +10 -10
|
@@ -24,7 +24,6 @@ export class SearchController extends AbstractController {
|
|
|
24
24
|
constructor(config, { client, store, urlManager, eventManager, profiler, logger, tracker }, context) {
|
|
25
25
|
super(config, { client, store, urlManager, eventManager, profiler, logger, tracker }, context);
|
|
26
26
|
this.type = ControllerTypes.search;
|
|
27
|
-
this.previousResults = [];
|
|
28
27
|
this.track = {
|
|
29
28
|
product: {
|
|
30
29
|
click: (e, result) => {
|
|
@@ -67,15 +66,16 @@ export class SearchController extends AbstractController {
|
|
|
67
66
|
},
|
|
68
67
|
};
|
|
69
68
|
this.search = async () => {
|
|
70
|
-
if (!this.initialized) {
|
|
71
|
-
await this.init();
|
|
72
|
-
}
|
|
73
|
-
const params = this.params;
|
|
74
|
-
if (this.params.search?.query?.string && this.params.search?.query?.string.length) {
|
|
75
|
-
// save it to the history store
|
|
76
|
-
this.store.history.save(this.params.search.query.string);
|
|
77
|
-
}
|
|
78
69
|
try {
|
|
70
|
+
if (!this.initialized) {
|
|
71
|
+
await this.init();
|
|
72
|
+
}
|
|
73
|
+
const params = this.params;
|
|
74
|
+
if (this.params.search?.query?.string && this.params.search?.query?.string.length) {
|
|
75
|
+
// save it to the history store
|
|
76
|
+
this.store.history.save(this.params.search.query.string);
|
|
77
|
+
}
|
|
78
|
+
this.store.loading = true;
|
|
79
79
|
try {
|
|
80
80
|
await this.eventManager.fire('beforeSearch', {
|
|
81
81
|
controller: this,
|
|
@@ -112,7 +112,7 @@ export class SearchController extends AbstractController {
|
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
// infinite backfill is enabled AND we have not yet fetched any results
|
|
115
|
-
if (this.config.settings?.infinite.backfill && !this.
|
|
115
|
+
if (this.config.settings?.infinite.backfill && !this.store.loaded) {
|
|
116
116
|
// create requests for all missing pages (using Arrray(page).fill() to populate an array to map)
|
|
117
117
|
const backfillRequests = Array(params.pagination.page)
|
|
118
118
|
.fill('backfill')
|
|
@@ -148,12 +148,10 @@ export class SearchController extends AbstractController {
|
|
|
148
148
|
else {
|
|
149
149
|
// infinite with no backfills.
|
|
150
150
|
[meta, response] = await this.client.search(params);
|
|
151
|
-
// append new results to previous results
|
|
152
|
-
response.results = [...this.previousResults, ...(response.results || [])];
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
153
|
else {
|
|
156
|
-
//
|
|
154
|
+
// normal request for next page
|
|
157
155
|
[meta, response] = await this.client.search(params);
|
|
158
156
|
}
|
|
159
157
|
// MockClient will overwrite the client search() method and use SearchData to return mock data which already contains meta data
|
|
@@ -183,10 +181,6 @@ export class SearchController extends AbstractController {
|
|
|
183
181
|
}
|
|
184
182
|
afterSearchProfile.stop();
|
|
185
183
|
this.log.profile(afterSearchProfile);
|
|
186
|
-
// store previous results for infinite usage
|
|
187
|
-
if (this.config.settings?.infinite) {
|
|
188
|
-
this.previousResults = JSON.parse(JSON.stringify(response.results));
|
|
189
|
-
}
|
|
190
184
|
// update the store
|
|
191
185
|
this.store.update(response);
|
|
192
186
|
const afterStoreProfile = this.profiler.create({ type: 'event', name: 'afterStore', context: params }).start();
|
|
@@ -250,9 +244,11 @@ export class SearchController extends AbstractController {
|
|
|
250
244
|
this.log.error(err);
|
|
251
245
|
this.handleError(err);
|
|
252
246
|
}
|
|
253
|
-
this.store.loading = false;
|
|
254
247
|
}
|
|
255
248
|
}
|
|
249
|
+
finally {
|
|
250
|
+
this.store.loading = false;
|
|
251
|
+
}
|
|
256
252
|
};
|
|
257
253
|
// deep merge config with defaults
|
|
258
254
|
this.config = deepmerge(defaultConfig, this.config);
|
|
@@ -267,11 +263,6 @@ export class SearchController extends AbstractController {
|
|
|
267
263
|
});
|
|
268
264
|
// set last params to undefined for compare in search
|
|
269
265
|
this.storage.set('lastStringyParams', undefined);
|
|
270
|
-
// add 'beforeSearch' middleware
|
|
271
|
-
this.eventManager.on('beforeSearch', async (search, next) => {
|
|
272
|
-
search.controller.store.loading = true;
|
|
273
|
-
await next();
|
|
274
|
-
});
|
|
275
266
|
// add 'afterSearch' middleware
|
|
276
267
|
this.eventManager.on('afterSearch', async (search, next) => {
|
|
277
268
|
const config = search.controller.config;
|
|
@@ -285,8 +276,7 @@ export class SearchController extends AbstractController {
|
|
|
285
276
|
if (config?.settings?.redirects?.singleResult &&
|
|
286
277
|
search?.response?.search?.query &&
|
|
287
278
|
search?.response?.pagination?.totalResults === 1 &&
|
|
288
|
-
!nonBackgroundFilters?.length
|
|
289
|
-
!search.controller.previousResults.length) {
|
|
279
|
+
!nonBackgroundFilters?.length) {
|
|
290
280
|
window.location.replace(search?.response.results[0].mappings.core.url);
|
|
291
281
|
return false;
|
|
292
282
|
}
|
|
@@ -306,7 +296,6 @@ export class SearchController extends AbstractController {
|
|
|
306
296
|
this.storage.set('scrollMap', {});
|
|
307
297
|
}
|
|
308
298
|
await this.eventManager.fire('restorePosition', { controller: this, element: elementPosition });
|
|
309
|
-
search.controller.store.loading = false;
|
|
310
299
|
});
|
|
311
300
|
// restore position
|
|
312
301
|
if (this.config.settings?.restorePosition?.enabled) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-controller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Snap Controllers",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,22 +20,22 @@
|
|
|
20
20
|
"test:watch": "jest --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@searchspring/snap-toolbox": "^0.
|
|
23
|
+
"@searchspring/snap-toolbox": "^0.63.0",
|
|
24
24
|
"css.escape": "1.5.1",
|
|
25
25
|
"deepmerge": "4.3.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@searchspring/snap-client": "^0.
|
|
29
|
-
"@searchspring/snap-event-manager": "^0.
|
|
30
|
-
"@searchspring/snap-logger": "^0.
|
|
31
|
-
"@searchspring/snap-profiler": "^0.
|
|
32
|
-
"@searchspring/snap-store-mobx": "^0.
|
|
33
|
-
"@searchspring/snap-tracker": "^0.
|
|
34
|
-
"@searchspring/snap-url-manager": "^0.
|
|
28
|
+
"@searchspring/snap-client": "^0.63.0",
|
|
29
|
+
"@searchspring/snap-event-manager": "^0.63.0",
|
|
30
|
+
"@searchspring/snap-logger": "^0.63.0",
|
|
31
|
+
"@searchspring/snap-profiler": "^0.63.0",
|
|
32
|
+
"@searchspring/snap-store-mobx": "^0.63.0",
|
|
33
|
+
"@searchspring/snap-tracker": "^0.63.0",
|
|
34
|
+
"@searchspring/snap-url-manager": "^0.63.0"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"files": [
|
|
38
38
|
"dist/**/*"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "46278e19380f22e90fdff4afc01359be27feb5a8"
|
|
41
41
|
}
|