Skip to content

Commit

Permalink
Update rendered-count _after_ async results have displayed
Browse files Browse the repository at this point in the history
This ensures that all async results are rendered.
  • Loading branch information
Per Nilsson committed May 5, 2015
1 parent 588440f commit 387290b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/typeahead/dataset.js
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
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);
}

});

2 comments on commit 387290b

@appsparkler
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1
It worked when I made the change in typeahead.bundle.js

Thanks!

@coopy
Copy link
Owner

@coopy coopy commented on 387290b Mar 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greeniceparadise The project has been forked and is now maintained at https://github.com/corejavascript/typeahead.js - you should update your dependencies to use the corejavascript project.

Please sign in to comment.