Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
perf(tagging multiple): transform tagging item only once when filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Mar 29, 2016
1 parent ce6a554 commit 2b4a9ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uiSelectMultipleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
// verify the new tag doesn't match the value of a possible selection choice or an already selected item.
if (
stashArr.some(function (origItem) {
return angular.equals(origItem, $select.tagging.fct($select.search));
return angular.equals(origItem, newItem);
}) ||
$select.selected.some(function (origItem) {
return angular.equals(origItem, newItem);
Expand Down
25 changes: 25 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ describe('ui-select tests', function() {
scope.$digest();
}

function showChoicesForSearch(el, search) {
setSearchText(el, search);
el.scope().$select.searchInput.trigger('keyup');
scope.$digest();
}


// Tests
//uisRepeatParser
Expand Down Expand Up @@ -2206,6 +2212,25 @@ describe('ui-select tests', function() {
expect(el.scope().$select.multiple).toBe(true);
});

it('should not call tagging function needlessly', function() {
scope.slowTaggingFunc = function (name) {
// for (var i = 0; i < 100000000; i++);
return {name: name};
};
spyOn(scope, 'slowTaggingFunc').and.callThrough();

var el = createUiSelectMultiple({tagging: 'slowTaggingFunc'});

showChoicesForSearch(el, 'Foo');
expect(el.find('.ui-select-choices-row-inner').size()).toBe(6);

showChoicesForSearch(el, 'a');
expect(el.find('.ui-select-choices-row-inner').size()).toBe(9);

expect(scope.slowTaggingFunc.calls.count()).toBe(2);
expect(scope.slowTaggingFunc.calls.count()).not.toBe(15);
});

it('should allow paste tag from clipboard', function() {
scope.taggingFunc = function (name) {
return {
Expand Down

0 comments on commit 2b4a9ea

Please sign in to comment.