-
Notifications
You must be signed in to change notification settings - Fork 73
feat(search-client): Add support for Custom Search Clients #111
Changes from 7 commits
6ad17d7
160e13a
0e09be7
2219d85
e716738
5821351
e677531
e250f84
90ffec0
b151eeb
f43fd4c
9b15a82
42b5480
1c34e6b
13ab84b
512d6c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,15 @@ import { | |
} from "@angular/core"; | ||
import { isPlatformBrowser } from "@angular/common"; | ||
|
||
import * as algoliasearch from "algoliasearch"; | ||
import instantsearch from "instantsearch.js/es"; | ||
|
||
import { Widget } from "../base-widget"; | ||
import { VERSION } from "../version"; | ||
|
||
export type InstantSearchConfig = { | ||
appId: string; | ||
apiKey: string; | ||
appId?: string; | ||
apiKey?: string; | ||
indexName: string; | ||
|
||
numberLocale?: string; | ||
|
@@ -28,6 +29,7 @@ export type InstantSearchConfig = { | |
appId: string, | ||
apiKey: string | ||
) => object; | ||
searchClient?: object; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of rely on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't done for Otherwise, I will add a more strict type for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here you should create a type and use it 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I'm working on the type according to the spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can import searchParameters from the typing of |
||
searchParameters?: object | void; | ||
urlSync?: | ||
| boolean | ||
|
@@ -106,12 +108,13 @@ export class NgAisInstantSearch implements AfterViewInit, OnInit, OnDestroy { | |
} | ||
|
||
// custom algolia client agent | ||
if (!config.createAlgoliaClient) { | ||
config.createAlgoliaClient = (algoliasearch, appId, apiKey) => { | ||
const client = algoliasearch(appId, apiKey); | ||
client.addAlgoliaAgent(`angular-instantsearch ${VERSION}`); | ||
return client; | ||
}; | ||
if (!config.searchClient && !config.createAlgoliaClient) { | ||
const client = algoliasearch(config.appId, config.apiKey); | ||
client.addAlgoliaAgent(`angular-instantsearch ${VERSION}`); | ||
|
||
config.searchClient = client; | ||
config.appId = undefined; | ||
config.apiKey = undefined; | ||
} | ||
|
||
this.instantSearchInstance = instantsearch(config); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not want to deprecate this yet, it is still used for the server side rendering strategy:
If we want to get rid of
createAlgoliaClient
we have to support server side rendering as well with the new method.I can help for this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added
createSSRSearchClient()
and deprecatedcreateSSRAlgoliaClient()
. Hope this is how you envisioned it!