@@ -8,6 +8,24 @@ define([
8
8
'algoliaInsights' ,
9
9
'algoliaHooks' ,
10
10
] , function ( $ , algoliaBundle , Hogan , Mustache , priceUtils ) {
11
+ const processTemplate = ( template , templateVars , useMustache = false ) => {
12
+ const hoganStart = performance . now ( ) ;
13
+ const wrapperTemplate = Hogan . compile ( template ) ;
14
+ const hoganResult = wrapperTemplate . render ( templateVars ) ;
15
+ const hoganEnd = performance . now ( ) ;
16
+ console . log ( "Hogan execution time: %s ms" , hoganEnd - hoganStart ) ;
17
+
18
+ if ( useMustache ) {
19
+ const mustacheStart = performance . now ( ) ;
20
+ const mustacheResult = Mustache . render ( template , templateVars ) ;
21
+ const mustacheEnd = performance . now ( ) ;
22
+ console . log ( "Mustache execution time: %s ms" , mustacheEnd - mustacheStart ) ;
23
+ return mustacheResult ;
24
+ }
25
+
26
+ return hoganResult ;
27
+ } ;
28
+
11
29
$ ( function ( $ ) {
12
30
/** We have nothing to do here if instantsearch is not enabled **/
13
31
if (
@@ -109,21 +127,9 @@ define([
109
127
config : algoliaConfig . instant ,
110
128
translations : algoliaConfig . translations ,
111
129
} ;
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
-
130
+
123
131
$ ( '.algolia-instant-selector-results' )
124
- . html (
125
- mustacheResult
126
- )
132
+ . html ( processTemplate ( template , templateVars , true ) )
127
133
. show ( ) ;
128
134
129
135
/**
@@ -348,17 +354,15 @@ define([
348
354
container : '#algolia-stats' ,
349
355
templates : {
350
356
text : function ( data ) {
351
- var hoganTemplate = Hogan . compile (
352
- $ ( '#instant-stats-template' ) . html ( )
353
- ) ;
354
-
355
357
data . first = data . page * data . hitsPerPage + 1 ;
356
358
data . last = Math . min (
357
359
data . page * data . hitsPerPage + data . hitsPerPage ,
358
360
data . nbHits
359
361
) ;
360
362
data . seconds = data . processingTimeMS / 1000 ;
361
363
data . translations = window . algoliaConfig . translations ;
364
+
365
+ // TODO: Revisit this injected jQuery logic
362
366
const searchParams = new URLSearchParams ( window . location . search ) ;
363
367
const searchQuery = searchParams . has ( 'q' ) || '' ;
364
368
if ( searchQuery === '' && ! algoliaConfig . isSearchPage ) {
@@ -368,7 +372,9 @@ define([
368
372
$ ( '.algolia-instant-replaced-content' ) . hide ( ) ;
369
373
$ ( '.algolia-instant-selector-results' ) . show ( ) ;
370
374
}
371
- return hoganTemplate . render ( data ) ;
375
+
376
+ var template = $ ( '#instant-stats-template' ) . html ( ) ;
377
+ return processTemplate ( template , data , true ) ;
372
378
} ,
373
379
} ,
374
380
} ,
0 commit comments