Skip to content

Commit e1777d3

Browse files
committed
fix(appId): Allow passing a custom appId
This should let developpers use it in a dev environment. Fixes #21 cc @maxiloc
1 parent b39d0d3 commit e1777d3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/lib/DocSearch.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import $ from 'npm-zepto';
1212
* @param {string} options.apiKey Read-only API key
1313
* @param {string} options.indexName Name of the index to target
1414
* @param {string} options.inputSelector CSS selector that targets the input
15+
* @param {string} [options.appId] Lets you override the applicationId used.
16+
* If using the default Algolia Crawler, you should not have to change this
17+
* value.
1518
* @param {Object} [options.algoliaOptions] Options to pass the underlying Algolia client
1619
* @param {Object} [options.autocompleteOptions] Options to pass to the underlying autocomplete instance
1720
* @return {Object}
@@ -28,6 +31,7 @@ class DocSearch {
2831
apiKey,
2932
indexName,
3033
inputSelector,
34+
appId = 'BH4D9OD16A',
3135
algoliaOptions = {
3236
hitsPerPage: 5
3337
},
@@ -39,12 +43,13 @@ class DocSearch {
3943
DocSearch.checkArguments({apiKey, indexName, inputSelector, algoliaOptions, autocompleteOptions});
4044

4145
this.apiKey = apiKey;
46+
this.appId = appId;
4247
this.indexName = indexName;
4348
this.input = DocSearch.getInputFromSelector(inputSelector);
4449
this.algoliaOptions = algoliaOptions;
4550
this.autocompleteOptions = autocompleteOptions;
4651

47-
this.client = algoliasearch('BH4D9OD16A', this.apiKey);
52+
this.client = algoliasearch(this.appId, this.apiKey);
4853
this.client.addAlgoliaAgent('docsearch.js ' + version);
4954
this.autocomplete = autocomplete(this.input, autocompleteOptions, [{
5055
source: this.getAutocompleteSource(),

test/DocSearch-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ describe('DocSearch', () => {
8787
expect(actual.indexName).toEqual('indexName');
8888
expect(actual.apiKey).toEqual('apiKey');
8989
});
90+
it('should set docsearch App Id as default', () => {
91+
// Given
92+
let options = defaultOptions;
93+
94+
// When
95+
let actual = new DocSearch(options);
96+
97+
// Then
98+
expect(actual.appId).toEqual('BH4D9OD16A');
99+
});
100+
it('should allow overriding appId', () => {
101+
// Given
102+
let options = {...defaultOptions, appId: 'foo'};
103+
104+
// When
105+
let actual = new DocSearch(options);
106+
107+
// Then
108+
expect(actual.appId).toEqual('foo');
109+
});
90110
it('should pass the input element as an instance property', () => {
91111
// Given
92112
let options = defaultOptions;

0 commit comments

Comments
 (0)