Skip to content

Commit 160359a

Browse files
authored
Merge pull request #1605 from algolia/feature/MAGE-998-unbundle-instantsearch
Feature/mage 998 unbundle instantsearch
2 parents e1df491 + 9c3585d commit 160359a

File tree

13 files changed

+109
-59
lines changed

13 files changed

+109
-59
lines changed

view/frontend/requirejs-config.js

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var config = {
2-
map : {
1+
const config = {
2+
map: {
33
'*': {
44
// Magento FE libs
55
'algoliaCommon' : 'Algolia_AlgoliaSearch/js/internals/common',
@@ -8,35 +8,54 @@ var config = {
88
'algoliaInsights' : 'Algolia_AlgoliaSearch/js/insights',
99
'algoliaHooks' : 'Algolia_AlgoliaSearch/js/hooks',
1010

11-
// Autocomplete templates
12-
'productsHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/products',
13-
'pagesHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/pages',
14-
'categoriesHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/categories',
15-
'suggestionsHtml': 'Algolia_AlgoliaSearch/js/template/autocomplete/suggestions',
16-
'additionalHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/additional-section',
11+
// Unbundled template processor
12+
'algoliaTemplateEngine': 'Algolia_AlgoliaSearch/js/internals/template-engine',
1713

18-
// Recommend templates
19-
'recommendProductsHtml': 'Algolia_AlgoliaSearch/js/template/recommend/products',
20-
21-
// Unbundling
22-
'algoliaTemplateEngine': 'Algolia_AlgoliaSearch/js/internals/template-engine'
14+
// DEPRECATED - migrated to new paths - these will be removed in a future release
15+
'algoliaAnalytics' : 'algoliaAnalyticsLib',
16+
'recommend' : 'algoliaRecommendLib',
17+
'recommendJs' : 'algoliaRecommendJsLib',
18+
'productsHtml' : 'algoliaAutocompleteProductsHtml',
19+
'pagesHtml' : 'algoliaAutocompletePagesHtml',
20+
'categoriesHtml' : 'algoliaAutocompleteCategoriesHtml',
21+
'suggestionsHtml' : 'algoliaAutocompleteSuggestionsHtml',
22+
'additionalHtml' : 'algoliaAutocompleteAdditionalHtml',
23+
'recommendProductsHtml': 'algoliaRecommendProductsHtml'
2324
}
2425
},
25-
paths : {
26-
'algoliaBundle' : 'Algolia_AlgoliaSearch/js/internals/algoliaBundle.min',
27-
'algoliaSearchLib' : 'Algolia_AlgoliaSearch/js/lib/algolia-search.min',
28-
'algoliaAutocompleteLib' : 'Algolia_AlgoliaSearch/js/lib/algolia-autocomplete.min',
29-
'algoliaAnalytics' : 'Algolia_AlgoliaSearch/js/internals/search-insights',
30-
'algoliaQuerySuggestionsPluginLib' : 'Algolia_AlgoliaSearch/js/lib/query-suggestions-plugin.min',
31-
'recommend' : 'Algolia_AlgoliaSearch/js/internals/recommend.min',
32-
'recommendJs' : 'Algolia_AlgoliaSearch/js/internals/recommend-js.min',
33-
'rangeSlider' : 'Algolia_AlgoliaSearch/js/navigation/range-slider-widget',
34-
// Legacy
35-
'algoliaHoganLib' : 'Algolia_AlgoliaSearch/js/lib/hogan.min',
36-
'algoliaMustacheLib' : 'Algolia_AlgoliaSearch/js/lib/mustache.min'
26+
paths: {
27+
// Core Search UI libs
28+
'algoliaSearchLib' : 'Algolia_AlgoliaSearch/js/lib/algolia-search.min',
29+
'algoliaInstantSearchLib': 'Algolia_AlgoliaSearch/js/lib/algolia-instantsearch.min',
30+
'algoliaAutocompleteLib' : 'Algolia_AlgoliaSearch/js/lib/algolia-autocomplete.min',
31+
'algoliaAnalyticsLib' : 'Algolia_AlgoliaSearch/js/lib/search-insights.min',
32+
'algoliaRecommendLib' : 'Algolia_AlgoliaSearch/js/lib/recommend.min',
33+
'algoliaRecommendJsLib' : 'Algolia_AlgoliaSearch/js/lib/recommend-js.min',
34+
35+
// Autocomplete plugins
36+
'algoliaQuerySuggestionsPluginLib': 'Algolia_AlgoliaSearch/js/lib/query-suggestions-plugin.min',
37+
38+
// Autocomplete templates
39+
'algoliaAutocompleteProductsHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/products',
40+
'algoliaAutocompletePagesHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/pages',
41+
'algoliaAutocompleteCategoriesHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/categories',
42+
'algoliaAutocompleteSuggestionsHtml': 'Algolia_AlgoliaSearch/js/template/autocomplete/suggestions',
43+
'algoliaAutocompleteAdditionalHtml' : 'Algolia_AlgoliaSearch/js/template/autocomplete/additional-section',
44+
45+
// Recommend templates
46+
'algoliaRecommendProductsHtml': 'Algolia_AlgoliaSearch/js/template/recommend/products',
47+
48+
// Parser libs for legacy templating
49+
'algoliaMustacheLib': 'Algolia_AlgoliaSearch/js/lib/mustache.min',
50+
'algoliaHoganLib' : 'Algolia_AlgoliaSearch/js/lib/hogan.min',
51+
52+
// DEPRECATED - to be removed in a future release
53+
'algoliaBundle': 'Algolia_AlgoliaSearch/js/internals/algoliaBundle.min',
54+
'rangeSlider' : 'Algolia_AlgoliaSearch/js/navigation/range-slider-widget'
55+
3756
},
38-
deps : [
39-
'algoliaInstantSearch',
57+
deps : [
58+
'algoliaInstantSearch',
4059
'algoliaInsights'
4160
],
4261
config: {
@@ -46,7 +65,7 @@ var config = {
4665
}
4766
}
4867
},
49-
shim: {
68+
shim : {
5069
'algoliaHoganLib': {
5170
exports: 'Hogan'
5271
}

view/frontend/templates/recommend/products.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (!empty($recommendConfig['enabledFBT'])
2323
<script type="text/x-magento-init">
2424
{
2525
"*": {
26-
"Algolia_AlgoliaSearch/recommend" : {
26+
"Algolia_AlgoliaSearch/js/recommend" : {
2727
"objectIDs" : ["<?= $product->getId() ?>"]
2828
}
2929
}

view/frontend/templates/recommend/widget/looking-similar.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if ($isEnabled):
77
<script type="text/x-magento-init">
88
{
99
"*": {
10-
"Algolia_AlgoliaSearch/recommend" : {
10+
"Algolia_AlgoliaSearch/js/recommend" : {
1111
"recommendLSContainer" : "<?= $lsContainer ?>",
1212
"numOfLookingSimilarItem" : "<?= $block->getData('numOfLookingSimilarItem') ?>",
1313
"objectIDs" : <?= $block->getProductIds() ?>

view/frontend/templates/recommend/widget/trends-item.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if ($isEnabled):
99
<script type="text/x-magento-init">
1010
{
1111
"*": {
12-
"Algolia_AlgoliaSearch/recommend" : {
12+
"Algolia_AlgoliaSearch/js/recommend" : {
1313
"recommendTrendContainer" : "<?= $trendConstainer ?>",
1414
"numOfTrendsItem" : "<?= $block->getData('numOfTrendsItem') ?>",
1515
"facetName" : "<?= $block->getData('facetName') ?>",

view/frontend/web/js/autocomplete.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
define([
22
'jquery',
3-
'algoliaBundle',
43
'algoliaSearchLib',
54
'algoliaAutocompleteLib',
65
'algoliaQuerySuggestionsPluginLib',
7-
'pagesHtml',
8-
'categoriesHtml',
9-
'productsHtml',
10-
'suggestionsHtml',
11-
'additionalHtml',
6+
'algoliaAutocompletePagesHtml',
7+
'algoliaAutocompleteCategoriesHtml',
8+
'algoliaAutocompleteProductsHtml',
9+
'algoliaAutocompleteSuggestionsHtml',
10+
'algoliaAutocompleteAdditionalHtml',
1211
'algoliaCommon',
1312
'algoliaInsights',
1413
'algoliaHooks',
1514
'domReady!',
1615
], function (
1716
$,
18-
algoliaBundle,
1917
algoliasearch,
2018
autocomplete,
2119
querySuggestionsPlugin,

view/frontend/web/js/insights.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define([
22
'jquery',
3-
'algoliaAnalytics',
4-
'algoliaBundle',
3+
'algoliaAnalyticsLib',
54
'algoliaCommon',
65
'mage/cookies',
7-
], function ($, algoliaAnalyticsWrapper, algoliaBundle) {
6+
], function ($, algoliaAnalyticsWrapper) {
87
algoliaAnalytics = algoliaAnalyticsWrapper.default;
98

109
window.algoliaInsights = {
@@ -223,7 +222,7 @@ define([
223222

224223
algolia.registerHook(
225224
'afterInstantsearchStart',
226-
function (search, algoliaBundle) {
225+
function (search) {
227226
var selectors = document.querySelectorAll(containers.join(', '));
228227
selectors.forEach(function (e) {
229228
e.addEventListener('click', function (event) {

view/frontend/web/js/instantsearch.js

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
define([
22
'jquery',
3-
'algoliaBundle',
3+
4+
// Algolia core UI libs
5+
'algoliaSearchLib',
6+
'algoliaInstantSearchLib',
7+
8+
// Algolia integration dependencies
49
'algoliaTemplateEngine',
10+
11+
// Magento core libs
512
'Magento_Catalog/js/price-utils',
13+
14+
// TODO: Refactor legacy global object dependencies
615
'algoliaCommon',
716
'algoliaInsights',
817
'algoliaHooks',
9-
], function ($, algoliaBundle, templateEngine, priceUtils) {
18+
], function ($, algoliasearch, instantsearch, templateEngine, priceUtils) {
19+
20+
/**
21+
* @deprecated algoliaBundle is going away!
22+
* This mock only includes libraries available to this module
23+
* The following have been removed:
24+
* - Hogan
25+
* - algoliasearchHelper
26+
* - autocomplete
27+
* - createAlgoliaInsightsPlugin
28+
* - createLocalStorageRecentSearchesPlugin
29+
* - createQuerySuggestionsPlugin
30+
* - getAlgoliaResults
31+
* However if you've used or require any of these additional libs in your customizations,
32+
* you can either augment this mock as you need or include the global dependency in your module
33+
* and make it available to your hook.
34+
* TODO: Mixin and documentation to come on how to do this...
35+
*/
36+
const mockAlgoliaBundle = {
37+
$,
38+
algoliasearch,
39+
instantsearch
40+
};
41+
1042
$(async function ($) {
1143
const templateProcessor = await templateEngine.getSelectedEngineAdapter();
1244

@@ -131,7 +163,7 @@ define([
131163
);
132164
}
133165

134-
var searchClient = algoliaBundle.algoliasearch(
166+
var searchClient = algoliasearch(
135167
algoliaConfig.applicationId,
136168
algoliaConfig.apiKey
137169
);
@@ -170,10 +202,10 @@ define([
170202
instantsearchOptions = algolia.triggerHooks(
171203
'beforeInstantsearchInit',
172204
instantsearchOptions,
173-
algoliaBundle
205+
mockAlgoliaBundle
174206
);
175207

176-
var search = algoliaBundle.instantsearch(instantsearchOptions);
208+
var search = instantsearch(instantsearchOptions);
177209

178210
search.client.addAlgoliaAgent(
179211
'Magento2 integration (' + algoliaConfig.extensionVersion + ')'
@@ -850,7 +882,7 @@ define([
850882
allWidgetConfiguration = algolia.triggerHooks(
851883
'beforeWidgetInitialization',
852884
allWidgetConfiguration,
853-
algoliaBundle
885+
mockAlgoliaBundle
854886
);
855887

856888
$.each(allWidgetConfiguration, function (widgetType, widgetConfig) {
@@ -890,13 +922,13 @@ define([
890922
search = algolia.triggerHooks(
891923
'beforeInstantsearchStart',
892924
search,
893-
algoliaBundle
925+
mockAlgoliaBundle
894926
);
895927
search.start();
896928
search = algolia.triggerHooks(
897929
'afterInstantsearchStart',
898930
search,
899-
algoliaBundle
931+
mockAlgoliaBundle
900932
);
901933

902934
isStarted = true;
@@ -911,9 +943,9 @@ define([
911943
search.addWidgets([config]);
912944
return;
913945
}
914-
var widget = algoliaBundle.instantsearch.widgets[type];
946+
var widget = instantsearch.widgets[type];
915947
if (config.panelOptions) {
916-
widget = algoliaBundle.instantsearch.widgets.panel(config.panelOptions)(
948+
widget = instantsearch.widgets.panel(config.panelOptions)(
917949
widget
918950
);
919951
delete config.panelOptions;
@@ -924,7 +956,7 @@ define([
924956
return options.range.min === 0 && options.range.max === 0;
925957
},
926958
};
927-
widget = algoliaBundle.instantsearch.widgets.panel(config.panelOptions)(
959+
widget = instantsearch.widgets.panel(config.panelOptions)(
928960
widget
929961
);
930962
delete config.panelOptions;

view/frontend/web/js/internals/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
1+
define(['jquery', 'algoliaInstantSearchLib'], function ($, instantsearch) {
22
// Character maps supplied for more performant Regex ops
33
const SPECIAL_CHAR_ENCODE_MAP = {
44
'&': '&amp;',
@@ -305,7 +305,7 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
305305
// Multivalued facets use "~" as separator
306306
// Targeted index is defined by sortBy parameter
307307
window.routing = {
308-
router: algoliaBundle.instantsearch.routers.history({
308+
router: instantsearch.routers.history({
309309
parseURL: function (qsObject) {
310310
var location = qsObject.location,
311311
qsModule = qsObject.qsModule;

view/frontend/web/js/lib/algolia-instantsearch.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)