MCPcopy
hub / github.com/algolia/autocomplete / stateReducer

Function stateReducer

packages/autocomplete-core/src/stateReducer.ts:7–181  ·  view source on GitHub ↗
(state, action)

Source from the content-addressed store, hash-verified

5import { getNextActiveItemId } from './utils';
6
7export const stateReducer: Reducer = (state, action) => {
8 switch (action.type) {
9 case 'setActiveItemId': {
10 return {
11 ...state,
12 activeItemId: action.payload,
13 };
14 }
15
16 case 'setQuery': {
17 return {
18 ...state,
19 query: action.payload,
20 completion: null,
21 };
22 }
23
24 case 'setCollections': {
25 return {
26 ...state,
27 collections: action.payload,
28 };
29 }
30
31 case 'setIsOpen': {
32 return {
33 ...state,
34 isOpen: action.payload,
35 };
36 }
37
38 case 'setStatus': {
39 return {
40 ...state,
41 status: action.payload,
42 };
43 }
44
45 case 'setContext': {
46 return {
47 ...state,
48 context: {
49 ...state.context,
50 ...action.payload,
51 },
52 };
53 }
54
55 case 'ArrowDown': {
56 const nextState = {
57 ...state,
58 activeItemId: action.payload.hasOwnProperty('nextActiveItemId')
59 ? action.payload.nextActiveItemId
60 : getNextActiveItemId(
61 1,
62 state.activeItemId,
63 getItemsCount(state),
64 action.props.defaultActiveItemId

Callers

nothing calls this directly

Calls 5

getNextActiveItemIdFunction · 0.90
getItemsCountFunction · 0.90
getCompletionFunction · 0.90
invariantFunction · 0.90
shouldPanelOpenMethod · 0.65

Tested by

no test coverage detected