Skip to content

Commit

Permalink
feat(onStateChange): provide prevState (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Oct 12, 2020
1 parent a20887d commit 21739b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/autocomplete-core/src/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function createStore<TItem>(
return state;
},
send(action, payload) {
const prevState = { ...state };
state = enhanceState(
reducer(state, {
type: action,
Expand All @@ -33,7 +34,7 @@ export function createStore<TItem>(
})
);

props.onStateChange({ state });
props.onStateChange({ state, prevState });
},
};
}
10 changes: 8 additions & 2 deletions packages/autocomplete-core/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ export interface AutocompleteOptions<TItem> {
/**
* Function called when the internal state changes.
*/
onStateChange?<TItem>(props: { state: AutocompleteState<TItem> }): void;
onStateChange?<TItem>(props: {
state: AutocompleteState<TItem>;
prevState: AutocompleteState<TItem>;
}): void;
/**
* The text that appears in the search box input when there is no query.
*/
Expand Down Expand Up @@ -282,7 +285,10 @@ export interface InternalAutocompleteOptions<TItem>
extends AutocompleteOptions<TItem> {
debug: boolean;
id: string;
onStateChange<TItem>(props: { state: AutocompleteState<TItem> }): void;
onStateChange<TItem>(props: {
state: AutocompleteState<TItem>;
prevState: AutocompleteState<TItem>;
}): void;
placeholder: string;
autoFocus: boolean;
defaultHighlightedIndex: number | null;
Expand Down

0 comments on commit 21739b4

Please sign in to comment.