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

Commit 2b4a9ea

Browse files
committed
perf(tagging multiple): transform tagging item only once when filtering
1 parent ce6a554 commit 2b4a9ea

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/uiSelectMultipleDirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
308308
// verify the new tag doesn't match the value of a possible selection choice or an already selected item.
309309
if (
310310
stashArr.some(function (origItem) {
311-
return angular.equals(origItem, $select.tagging.fct($select.search));
311+
return angular.equals(origItem, newItem);
312312
}) ||
313313
$select.selected.some(function (origItem) {
314314
return angular.equals(origItem, newItem);

test/select.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ describe('ui-select tests', function() {
212212
scope.$digest();
213213
}
214214

215+
function showChoicesForSearch(el, search) {
216+
setSearchText(el, search);
217+
el.scope().$select.searchInput.trigger('keyup');
218+
scope.$digest();
219+
}
220+
215221

216222
// Tests
217223
//uisRepeatParser
@@ -2206,6 +2212,25 @@ describe('ui-select tests', function() {
22062212
expect(el.scope().$select.multiple).toBe(true);
22072213
});
22082214

2215+
it('should not call tagging function needlessly', function() {
2216+
scope.slowTaggingFunc = function (name) {
2217+
// for (var i = 0; i < 100000000; i++);
2218+
return {name: name};
2219+
};
2220+
spyOn(scope, 'slowTaggingFunc').and.callThrough();
2221+
2222+
var el = createUiSelectMultiple({tagging: 'slowTaggingFunc'});
2223+
2224+
showChoicesForSearch(el, 'Foo');
2225+
expect(el.find('.ui-select-choices-row-inner').size()).toBe(6);
2226+
2227+
showChoicesForSearch(el, 'a');
2228+
expect(el.find('.ui-select-choices-row-inner').size()).toBe(9);
2229+
2230+
expect(scope.slowTaggingFunc.calls.count()).toBe(2);
2231+
expect(scope.slowTaggingFunc.calls.count()).not.toBe(15);
2232+
});
2233+
22092234
it('should allow paste tag from clipboard', function() {
22102235
scope.taggingFunc = function (name) {
22112236
return {

0 commit comments

Comments
 (0)