Skip to content

Commit ef78cdd

Browse files
committed
MAGE-975: Improve JSDoc per code review
1 parent 926e0f3 commit ef78cdd

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

view/frontend/web/js/instantsearch.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@ define([
2828
minQuerySuggestions: 4,
2929

3030
/**
31-
* Initialize search results using Algolia's InstantSearch.js library v4
31+
* Load and display search results using Algolia's InstantSearch.js library v4
32+
*
33+
* This is the main entry point for building the Magento InstantSearch experience.
34+
*
35+
* Rough overview of build process:
36+
*
37+
* - Initializes dependencies
38+
* - Creates the DOM elements where InstantSearch widgets will be inserted on the PLP
39+
* - Creates the InstantSearch object with configured options
40+
* - All widgets are preconfigured using the `allWidgetConfiguration` object
41+
* - This object houses all widgets to be displayed in the frontend experience and is important for customization
42+
* - Passed to `beforeWidgetInitialization` hook
43+
* - Implementation is specific to Magento index object data structure
44+
* - Loads `allWidgetConfiguration` into InstantSearch
45+
* - Starts InstantSearch which adds the widgets to the DOM and performs first search
46+
*
3247
* Docs: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/
3348
*/
3449
async buildInstantSearch() {
@@ -151,6 +166,8 @@ define([
151166
*
152167
* Any facet builders returned by this function will take precedence over getFacetConfig()
153168
*
169+
* Triggers the hook: beforeFacetInitialization
170+
*
154171
* @returns {Object<string, function>}
155172
* @see getFacetConfig
156173
*/
@@ -386,6 +403,10 @@ define([
386403
},
387404

388405
/**
406+
* Loads refinements management capabilities
407+
* i.e. As refinements are applied to search results via faceting,
408+
* this feature allows you to selectively remove one or all refinements.
409+
*
389410
* @param allWidgetConfiguration
390411
* @returns {*}
391412
*/
@@ -667,6 +688,15 @@ define([
667688
});
668689
},
669690

691+
/**
692+
* Load the supplied widget configuration into InstantSearch
693+
*
694+
* Triggers the hook: beforeWidgetInitialization
695+
*
696+
* @param search
697+
* @param allWidgetConfiguration
698+
* @param mockAlgoliaBundle
699+
*/
670700
initializeWidgets(search, allWidgetConfiguration, mockAlgoliaBundle) {
671701
allWidgetConfiguration = algoliaCommon.triggerHooks(
672702
'beforeWidgetInitialization',
@@ -690,6 +720,11 @@ define([
690720
},
691721

692722
/**
723+
* Get the configuration options for creating the InstantSearch object
724+
* Docs: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#options
725+
*
726+
* Triggers the hook: beforeInstantsearchInit
727+
*
693728
* @param mockAlgoliaBundle to be removed in a future release
694729
* @returns {*}
695730
*/
@@ -705,6 +740,9 @@ define([
705740
);
706741
},
707742

743+
/**
744+
* NOTE: The initial (relevant) sort is based on the main index
745+
*/
708746
prepareSortingIndices() {
709747
algoliaConfig.sortingIndices.unshift({
710748
name : this.getProductIndexName(),
@@ -796,7 +834,8 @@ define([
796834
},
797835

798836
/**
799-
* Build wrapper DOM object to contain InstantSearch
837+
* Build wrapper DOM object to contain InstantSearch widgets
838+
*
800839
* @param templateProcessor
801840
*/
802841
setupWrapper(templateProcessor) {
@@ -921,6 +960,18 @@ define([
921960
return attributes;
922961
},
923962

963+
/**
964+
* Starts InstantSearch which adds all pre-loaded widgets to the DOM and triggers the first search
965+
*
966+
* Docs: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-start
967+
*
968+
* Triggers the hooks:
969+
* - beforeInstantsearchStart
970+
* - afterInstantsearchStart
971+
*
972+
* @param search
973+
* @param mockAlgoliaBundle
974+
*/
924975
startInstantSearch(search, mockAlgoliaBundle) {
925976
if (this.isStarted) {
926977
return;
@@ -976,6 +1027,9 @@ define([
9761027
return this.getFacetConfig(facet);
9771028
},
9781029

1030+
/**
1031+
* Docs: https://www.algolia.com/doc/api-reference/widgets/range-input/js/
1032+
*/
9791033
getRangeInputFacetConfig(facet, panelOptions) {
9801034
return [
9811035
'rangeInput',
@@ -1055,7 +1109,7 @@ define([
10551109
),
10561110
attribute : facet.attribute,
10571111
pips : false,
1058-
panelOptions: panelOptions,
1112+
panelOptions,
10591113
tooltips : {
10601114
format(value) {
10611115
return facet.attribute.match(/price/) === null

0 commit comments

Comments
 (0)