-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docsearch): introduce
transformSearchClient
API
`transformSearchClient` allows to attach user agents to the search client, to manipulate the cache, etc.
- Loading branch information
1 parent
a358695
commit 70b4de6
Showing
6 changed files
with
20 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type SearchClient = any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './DocSearchHit'; | ||
export * from './InternalDocSearchHit'; | ||
export * from './SearchClient'; | ||
export * from './StoredDocSearchHit'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import React from 'react'; | ||
import algoliasearch from 'algoliasearch/dist/algoliasearch-lite.esm.browser'; | ||
|
||
import { SearchClient } from './types'; | ||
import { version } from './version'; | ||
|
||
export function useSearchClient(appId: string, apiKey: string) { | ||
export function useSearchClient( | ||
appId: string, | ||
apiKey: string, | ||
transformSearchClient: (searchClient: SearchClient) => SearchClient | ||
): SearchClient { | ||
const searchClient = React.useMemo(() => { | ||
const client = algoliasearch(appId, apiKey); | ||
client.addAlgoliaAgent(`docsearch (${version})`); | ||
|
||
return client; | ||
}, [appId, apiKey]); | ||
return transformSearchClient(client); | ||
}, [appId, apiKey, transformSearchClient]); | ||
|
||
return searchClient; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function identity<TParam>(x: TParam): TParam { | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './groupBy'; | ||
export * from './identity'; | ||
export * from './noop'; |