Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 990565d

Browse files
author
Robert Miller
authored
Merge pull request #17 from looker/rlm1023/massive-paste-performance
Fix performance when pasting thousands of values.
2 parents 56fdbff + 52760ec commit 990565d

8 files changed

+42
-17
lines changed

dist/select.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.8 - 2017-08-16T19:47:39.450Z
4+
* Version: 0.19.8 - 2017-11-06T21:30:55.941Z
55
* License: MIT
66
*/
77

dist/select.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.8 - 2017-08-16T19:47:39.332Z
4+
* Version: 0.19.8 - 2017-11-06T21:30:55.814Z
55
* License: MIT
66
*/
77

@@ -1024,9 +1024,7 @@ uis.controller('uiSelectCtrl',
10241024
var pastedItems = ctrl.paste(data);
10251025
// broadcast selected items if paste function returns them
10261026
if (pastedItems && pastedItems.length) {
1027-
pastedItems.forEach(function(item) {
1028-
$scope.$broadcast('uis:select', item);
1029-
});
1027+
$scope.$broadcast('uis:select-multiple', pastedItems);
10301028
}
10311029
ctrl.search = EMPTY_SEARCH;
10321030
e.preventDefault();
@@ -1944,6 +1942,14 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
19441942
$selectMultiple.updateModel();
19451943
});
19461944

1945+
scope.$on('uis:select-multiple', function (event, items) {
1946+
if ($select.selected.length >= $select.limit) {
1947+
return;
1948+
}
1949+
$select.selected = $select.selected.concat(items);
1950+
$selectMultiple.updateModel();
1951+
});
1952+
19471953
scope.$on('uis:activate', function () {
19481954
$selectMultiple.allChoicesActive = false;
19491955
$selectMultiple.activeMatchIndex = -1;

dist/select.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uiSelectController.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,7 @@ uis.controller('uiSelectCtrl',
728728
var pastedItems = ctrl.paste(data);
729729
// broadcast selected items if paste function returns them
730730
if (pastedItems && pastedItems.length) {
731-
pastedItems.forEach(function(item) {
732-
$scope.$broadcast('uis:select', item);
733-
});
731+
$scope.$broadcast('uis:select-multiple', pastedItems);
734732
}
735733
ctrl.search = EMPTY_SEARCH;
736734
e.preventDefault();

src/uiSelectMultipleDirective.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
212212
$selectMultiple.updateModel();
213213
});
214214

215+
scope.$on('uis:select-multiple', function (event, items) {
216+
if ($select.selected.length >= $select.limit) {
217+
return;
218+
}
219+
$select.selected = $select.selected.concat(items);
220+
$selectMultiple.updateModel();
221+
});
222+
215223
scope.$on('uis:activate', function () {
216224
$selectMultiple.allChoicesActive = false;
217225
$selectMultiple.activeMatchIndex = -1;

test/select.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,8 +2902,21 @@ describe('ui-select tests', function () {
29022902
clickMatch(el);
29032903
triggerPaste(el.find('input'), 'tag1');
29042904

2905-
expect(scope.$broadcast).toHaveBeenCalledWith('uis:select', 'tag1');
2906-
})
2905+
expect(scope.$broadcast).not.toHaveBeenCalledWith('uis:select', 'tag1');
2906+
expect(scope.$broadcast).toHaveBeenCalledWith('uis:select-multiple', ['tag1']);
2907+
});
2908+
2909+
it('should broadcast pasted items once regardless of paste size', function() {
2910+
scope.pasteFunc = function(str) { return str.split(",") };
2911+
spyOn(scope, '$broadcast');
2912+
2913+
var el = createUiSelectMultiple({tagging: true, paste: "pasteFunc", taggingTokens: ","});
2914+
clickMatch(el);
2915+
triggerPaste(el.find('input'), 'tag1,tag2,tag3');
2916+
2917+
expect(scope.$broadcast).not.toHaveBeenCalledWith('uis:select', 'tag1');
2918+
expect(scope.$broadcast).toHaveBeenCalledWith('uis:select-multiple', ['tag1', 'tag2', 'tag3']);
2919+
});
29072920

29082921
it('should not broadcast if paste function does not return pasted items', function() {
29092922
scope.pasteFunc = function() {};
@@ -2913,8 +2926,8 @@ describe('ui-select tests', function () {
29132926
clickMatch(el);
29142927
triggerPaste(el.find('input'), 'tag1');
29152928

2916-
expect(scope.$broadcast).not.toHaveBeenCalledWith('uis:select', 'tag1');
2917-
})
2929+
expect(scope.$broadcast).not.toHaveBeenCalledWith('uis:select-multiple', ['tag1']);
2930+
});
29182931

29192932
it('should add an id to the search input field', function () {
29202933
var el = createUiSelectMultiple({ inputId: 'inid' });

0 commit comments

Comments
 (0)