Skip to content

Commit 303162c

Browse files
feat(plugins): provide state to transformSource
1 parent 5f1f92e commit 303162c

6 files changed

Lines changed: 11 additions & 6 deletions

File tree

examples/recently-viewed-items/recentlyViewedItemsPlugin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export function createLocalStorageRecentlyViewedItems<
4848

4949
return search(params);
5050
},
51-
transformSource({ source, onRemove }) {
51+
transformSource({ source, onRemove, state }) {
5252
const transformedSource = params.transformSource
53-
? params.transformSource({ source, onRemove })
53+
? params.transformSource({ source, onRemove, state })
5454
: source;
5555

5656
return {

packages/autocomplete-plugin-query-suggestions/src/createQuerySuggestionsPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type CreateQuerySuggestionsPluginParams<
1818
getSearchParams?(params: { state: AutocompleteState<TItem> }): SearchOptions;
1919
transformSource?(params: {
2020
source: AutocompleteSource<TItem>;
21+
state: AutocompleteState<TItem>;
2122
onTapAhead(item: TItem): void;
2223
}): AutocompleteSource<TItem>;
2324
/**
@@ -115,6 +116,7 @@ export function createQuerySuggestionsPlugin<
115116
templates: getTemplates({ onTapAhead }),
116117
},
117118
onTapAhead,
119+
state,
118120
}),
119121
];
120122
},

packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
AutocompletePlugin,
3+
AutocompleteState,
34
PluginSubscribeParams,
45
} from '@algolia/autocomplete-core';
56
import { AutocompleteSource } from '@algolia/autocomplete-js';
@@ -21,6 +22,7 @@ export type CreateRecentSearchesPluginParams<
2122
storage: Storage<TItem>;
2223
transformSource?(params: {
2324
source: AutocompleteSource<TItem>;
25+
state: AutocompleteState<TItem>;
2426
onRemove(id: string): void;
2527
onTapAhead(item: TItem): void;
2628
}): AutocompleteSource<TItem>;
@@ -70,7 +72,7 @@ export function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({
7072
store.addItem(recentItem as TItem);
7173
}
7274
},
73-
getSources({ query, setQuery, refresh }) {
75+
getSources({ query, setQuery, refresh, state }) {
7476
lastItemsRef.current = store.getAll(query);
7577

7678
function onRemove(id: string) {
@@ -102,6 +104,7 @@ export function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({
102104
},
103105
onRemove,
104106
onTapAhead,
107+
state,
105108
}),
106109
];
107110
});

packages/website/docs/createLocalStorageRecentSearchesPlugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function search({ query, items, limit }) {
140140

141141
### `transformSource`
142142

143-
> `(params: { source: AutocompleteSource, onRemove: () => void, onTapAhead: () => void })`
143+
> `(params: { source: AutocompleteSource, state: AutocompleteState, onRemove: () => void, onTapAhead: () => void })`
144144
145145
A function to transform the provided source.
146146

packages/website/docs/createQuerySuggestionsPlugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ A function returning [Algolia search parameters](https://www.algolia.com/doc/api
104104

105105
### `transformSource`
106106

107-
> `(params: { source: AutocompleteSource, onTapAhead: () => void })`
107+
> `(params: { source: AutocompleteSource, state: AutocompleteState, onTapAhead: () => void })`
108108
109109
A function to transform the provided source.
110110

packages/website/docs/createRecentSearchesPlugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type RecentSearchesStorage<TItem extends RecentSearchesItem> = {
145145

146146
### `transformSource`
147147

148-
> `(params: { source: AutocompleteSource, onRemove: () => void, onTapAhead: () => void })`
148+
> `(params: { source: AutocompleteSource, state: AutocompleteState, onRemove: () => void, onTapAhead: () => void })`
149149
150150
A function to transform the provided source.
151151

0 commit comments

Comments
 (0)