@@ -42,18 +42,16 @@ define([
42
42
const DEBOUNCE_MS = algoliaConfig . autocomplete . debounceMilliseconds ;
43
43
const MIN_SEARCH_LENGTH_CHARS = algoliaConfig . autocomplete . minimumCharacters ;
44
44
45
- // Global state
46
- const state = {
47
- hasRendered : false ,
48
- hasSuggestionSection : false
49
- } ;
50
-
51
45
return Component . extend ( {
52
46
DEFAULT_HITS_PER_SECTION ,
53
47
DEBOUNCE_MS ,
54
48
MIN_SEARCH_LENGTH_CHARS ,
55
49
56
- hasRedirect : false ,
50
+ state : {
51
+ hasRendered : false ,
52
+ hasSuggestionSection : false ,
53
+ hasRedirect : false
54
+ } ,
57
55
58
56
navigator : {
59
57
navigate ( { itemUrl} ) {
@@ -119,7 +117,7 @@ define([
119
117
} ,
120
118
121
119
handleAutocompleteSubmit ( { state : { query } } ) {
122
- if ( query && ! this . hasRedirect ) {
120
+ if ( query && ! this . state . hasRedirect ) {
123
121
this . navigator . navigate ( { itemUrl : this . getSearchResultsUrl ( query ) } ) ;
124
122
}
125
123
} ,
@@ -425,7 +423,7 @@ define([
425
423
source . transformResponse = ( { results, hits} ) => {
426
424
const resDetail = results [ 0 ] ;
427
425
const redirectUrl = resDetail ?. renderingContent ?. redirect ?. url ;
428
- this . hasRedirect = ! ! redirectUrl ;
426
+ this . state . hasRedirect = ! ! redirectUrl ;
429
427
430
428
return hits . map ( ( res ) => {
431
429
return res . map ( ( hit , i ) => {
@@ -555,7 +553,7 @@ define([
555
553
const plugins = [ ] ;
556
554
557
555
if ( algoliaConfig . autocomplete . nbOfQueriesSuggestions > 0 ) {
558
- state . hasSuggestionSection = true ;
556
+ this . state . hasSuggestionSection = true ;
559
557
plugins . push ( this . buildSuggestionsPlugin ( searchClient ) ) ;
560
558
}
561
559
@@ -917,9 +915,9 @@ define([
917
915
} ,
918
916
919
917
handleAutocompleteStateChange ( autocompleteState ) {
920
- if ( ! state . hasRendered && autocompleteState . isOpen ) {
918
+ if ( ! this . state . hasRendered && autocompleteState . isOpen ) {
921
919
this . addPanelObserver ( ) ;
922
- state . hasRendered = true ;
920
+ this . state . hasRendered = true ;
923
921
}
924
922
} ,
925
923
0 commit comments