mirror of
https://github.com/correl/melpa.git
synced 2024-12-23 03:00:12 +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
|
// 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) {
|
app.directive("viewOrError", function($rootScope) {
|
||||||
return {
|
return {
|
||||||
template: '<div>' +
|
template: '<div>' +
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<small ng-show="totalDownloads">(<span ng-bind="totalDownloads"></span> downloads to date)</small>
|
<small ng-show="totalDownloads">(<span ng-bind="totalDownloads"></span> downloads to date)</small>
|
||||||
</h2>
|
</h2>
|
||||||
<p>
|
<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>
|
<span class="muted"> <ng-pluralize when="{1: '1 match', 'other': '{} matches'}" count="(packages | filter:packageMatcher(searchTerms)).length"/></span>
|
||||||
</p>
|
</p>
|
||||||
<table id="package-list" class="table table-bordered table-responsive table-hover">
|
<table id="package-list" class="table table-bordered table-responsive table-hover">
|
||||||
|
|
Loading…
Reference in a new issue