fix(appId): Allow passing a custom appId
This should let developpers use it in a dev environment. Fixes #21 cc @maxiloc
This commit is contained in:
parent
b39d0d3770
commit
e1777d31a7
2 changed files with 26 additions and 1 deletions
|
|
@ -12,6 +12,9 @@ import $ from 'npm-zepto';
|
||||||
* @param {string} options.apiKey Read-only API key
|
* @param {string} options.apiKey Read-only API key
|
||||||
* @param {string} options.indexName Name of the index to target
|
* @param {string} options.indexName Name of the index to target
|
||||||
* @param {string} options.inputSelector CSS selector that targets the input
|
* @param {string} options.inputSelector CSS selector that targets the input
|
||||||
|
* @param {string} [options.appId] Lets you override the applicationId used.
|
||||||
|
* If using the default Algolia Crawler, you should not have to change this
|
||||||
|
* value.
|
||||||
* @param {Object} [options.algoliaOptions] Options to pass the underlying Algolia client
|
* @param {Object} [options.algoliaOptions] Options to pass the underlying Algolia client
|
||||||
* @param {Object} [options.autocompleteOptions] Options to pass to the underlying autocomplete instance
|
* @param {Object} [options.autocompleteOptions] Options to pass to the underlying autocomplete instance
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
|
|
@ -28,6 +31,7 @@ class DocSearch {
|
||||||
apiKey,
|
apiKey,
|
||||||
indexName,
|
indexName,
|
||||||
inputSelector,
|
inputSelector,
|
||||||
|
appId = 'BH4D9OD16A',
|
||||||
algoliaOptions = {
|
algoliaOptions = {
|
||||||
hitsPerPage: 5
|
hitsPerPage: 5
|
||||||
},
|
},
|
||||||
|
|
@ -39,12 +43,13 @@ class DocSearch {
|
||||||
DocSearch.checkArguments({apiKey, indexName, inputSelector, algoliaOptions, autocompleteOptions});
|
DocSearch.checkArguments({apiKey, indexName, inputSelector, algoliaOptions, autocompleteOptions});
|
||||||
|
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
|
this.appId = appId;
|
||||||
this.indexName = indexName;
|
this.indexName = indexName;
|
||||||
this.input = DocSearch.getInputFromSelector(inputSelector);
|
this.input = DocSearch.getInputFromSelector(inputSelector);
|
||||||
this.algoliaOptions = algoliaOptions;
|
this.algoliaOptions = algoliaOptions;
|
||||||
this.autocompleteOptions = autocompleteOptions;
|
this.autocompleteOptions = autocompleteOptions;
|
||||||
|
|
||||||
this.client = algoliasearch('BH4D9OD16A', this.apiKey);
|
this.client = algoliasearch(this.appId, this.apiKey);
|
||||||
this.client.addAlgoliaAgent('docsearch.js ' + version);
|
this.client.addAlgoliaAgent('docsearch.js ' + version);
|
||||||
this.autocomplete = autocomplete(this.input, autocompleteOptions, [{
|
this.autocomplete = autocomplete(this.input, autocompleteOptions, [{
|
||||||
source: this.getAutocompleteSource(),
|
source: this.getAutocompleteSource(),
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,26 @@ describe('DocSearch', () => {
|
||||||
expect(actual.indexName).toEqual('indexName');
|
expect(actual.indexName).toEqual('indexName');
|
||||||
expect(actual.apiKey).toEqual('apiKey');
|
expect(actual.apiKey).toEqual('apiKey');
|
||||||
});
|
});
|
||||||
|
it('should set docsearch App Id as default', () => {
|
||||||
|
// Given
|
||||||
|
let options = defaultOptions;
|
||||||
|
|
||||||
|
// When
|
||||||
|
let actual = new DocSearch(options);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(actual.appId).toEqual('BH4D9OD16A');
|
||||||
|
});
|
||||||
|
it('should allow overriding appId', () => {
|
||||||
|
// Given
|
||||||
|
let options = {...defaultOptions, appId: 'foo'};
|
||||||
|
|
||||||
|
// When
|
||||||
|
let actual = new DocSearch(options);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(actual.appId).toEqual('foo');
|
||||||
|
});
|
||||||
it('should pass the input element as an instance property', () => {
|
it('should pass the input element as an instance property', () => {
|
||||||
// Given
|
// Given
|
||||||
let options = defaultOptions;
|
let options = defaultOptions;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue