corejavascript / corejavascript/typeahead.js
Weird behavior on transport function override when `onSuccess` and `onError` are not called
- Dominant language
- JavaScript
- Stars
- 968
- Forks
- 231
- PR merge metrics
- No merged PRs in 30d
Description
I have detected some unusual behavior when overriding the `transport` property of the remote option.
Basically, I do some logic before determining if the response should be made, like so:
var engine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'mysite.com?searchPlugins&q=%QUERY',
wildcard: '%QUERY',
cache: true,
transport: function (options, onSuccess, onError) {
var query = input.val(); // get the query
if(query.startsWith('something')) {
// make the request
// abort previous requests made by typeahead
options.url = options.url.replace('something', ''); // remove "something" from query
$.ajax(options)
.done(function(data, textStatus, request) { onSuccess(data); })
.fail(function(request, textStatus, errorThrown) { onError(errorThrown); });
}
}
}
});
However, if the `if(query.startsWith('something')) {` does not fire, resulting in neither `onSuccess` or `onError` are being called, then it might break the request from every being sent again. It only happen after X amount of requests sent, so the next request might work, but then after that, they will never fire.
I have debugged this issue, somewhat successfully, by removing the `if(query.startsWith('something')) {` statement. In this case, requests will always be sent, despite it being against the usecase.
I only want the request to be sent if the query contains `something`, otherwise not.
I am not sure if anything in the codebase depends on `onSuccess` or `onError` _always_ being called?
Contributor guide
Assessment
This issue has not been assessed yet.