Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render all async results when there were no sync results #1212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/typeahead/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ var Dataset = (function() {
// do not render the suggestions as they've become outdated
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));
rendered += suggestions.length;

that.async && that.trigger('asyncReceived', query);
}
Expand Down
27 changes: 27 additions & 0 deletions test/typeahead/dataset_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ describe('Dataset', function() {
});
});

it('should render all async suggestions if sync had no content', function() {
this.source.andCallFake(fakeGetWithEmptySyncAndAsyncSuggestions);
this.dataset.update('woah');

waits(100);

runs(function() {
var rendered = this.dataset.$el.find('.tt-suggestion');
expect(rendered).toHaveLength(5);
});
});

it('should trigger rendered after suggestions are rendered', function() {
var spy;

Expand Down Expand Up @@ -466,4 +478,19 @@ describe('Dataset', function() {
]);
}, 0);
}

function fakeGetWithEmptySyncAndAsyncSuggestions(query, sync, async) {
sync([]);

setTimeout(function() {
async([
{ value: 'four', raw: { value: 'four' } },
{ value: 'five', raw: { value: 'five' } },
{ value: 'six', raw: { value: 'six' } },
{ value: 'seven', raw: { value: 'seven' } },
{ value: 'eight', raw: { value: 'eight' } },
]);
}, 0);
}

});