11import { Reducer } from './types' ;
22import { getItemsCount , getNextHighlightedIndex } from './utils' ;
33
4- export const stateReducer : Reducer = ( action , state , props ) => {
4+ export const stateReducer : Reducer = ( state , action ) => {
55 switch ( action . type ) {
66 case 'setHighlightedIndex' : {
77 return {
88 ...state ,
9- highlightedIndex : action . value ,
9+ highlightedIndex : action . payload ,
1010 } ;
1111 }
1212
1313 case 'setQuery' : {
1414 return {
1515 ...state ,
16- query : action . value ,
16+ query : action . payload ,
1717 } ;
1818 }
1919
2020 case 'setSuggestions' : {
2121 return {
2222 ...state ,
23- suggestions : action . value ,
23+ suggestions : action . payload ,
2424 } ;
2525 }
2626
2727 case 'setIsOpen' : {
2828 return {
2929 ...state ,
30- isOpen : action . value ,
30+ isOpen : action . payload ,
3131 } ;
3232 }
3333
3434 case 'setStatus' : {
3535 return {
3636 ...state ,
37- status : action . value ,
37+ status : action . payload ,
3838 } ;
3939 }
4040
@@ -43,7 +43,7 @@ export const stateReducer: Reducer = (action, state, props) => {
4343 ...state ,
4444 context : {
4545 ...state . context ,
46- ...action . value ,
46+ ...action . payload ,
4747 } ,
4848 } ;
4949 }
@@ -55,7 +55,7 @@ export const stateReducer: Reducer = (action, state, props) => {
5555 1 ,
5656 state . highlightedIndex ,
5757 getItemsCount ( state ) ,
58- props . defaultHighlightedIndex
58+ action . props . defaultHighlightedIndex
5959 ) ,
6060 } ;
6161 }
@@ -67,7 +67,7 @@ export const stateReducer: Reducer = (action, state, props) => {
6767 - 1 ,
6868 state . highlightedIndex ,
6969 getItemsCount ( state ) ,
70- props . defaultHighlightedIndex
70+ action . props . defaultHighlightedIndex
7171 ) ,
7272 } ;
7373 }
@@ -108,8 +108,10 @@ export const stateReducer: Reducer = (action, state, props) => {
108108
109109 // Since we close the menu when openOnFocus=false
110110 // we lose track of the highlighted index. (Query-suggestions use-case)
111- props . openOnFocus === true ? props . defaultHighlightedIndex : null ,
112- isOpen : props . openOnFocus , // @TODO : Check with UX team if we want to close the menu on reset.
111+ action . props . openOnFocus === true
112+ ? action . props . defaultHighlightedIndex
113+ : null ,
114+ isOpen : action . props . openOnFocus , // @TODO : Check with UX team if we want to close the menu on reset.
113115 status : 'idle' ,
114116 statusContext : { } ,
115117 query : '' ,
@@ -119,13 +121,13 @@ export const stateReducer: Reducer = (action, state, props) => {
119121 case 'focus' : {
120122 return {
121123 ...state ,
122- highlightedIndex : props . defaultHighlightedIndex ,
123- isOpen : props . openOnFocus || state . query . length > 0 ,
124+ highlightedIndex : action . props . defaultHighlightedIndex ,
125+ isOpen : action . props . openOnFocus || state . query . length > 0 ,
124126 } ;
125127 }
126128
127129 case 'blur' : {
128- if ( props . debug ) {
130+ if ( action . props . debug ) {
129131 return state ;
130132 }
131133
@@ -139,14 +141,14 @@ export const stateReducer: Reducer = (action, state, props) => {
139141 case 'mousemove' : {
140142 return {
141143 ...state ,
142- highlightedIndex : action . value ,
144+ highlightedIndex : action . payload ,
143145 } ;
144146 }
145147
146148 case 'mouseleave' : {
147149 return {
148150 ...state ,
149- highlightedIndex : props . defaultHighlightedIndex ,
151+ highlightedIndex : action . props . defaultHighlightedIndex ,
150152 } ;
151153 }
152154
0 commit comments