From 2b4a9ea9122de7741b1689fdec5cbecb6cb50495 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Sat, 11 Jul 2015 18:10:43 +0200 Subject: [PATCH] perf(tagging multiple): transform tagging item only once when filtering --- src/uiSelectMultipleDirective.js | 2 +- test/select.spec.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index 75744a77e..97c79f481 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -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); diff --git a/test/select.spec.js b/test/select.spec.js index b276a88ca..9e146e689 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -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 @@ -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 {