mirror of
https://github.com/correl/melpa.git
synced 2024-12-22 19:17:27 +00:00
Debounce the package filter so search is more responsive
This commit is contained in:
parent
745f7b6bec
commit
9d7a19d624
2 changed files with 25 additions and 1 deletions
|
@ -165,6 +165,30 @@
|
|||
// Directives
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
app.directive("debounceModel", ["$timeout", function($timeout) {
|
||||
return {
|
||||
restrict: "A",
|
||||
require: "ngModel",
|
||||
scope: {
|
||||
"ngModel": "=",
|
||||
"debounceModel": "="
|
||||
},
|
||||
link: function (scope, element, attrs, ngModel) {
|
||||
//jshint unused: false
|
||||
var delay = 250;
|
||||
var copyValue;
|
||||
scope.$watch(function() {
|
||||
return ngModel.$modelValue;
|
||||
}, function (value) {
|
||||
$timeout.cancel(copyValue);
|
||||
copyValue = $timeout(function() {
|
||||
scope.debounceModel = value;
|
||||
}, delay);
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
app.directive("viewOrError", function($rootScope) {
|
||||
return {
|
||||
template: '<div>' +
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<small ng-show="totalDownloads">(<span ng-bind="totalDownloads"></span> downloads to date)</small>
|
||||
</h2>
|
||||
<p>
|
||||
<input type="text" ng-model="searchTerms" placeholder="Enter filter terms" autofocus>
|
||||
<input type="text" ng-model="enteredSearchTerms" debounce-model="searchTerms" placeholder="Enter filter terms" autofocus>
|
||||
<span class="muted"> <ng-pluralize when="{1: '1 match', 'other': '{} matches'}" count="(packages | filter:packageMatcher(searchTerms)).length"/></span>
|
||||
</p>
|
||||
<table id="package-list" class="table table-bordered table-responsive table-hover">
|
||||
|
|
Loading…
Reference in a new issue