Skip to content

Commit

Permalink
fix(dataset): avoid usage of callNow for debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss committed May 24, 2018
1 parent 50240ee commit 1a0ce74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/autocomplete/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,8 @@ _.mixin(Dataset.prototype, EventEmitter, {
that.debounceTimeout = null;
execSource();
};
var callNow = !this.debounceTimeout;
clearTimeout(this.debounceTimeout);
this.debounceTimeout = setTimeout(later, this.debounce);
if (callNow) {
execSource();
}
} else {
execSource();
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/dataset_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,28 @@ describe('Dataset', function() {
this.dataset.update('woah 2');
expect(this.source.calls.count()).toBe(2);
});

it('should wait before calling the source if debounce is provided', function(done) {
var that = this;

this.dataset = new Dataset({
source: this.source,
debounce: 250
});

this.source.and.callFake(fakeGetWithSyncResultsAndExtraParams);

this.dataset.update('woah');
expect(this.source.calls.count()).toBe(0);

this.dataset.update('woah 2');
expect(this.source.calls.count()).toBe(0);

setTimeout(function() {
expect(that.source.calls.count()).toBe(1);
done();
}, 500);
});
});

describe('#cacheSuggestions', function() {
Expand Down

0 comments on commit 1a0ce74

Please sign in to comment.