@@ -2,11 +2,12 @@ define([
2
2
'jquery' ,
3
3
'algoliaBundle' ,
4
4
'algoliaHoganLib' ,
5
+ 'algoliaMustacheLib' ,
5
6
'Magento_Catalog/js/price-utils' ,
6
7
'algoliaCommon' ,
7
8
'algoliaInsights' ,
8
9
'algoliaHooks' ,
9
- ] , function ( $ , algoliaBundle , Hogan , priceUtils ) {
10
+ ] , function ( $ , algoliaBundle , Hogan , Mustache , priceUtils ) {
10
11
$ ( function ( $ ) {
11
12
/** We have nothing to do here if instantsearch is not enabled **/
12
13
if (
@@ -83,10 +84,10 @@ define([
83
84
*
84
85
* For templating is used Hogan library
85
86
* Docs: http://twitter.github.io/hogan.js/
87
+ *
88
+ * Alternatively use Mustache
89
+ * https://github.com/janl/mustache.js
86
90
**/
87
- var wrapperTemplate = Hogan . compile (
88
- $ ( '#instant_wrapper_template' ) . html ( )
89
- ) ;
90
91
var instant_selector = '#instant-search-bar' ;
91
92
92
93
var div = document . createElement ( 'div' ) ;
@@ -100,14 +101,28 @@ define([
100
101
$ ( '.algolia-instant-results-wrapper' ) . append (
101
102
'<div class="algolia-instant-selector-results"></div>'
102
103
) ;
104
+
105
+ const template = $ ( '#instant_wrapper_template' ) . html ( ) ;
106
+ const templateVars = {
107
+ second_bar : algoliaConfig . instant . enabled ,
108
+ findAutocomplete : findAutocomplete ,
109
+ config : algoliaConfig . instant ,
110
+ translations : algoliaConfig . translations ,
111
+ } ;
112
+ const hoganStart = performance . now ( ) ;
113
+ const wrapperTemplate = Hogan . compile ( template ) ;
114
+ const hoganResult = wrapperTemplate . render ( templateVars ) ;
115
+ const hoganEnd = performance . now ( ) ;
116
+ console . log ( "Hogan execution time: %s ms" , hoganEnd - hoganStart ) ;
117
+
118
+ const mustacheStart = performance . now ( ) ;
119
+ const mustacheResult = Mustache . render ( template , templateVars ) ;
120
+ const mustacheEnd = performance . now ( ) ;
121
+ console . log ( "Mustache execution time: %s ms" , mustacheEnd - mustacheStart ) ;
122
+
103
123
$ ( '.algolia-instant-selector-results' )
104
124
. html (
105
- wrapperTemplate . render ( {
106
- second_bar : algoliaConfig . instant . enabled ,
107
- findAutocomplete : findAutocomplete ,
108
- config : algoliaConfig . instant ,
109
- translations : algoliaConfig . translations ,
110
- } )
125
+ mustacheResult
111
126
)
112
127
. show ( ) ;
113
128
0 commit comments